      var zoomPopup = false;
      if (!fil)
        var fil = 'fil.gif';

      window.oldonload = window.onload;
      window.onload = function () {
        /* init popup div */
        
        zoomPopup = {
          'zoom'      : document.getElementById ('zoom')        || alert ('picture zoom div not found'),
          'image'     : document.getElementById ('zoomImg')     || alert ('picture zoom img not found'),
          'loadImg'   : document.getElementById ('zoomLoadImg') || alert ('picture zoom loader not found'),
          'titleDiv'  : document.getElementById ('zoomTitle'),
          'textDiv'   : document.getElementById ('zoomText'),
          'nowShowing': false,
          'nowLoading': false,
          'delaying'  : 300,
          'show'      : function (src, title, text, loading, width, height) {

//            this.close ();
            this.clearDelayed ();

            /* hide div */
            this.zoom.style.display = 'none';

            /* IE width and height hinting */
            this.width  = width;
            this.height = height;

            /* show image alt */
            this.image.alt               = title;

            /* show title */
            if (this.titleDiv) {
              this.titleDiv.style.display = !loading && title ? 'block' : 'none';
              this.titleDiv.innerHTML     = title;
            }
            /* show text */
            if (this.textDiv) {
              this.textDiv.style.display  = !loading && text ? 'block' : 'none';
              this.textDiv.innerHTML      = text;
            }

            this.nowShowing                = src && !loading ? src : false;
            this.nowLoading                = src &&  loading ? src : false;
            this.loadImg.style.display     = loading ? 'block' : 'none';
            
            /* IE display none bug */
            this.loadImg.style.visibility  = loading ? 'visible' : 'hidden';

            /* load image */
            this.image.onload = function () {
//              this.onload = '';
//              debug ('width ' + this.width + '  ' + this.height + ' ' + width + ' ' + height + ' ' + this.src);
              zoomPopup.center ();
              return true;
            }
//            debug ('load ' + src);
            this.image.src = src;

            return true;
          },
          'center'   : function () {
            
            /* set text divs width - IE gives the dimensions of prev image loaded */
/*
            this.titleDiv.style.width   = this.image.width + 'px';
            this.textDiv.style.width    = this.image.width + 'px';
*/
            this.titleDiv.style.width   = this.width + 'px';
            this.textDiv.style.width    = this.width + 'px';

            /* get window dims */
            var top           = !window.pageYOffset ? document.documentElement.scrollTop  : window.pageYOffset;
            var left          = !window.pageXOffset ? document.documentElement.scrollLeft : window.pageXOffset;
            var winWidth      = window.innerWidth  ? window.innerWidth  : document.documentElement.clientWidth;
            var winHeight     = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;

            /* display offscreen to measure */
            this.zoom.style.left     = '-2000px';
            this.zoom.style.display  = 'block';

//          alert ('stop');

            /* measure extends */
            var width         = this.zoom.scrollWidth;
            var height        = this.zoom.scrollHeight;
            
            /* hide */
//            alert ('stop ' + height + ' ' + this.height);
            this.zoom.style.display     = 'none';

            /* set position and dimensions */
            this.zoom.style.top   = Math.max (0, Math.round ((winHeight - height) / 2 + top )) + 'px';
            this.zoom.style.left  = Math.max (0, Math.round ((winWidth  - width)  / 2 + left)) + 'px';
            // alert (winWidth + ' ' + winHeight + ' ' + left + ' ' + top + ' ' + z.width + ' ' + z.height);

            /* show */
            this.zoom.style.display     = 'block';
            return true;
          },
          'isShowing': function (src) {
            return src == this.nowShowing;
          },
          'isLoading': function (src) {
            return src == this.nowLoading;
          },
          'timeout'     : false,
          'showDelayed' : function (src, title, text, width, height) {
            this.clearDelayed ();
            this.timeout = window.setTimeout (
              function () {
                zoomPopup.show (src, title, text, false, width, height);
              },
              this.delaying
            );
            return true;
          },
          'clearDelayed': function () {
            if (this.timeout) {
              window.clearTimeout (this.timeout);
            }
            this.timeout = false;
            return true;
          },
          'close': function () {
//            debug ('close');
            if (this.timeout) {
              window.clearTimeout (this.timeout);
            }
            this.loadImg.style.display  = 'none';
            if (this.titleDiv) {
              this.titleDiv.display     = 'none';
            }
            if (this.textDiv) {
              this.textDiv.display      = 'none';
            }
            this.zoom.style.display     = 'none';
            this.timeout       = false;
            this.nowShowing    = false;
            this.nowLoading    = false;
            this.image.onload = function () {
//              debug ('load fil ' + this.width + ' ' + this.height);
              this.onload = '';
              return true;
            }
            this.image.src     = fil;
            return true;
          }
        }
        zoomPopup.zoom.onclick = function () {
          zoomPopup.close ();
          return false;
        }
        if (window.oldonload)
          return window.oldonload ();
        return true;
      }

      function zoomPicture (o, bigsrc, title, text) {
      
        /* find source image */
        var img = o;
        if (o.tagName != 'IMG') {
          var imgs = img.getElementsByTagName ('IMG');
          if (!imgs.length) {
            alert ('source img not found');
            return false;
          }
          img = imgs [0];
        }
        
        if (!img.zPHelper) {
          img.zPHelper = {
            'img'         : img,
            'src'         : img.src,
            'bigsrc'      : bigsrc,
            'title'       : title,
            'text'        : text,
            'preloadImg'  : new Image (),
            'loaded'      : false,
            'onload'      : function () {
              this.loaded = true;
              if (zoomPopup.isLoading (this.src)) {
                zoomPopup.showDelayed (
                  this.bigsrc,
                  this.title,
                  this.text,
                  this.preloadImg.width,
                  this.preloadImg.height
                );
              }
              return true;
            },
            'onclick'     : function () {
              /* this img is already popped - close it */
              if (zoomPopup.isShowing (this.bigsrc)) {
                zoomPopup.close ();
              }
              /* cancel pending load and retry */
              if (!this.loaded) {
                this.preloadImg.onload = '';
              }
              /* show small img and "loading .." */
              zoomPopup.show (this.src, this.title, this.text, true, this.img.width, this.img.height);

              /* already loaded big image */
              if (this.loaded) {
                zoomPopup.showDelayed (this.bigsrc, this.title, this.text, this.preloadImg.width, this.preloadImg.height);
                return false;
              }
              this.preloadImg.zPHelper = this;
              this.preloadImg.onload = function () {
                this.zPHelper.onload ();
                return false;
              }
              /* start load big image */
              this.preloadImg.src = this.bigsrc;
              return false;
            }
          }

          /* set new image or object click handler */
          o.img = img;
          o.onclick = function () {
            this.img.zPHelper.onclick ();
            return false;
          }
        }
        return true;
      }
      
      /* called with onclick */
      function zPClick (o, bigsrc, title, text) {

        /* clear pending delay show */
        zoomPopup.clearDelayed ();

        /* init */
        zoomPicture (o, bigsrc, title, text);

        /* do the click */
        return o.onclick ();
      }
