function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	
	return arrayPageScroll;
}

function getPageSize(){
	
	var xScroll, yScroll;

	if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	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;
	}	
	
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function pause(numberMillis) {
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}	

function showLightbox(objLink){

    var objBody = document.getElementsByTagName("body").item(0);
	var objOverlay=document.getElementById('overlay');
	objBody.insertBefore(objOverlay, objBody.firstChild);
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var imgPreloader = new Image();
	

	var objLightbox = document.createElement("div");
	objLightbox.setAttribute('id','lightbox');
	objLightbox.style.display = 'none';
	objLightbox.style.position = 'absolute';
	objLightbox.style.zIndex = '1000';	
	objBody.insertBefore(objLightbox, objOverlay.nextSibling);
	
	var objLink2 = document.createElement("a");
	objLink2.setAttribute('href','#');
	objLink2.onclick = function () {hideLightbox(); return false;}
	objLightbox.appendChild(objLink2);
	
	var objImage = document.createElement("img");
	objImage.setAttribute('id','lightboxImage');
	objLink2.appendChild(objImage);


	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.display = 'block';
	//objOverlay.style.background = "url(images/overlay.png)";

	imgPreload = new Image();

	imgPreload.onload=function(){
		objImage.src = objLink.href;

		objLightbox.style.top = ((arrayPageScroll[1]) + ((arrayPageSize[3] - 35 - imgPreload.height) / 2) + 'px');
		objLightbox.style.left = (((arrayPageSize[0] - 40 - imgPreload.width) / 2) + 'px');

		if (navigator.appVersion.indexOf("MSIE")!=-1){
			pause(250);
		} 

		objLightbox.style.display = 'block';

		return false;
	}

	imgPreload.src = objLink.href;
	
}

function hideLightbox(){

	objOverlay = document.getElementById('overlay');
	objLightbox = document.getElementById('lightbox');
	objOverlay.style.display = 'none';
	objLightbox.style.display = 'none';
}