﻿
function ShowLightBox(theDivID) {
    var theDiv = document.getElementById(theDivID);

    if (theDiv) {

        theDiv.style.display = 'block';

        if (document.getElementById('lightbox_black_overlay_div')) {
            document.getElementById('lightbox_black_overlay_div').style.display = 'block';
        }
        else {
            AddOverlayWithID(theDivID);
        }
    }
}

function CloseLightBox(theDiv) {

    if (document.getElementById(theDiv)) {
        
        // hide the light box
        document.getElementById(theDiv).style.display = 'none';
        
        // hide the black over lay
        if (document.getElementById('lightbox_black_overlay_div')) {
            document.getElementById('lightbox_black_overlay_div').style.display = 'none';
        }
    }
}

function AddOverlay() {
    AddOverlayWithID('LightBox_Show_TD');
}

function ResizeWorkshopOverlay() {
    if (document.getElementById('LightBox_Show_TD'))
        ResizeOverlay('LightBox_Show_TD');
}

function AddOverlayWithID(theLightBoxID) {
    var theBody = document.getElementsByTagName('body')[0];
    var newDiv = document.createElement('div');
    newDiv.id = "lightbox_black_overlay_div";
    newDiv.className = "lightbox_black_overlay";
    newDiv.innerHTML = "";
    theBody.appendChild(newDiv);
    ResizeOverlay(theLightBoxID);
}

function ResizeOverlay(theLightBoxID) {
    // resize the overlay to the window size
    var clientHeight;
    var clientWidth;
    var overlayHeight;
    var lBoxOffsetHeight;

    var theLightBox = document.getElementById(theLightBoxID);
    var lBoxWidth = parseInt(theLightBox.scrollWidth);
    var lBoxHeight = parseInt(theLightBox.scrollHeight);


    var theBody = document.getElementsByTagName('body')[0];
    var contentHeight = parseInt(theLightBox.scrollHeight) + 140;

    if (window.innerHeight) {
        clientHeight = parseInt(window.innerHeight);
        clientWidth = parseInt(window.innerWidth);
    }
    else { // IE
        clientHeight = parseInt(document.body.offsetHeight);
        clientWidth = parseInt(document.body.offsetWidth);
    }

    overlayHeight = clientHeight;

    if (overlayHeight < theBody.scrollHeight + 25)
        overlayHeight = theBody.scrollHeight + 25;

    if (contentHeight > overlayHeight)
        document.getElementById('lightbox_black_overlay_div').style.height = (overlayHeight + (contentHeight - overlayHeight)) + "px";
    else document.getElementById('lightbox_black_overlay_div').style.height = overlayHeight + "px";

    // put the light box in the center of the screen	
    lBoxOffsetHeight = (clientHeight / 2) - (lBoxHeight / 2);
        
    theLightBox.style.left = ((clientWidth / 2) - (lBoxWidth / 2) - 13) + "px";   
    theLightBox.style.top = "15px";
}

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != "function")
        window.onload = func;
    else
        window.onload = function() {
            oldonload();
            func();
        }
    }

function AddOverlayToLoad() {
    addLoadEvent(AddOverlay); 
}