
var oOverlay, oPopup;

function showGallery(url, width, height, closeUrl) {
    var iWidth = width / 1;
    var iHeight = height / 1;
    var popWidth = iWidth + 30;
    var popHeight = iHeight + 45;
    oOverlay = document.createElement("div");
    oOverlay.className = "gallery_overlay";
    oOverlay.style.width = getViewportWidth() + 'px';
    oOverlay.style.height = getViewportHeight() + 'px';
    oOverlay.style.top = document.documentElement.scrollTop + 'px';
    oOverlay.style.left = "0px";
    document.body.style.width = "100%";
    document.body.style.height = "100%";
    document.body.appendChild(oOverlay);

    oPopup = document.createElement("div");
    oPopup.className = "gallery_popup";
    oPopup.style.width = popWidth + "px";
    oPopup.style.height = popHeight + "px";

    var vpWidth = getViewportWidth();
    var vpHeight = getViewportHeight();

    oPopup.style.left = (vpWidth / 2) - (popWidth / 2) + "px";
    oPopup.style.top = (vpHeight / 2) - (popHeight / 2) + document.documentElement.scrollTop + "px";

    var oImage = document.createElement("img");
    oImage.src = url;
    oImage.width = iWidth;
    oImage.height = iHeight;
    oImage.className = "gallery_image";

    var oCloseButton = document.createElement("img");
    oCloseButton.src = 'images/closelabel.gif';
    oCloseButton.className = "gallery_close";
    oCloseButton.style.top = iHeight + 18 + 'px';
    oCloseButton.style.left = iWidth - 33 - 15 + 'px';
    oCloseButton.onclick = function() { document.body.removeChild(oOverlay); document.body.removeChild(oPopup); }    
	oCloseButton.style.cursor = "pointer";

    oPopup.appendChild(oImage);
    oPopup.appendChild(oCloseButton);
    document.body.appendChild(oPopup);        
}

getViewportWidth = function() {
    var width = 0;
    if (document.documentElement && document.documentElement.clientWidth) {
        width = document.documentElement.clientWidth;
    }
    else if (document.body && document.body.clientWidth) {
        width = document.body.clientWidth;
    }
    else if (window.innerWidth) {
        width = window.innerWidth - 18;
    }
    return width;
};

getViewportHeight = function() {
    var height = 0;
    if (document.documentElement && document.documentElement.clientHeight) {
        height = document.documentElement.clientHeight;
    }
    else if (document.body && document.body.clientHeight) {
        height = document.body.clientHeight;
    }
    else if (window.innerHeight) {
        height = window.innerHeight - 18;
    }
    return height;
};