var lingerTime = 2000;
var offsetLeft = 10;
var loadingImage = '/images/loading.gif';		
var closeButton = '/images/close.gif';		


function getPageScroll_div() {
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {
		yScroll = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}


function getPageSize_div() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) {
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { 
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { 
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		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_div(objLink) {
	var objOverlay = document.getElementById('overlay_div');
	var objLightbox = document.getElementById('lightbox_div');
	var objDiv = document.getElementById('lightboxDiv_div');
	var objLoadingImage = document.getElementById('loadingImage_div');
	var objLightboxDetails = document.getElementById('lightboxDetails_div');
	var arrayPageSize = getPageSize_div();
	var arrayPageScroll = getPageScroll_div();
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.display = 'block';
	var str_divid = objLink.getAttribute('href');
	var int_pindex = str_divid.indexOf("#");
	str_divid = str_divid.substring( int_pindex , str_divid.length );
	str_divid = str_divid.replace("#", "");
	var obj_div = document.getElementById(str_divid);

	if (obj_div) {
		var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 - obj_div.style.height.replace("px","")) / 2);
		var lightboxLeft = ((arrayPageSize[0] - 20 - obj_div.style.width.replace("px","")) / 2);
		objLightbox.style.top = "115px";
		objLightbox.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft+offsetLeft + "px";
		objLightbox.style.width = obj_div.style.width;
		objDiv.style.width = obj_div.style.width;
		objLightboxDetails.style.width = obj_div.style.width;// + 'px';
		objDiv.innerHTML = obj_div.innerHTML;
		if (navigator.appVersion.indexOf("MSIE")!=-1){ pause(250); } 
		if (objLoadingImage) { objLoadingImage.style.display = 'none'; }
		selects = document.getElementsByTagName("select");
		for (i = 0; i != selects.length; i++) {
				selects[i].style.visibility = "hidden";
		}	
		objLightbox.style.display = 'block';
		arrayPageSize = getPageSize_div();
		objOverlay.style.height = (arrayPageSize[1] + 'px');

		setTimeout("hideLightbox_div();", lingerTime);
	}
}


function hideLightbox_div() {
	objOverlay = document.getElementById('overlay_div');
	objLightbox = document.getElementById('lightbox_div');
	objOverlay.style.display = 'none';
	objLightbox.style.display = 'none';
	selects = document.getElementsByTagName("select");
    for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility = "visible";
	}
	
	propagandapop();
}


function initLightbox_div() {
	if (!document.getElementsByTagName){ return; }
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++){
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && (anchor.getAttribute("rel") == "lightbox_div")){
			anchor.onclick = function () {showLightbox_div(this); return false;}
		}
	}
	var objBody = document.getElementsByTagName("body").item(0);

	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay_div');
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '90';
 	objOverlay.style.width = '100%';
	objBody.insertBefore(objOverlay, objBody.firstChild);
	
	var arrayPageSize = getPageSize_div();
	var arrayPageScroll = getPageScroll_div();
	var imgPreloader = new Image();

	var objLightbox = document.createElement("div");
	objLightbox.setAttribute('id','lightbox_div');
	objLightbox.style.display = 'none';
	objLightbox.style.position = 'absolute';
	objLightbox.style.zIndex = '100';	
	objBody.insertBefore(objLightbox, objOverlay.nextSibling);
	
	var objDiv = document.createElement("div");
	objDiv.setAttribute('id','lightboxDiv_div');
	objLightbox.appendChild(objDiv);

	var objLightboxDetails = document.createElement("div");
	objLightboxDetails.setAttribute('id','lightboxDetails_div');
	objLightbox.appendChild(objLightboxDetails);
}

addLoadEvent(initLightbox_div);