      function gallery(element) {

        {
          // allows access to object from event handlers
          var me = this;

          this.gallery = element;

          e = this.gallery.firstChild;
          while (e) {
            if (e.nodeName == "A") {
              e.onclick = function(e) { return me.showLargeImage(e); }
            }
            e = e.nextSibling;
          }

          this.popup = document.createElement("div");
          this.popup.onclick = function(e) { return me.hideLargeImage(e); }

          this.image = document.createElement("img");
          this.image.onclick = function(e) { return me.hideLargeImage(e); }

          this.loader = document.createElement("img");
          this.loader.className = "loader";
          this.loader.src = "img/loader.gif";

          this.popup.appendChild(this.image);
          this.popup.appendChild(this.loader);
          this.gallery.appendChild(this.popup);

          this.fadeOpacity = 0;
          this.fadeTimer = null;
          this.fading = false;
          this.fadeRate = 10;
          this.fadeSmoothness = 10;
        }

        this.showLargeImage = function(event) {
          event = event || window.event;
          target = event.target || event.srcElement;
          this.loader.style.display = "inline";
          this.image.style.display = "none";
          this.image.src = target.parentNode;
          this.image.onload = function() {
            me.image.style.display = "inline";
            me.loader.style.display = "none";
          }
          this.fadeInPopup();
          return false;
        };

        this.hideLargeImage = function(event) {
          this.fadeOutPopup();
          return false;
        };

        this.setPopupOpacity = function(opacity) {
          x = this.popup.style;
          if (opacity == 0) { x.display = "none"; }
          else { x.display = "block"; }
          x.opacity = (opacity / 100);
          x.MozOpacity = (opacity / 100);
          x.KhtmlOpacity = (opacity / 100);
          x.filter = "alpha(opacity=" + opacity + ")";
        };

        this.fadeInPopup = function() {
          if (this.fading) { return; }
          this.fading = true;
          this.fadeTimer = window.setInterval(function() { me.fadeInPopupTimer(); }, this.fadeRate);
        };

        this.fadeInPopupTimer = function() {
          if (this.fadeOpacity < 100) {
            this.fadeOpacity += this.fadeSmoothness;
            this.setPopupOpacity(this.fadeOpacity);
          } else {
            this.fading = false;
            clearInterval(this.fadeTimer);
          }
        };

        this.fadeOutPopup = function() {
          if (this.fading) { return; }
          this.fading = true;
          this.fadeTimer = window.setInterval(function() { me.fadeOutPopupTimer(); }, this.fadeRate);
        };

        this.fadeOutPopupTimer = function() {
          if (this.fadeOpacity > 0) {
            this.fadeOpacity -= this.fadeSmoothness;
            this.setPopupOpacity(this.fadeOpacity);
          } else {
            this.fading = false;
            clearInterval(this.fadeTimer);
          }
        };

      }

      function x() {
        tags = document.getElementsByTagName("div");
        for (i = 0; i < tags.length; i++) {
          //if (tags[i].className == "gallery") {
          if (new RegExp("\\bgallery\\b").test(tags[i].className)) {
            new gallery(tags[i]);
          }
        }
      }
      if (window.addEventListener) { window.addEventListener("load", x, false); }
      else { window.attachEvent("onload", x); }
