﻿// JScript File

function lightboxImg(src) {
    preloadImage(src)

    var img = document.createElement('img');
    img.src = src;
    img.style.display = 'block';
    img.style.position = 'fixed';
	img.style.zIndex = '-1';
	img.style.border = 'solid 2px black';
    img.alt = 'Click to Close';
    
    img.modal = modalOverlay();

    document.body.insertBefore(img.modal, document.body.firstChild);
    document.body.insertBefore(img, img.modal.nextSibling);

    imgHeight = (img.clientHeight == 0) ? 300 : img.clientHeight;
    imgWidth = (img.clientWidth == 0) ? 300 : img.clientWidth;
    
    img.style.top = 0;//getY(img.modal) + (img.modal.clientHeight / 2) - (imgHeight / 2) + 'px';
    img.style.left = 0;//getX(img.modal) + (img.modal.clientWidth / 2) - (imgWidth / 2) + 'px';
    img.style.zIndex = '1000';
	
    img.onclick = function (e) {
        document.body.removeChild(this.modal);
        document.body.removeChild(this)
    }
}

function lightboxDiv(src, divWidth, divHeight) {

    var div = src.cloneNode(true);
    div.style.display = 'block';
    div.style.position = 'fixed';
	div.style.zIndex = '-1';
	div.style.border = 'solid 2px black';
	div.style.backgroundColor = 'white';
	div.style.overflow = 'scroll';
    div.alt = 'Click to Close';
    
    div.modal = modalOverlay();

    document.body.insertBefore(div.modal, document.body.firstChild);
    document.body.insertBefore(div, div.modal.nextSibling);

    divHeight = divHeight || (div.clientHeight == 0) ? 500 : div.clientHeight;
    divWidth = divWidth || (div.clientWidth == 0) ? 300 : div.clientWidth;
    
    div.style.height = divHeight + 'px';
    div.style.width = divWidth + 'px';
    
    div.style.top = getY(div.modal) + (div.modal.clientHeight / 2) - (divHeight / 2) + 'px';
    div.style.left = getX(div.modal) + (div.modal.clientWidth / 2) - (divWidth / 2) + 'px';
    div.style.zIndex = '1000';
	
    div.onclick = function (e) {
        document.body.removeChild(this.modal);
        document.body.removeChild(this)
    }
}

function modalOverlay(obj) {
    obj = obj || document.body;
    
    var div = document.createElement('div');
	div.setAttribute('id','overlay');
	div.style.display = 'block';
	div.style.position = 'fixed';
	div.style.top = '0';
	div.style.left = '0';
	div.style.zIndex = '999';
 	div.style.width = obj.clientWidth + 'px';
 	div.style.height = '100%';
    div.style.backgroundImage = "url(images/overlay.png)";
	
	div.onclick = function (e) { 
	    e.cancelBubble = true;
	    return false; 
	}

    return div;
}

