/**
 * $Id: site-gallerypopup.js 116 2007-11-30 20:00:02Z svollbehr $
 *
 *
 * Copyright (C) 2007 BEHR Software Systems. All Rights Reserved.
 */


/* Site Gallery Popup   *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  */

var activeImagePopup = null;
    
function imagePopup(source, hashCode, label)
{
  var pos = 0;
  if (window.innerHeight)
    pos = window.pageYOffset;
  else if (document.documentElement && document.documentElement.scrollTop)
    pos = document.documentElement.scrollTop;
  else if (document.body)
    pos = document.body.scrollTop;
  
  document.body.style.cursor = "wait";
  
  var i = new Image();
  i.onload = function () {
    document.body.style.cursor = "auto";
     var elem = getElement(hashCode);
     if (!elem) {
     elem = document.createElement("div");
     elem.onclick = function () {
       imageClose(this.id);
     };
     elem.style.cursor = "pointer";
     elem.style.display = "none";
    elem.style.position = "absolute";
    elem.style.zIndex = 999;
      document.body.appendChild(elem);
  }
  if (elem.style.display == "none") {
    if (activeImagePopup)
        imageClose(activeImagePopup);
     elem.id = elem.hashCode = activeImagePopup = hashCode;
     elem.source = source;
     elem.label = label;
    elem.style.top = getElementPositionY(source) + 1 + "px";
    elem.style.left = getElementPositionX(source) + 1 + "px";
    elem.style.width = parseInt(source.clientWidth) + "px";
    elem.style.height = parseInt(source.clientHeight) + "px";
    elem.innerHTML = '<img src="/(' + hashCode + ')?sizehint=95" width="100%' +
      '" height="100%" style="z-index: 1000; position: absolute; top: 0; lef' +
      't: 0; right: 0; bottom: 0;"><img src="/(' + hashCode + ')?sizehint=64' +
      '0" width="100%" height="100%" title="' + label + '" style="z-index: 1' +
      '001; position: absolute; top: 0; left: 0; right: 0; bottom: 0; opacit' +
      'y: 0;">';
      if (elem.lastChild.style.filter != undefined)
         elem.lastChild.style.filter +=
           "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";
    elem.style.display = "block";
    Timing.addZoom
      (elem, 10, ((getClientWidth() - this.width) / 2), pos +
       ((getClientHeight() - this.height) / 2), this.width, this.height,
       elem.lastChild, 0, 1);
   }
  };
  i.src = "/(" + hashCode + ")?sizehint=640";
}
  
function imageClose(hashCode)
{
  if (!hashCode)
    hashCode = activeImagePopup;
  var elem = getElement(hashCode);
  if (elem) {
    elem.onafterzoom = function () {
      this.style.display = "none";
      this.onafterzoom = null;
    };
    Timing.addZoom
      (elem, 10, getElementPositionX(elem.source),
       getElementPositionY(elem.source), 95, 95, elem.lastChild, 1, 0);
    activeImagePopup = null;
  }
}

function documentKeyListener (e)
{
  if (!e) var e = window.event;

  var charcode = (e.keyCode ? e.keyCode : (e.which ? e.which : null));
  if (charcode == 27 /* ESC */ || charcode == 13 /* Enter */)  {
    imageClose();
  }
};

function documentScrollListener (e)
{
  imageClose();
}
   
if (document.addEventListener) {
  document.addEventListener("scroll", documentScrollListener, false);
  document.addEventListener("keypress", documentKeyListener, false);
} else if (document.attachEvent) {
  window.attachEvent("onscroll", documentScrollListener);
  document.attachEvent("onkeypress", documentKeyListener);
}