var mCloseButton;

function initializeLightBox() {
	
    overlay = document.createElement("div");
    overlay.style.display = 'none';
    overlay.style.backgroundColor = 'black';
    overlay.style.opacity = .4;
    overlay.style.position = 'absolute';
    if (navigator.userAgent.indexOf("MSIE") > 0) {
        overlay.style.filter = 'progid:DXImageTransform.Microsoft.Alpha( style=0,opacity=40)';
    }
    
    document.body.appendChild(overlay);
    
    lightBox = document.createElement("div");
    lightBox.onclick = hideLightBox;
    document.body.appendChild(lightBox);
    lightBox.style.display = 'none';
    lightBox.style.position = 'absolute';
    lightBox.style.marginRight = 'auto';
    lightBox.style.marginLeft = 'auto';
    lightBox.style.backgroundColor = '#ffffff';
    lightBox.style.padding = '10px';
    
    lightBoxImageDiv = document.createElement("div")
    lightBoxImageDiv.style.verticalAlign = 'middle';
    lightBoxImageDiv.style.textAlign = 'center';
    lightBox.appendChild(lightBoxImageDiv);
    
    lightBoxImage = document.createElement("img");
    lightBoxImage.src = lightBoxLoadImgUrl;
    lightBoxImageDiv.appendChild(lightBoxImage);
    
    var row2 = document.createElement("div");
    row2.style.paddingTop = '5px';
    lightBox.appendChild(row2);
    lightBox.style.textAlign = 'right';
    
    
   
   
	var objBottomNavCloseLink = document.createElement("a");
	objBottomNavCloseLink.setAttribute('id','bottomNavClose');
	objBottomNavCloseLink.setAttribute('href','#');
	objBottomNavCloseLink.onclick = hideLightBox;
	objBottomNavCloseLink.innerHTML = "Close";
	objBottomNavCloseLink.className = "CloseLink"; 
	
	row2.appendChild(objBottomNavCloseLink);
	
      
    
    
    
    
    
}

function changeToMouseOver(){
	mCloseButton.style.cursor='hand'
}


function hideLightBox() {
    lightBoxImage.src = lightBoxLoadImgUrl;    
    lightBoxImage.style.height = '';
    lightBoxImage.style.width = '';
    overlay.style.display = 'none';
    lightBox.style.display = 'none';
    
}

function showLightBox(imgUrl, width, height) {
    if (!lightBoxIntialized)
        initializeLightBox();
        
    var winSize = getWindowSize();
    var scrollTop = getScrollTop();
    
    var preLoadImage = new Image();
    // preload image
	preLoadImage = new Image();

	preLoadImage.onload=function() {
	    lightBoxImage.src = preLoadImage.src;
	    lightBoxImage.style.height = height + 'px';
	    lightBoxImage.style.width = width + 'px';
	}
	
	preLoadImage.src = imgUrl;
    
    lightBoxImageDiv.style.width = width + 'px';
    lightBoxImageDiv.style.height = height + 'px';
    
    overlay.style.display = '';
    if (navigator.userAgent.indexOf('MSIE') < 0 ) {
        overlay.style.right = '0px';
        overlay.style.left = '0px';
    } else {
        overlay.style.width = winSize[0] + 'px';
    }
    
    overlay.style.height = (winSize[1]+scrollTop) + 'px';
    
    overlay.style.top = '0px';
    overlay.style.left = '0px';
    
    lightBox.style.display = '';
    lightBox.style.borderWidth = '2px';
    lightBox.style.borderColor = '#333';
    lightBox.style.borderStyle = 'solid';
    lightBox.style.left = ((winSize[0] - lightBox.offsetWidth)/2) + 'px';
    lightBox.style.top = (((winSize[1] - lightBox.offsetHeight)/2) + scrollTop)  + 'px';
   
}

function getWindowSize(){
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers	
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	

	arrayPageSize = new Array(windowWidth,windowHeight) 
	return arrayPageSize;
}

function getScrollTop() {
    if (self.pageYOffset) {
		return self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		return document.documentElement.scrollTop;
	} else {
		return document.body.scrollTop;
	}
}

function showPopUpImage(url, width, height) {
    var popUpWidth = width + 20;
    var popUpHeight = height + 20;
	var popWin = window.open(url,"thumbNailWin","width=" + popUpWidth + ",height=" + popUpHeight + ",scrollbars=yes,toolbar=no,menubar=no,status=no,resizable=yes,location=no");
	return popWin;
}

function showFullImage(mode, url, width, height) {
	
    switch (mode) {
        case 1:
            showPopUpImage(url,width,height);
            break;
        case 2:
            showLightBox(url,width,height);
            break;
        default:
            try {
                var win = showPopUpImage(url,width,height);
                win.focus();
            } catch (e) {
                showLightBox(url,width,height);
            }
            break;
    }
}

var lightBox;
var lightBoxCaption;
var lightBoxImage;
var lightBoxImageDiv;
var overlay;
var oldonload = window.onload;
var lightBoxIntialized = false;


