function getWindowXY(){
	var winX=0,winY=0;

	if(typeof(window.innerWidth)=='number'){
		winX = window.innerWidth;
		winY = window.innerHeight;
	}
	else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
	{
		winX = document.documentElement.clientWidth;
		winY = document.documentElement.clientHeight;
	}
	else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
		winX = document.body.clientWidth;
		winY = document.body.clientHeight;
	}
	return [winX,winY];
}
function getScrollXY(){
	var scrOfX=0,scrOfY=0;
	
	if(document.body && (document.body.scrollLeft || document.body.scrollTop)){
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	}
	else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)){
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [scrOfX,scrOfY];
}

function loadLighbox(ltbxWidth,ltbxHeight,divId){
	var windCord = getWindowXY();
	var scroCord = getScrollXY();
	var bodyObj= document.body;
	var boxLayer1 = document.createElement('div');
	//var boxLayer2 = document.createElement('div');
	//var actualBox = document.getElementById(divId);
	var boxLayer2 = document.getElementById(divId);

	boxLayer1.id="rootBoxId";
	boxLayer1.style.background="#111";
	boxLayer1.style.opacity =0.8;
	boxLayer1.style.filter ='alpha(opacity=80)';

	if(bodyObj.scrollHeight > windCord[1]){
		boxLayer1.style.width=(bodyObj.scrollWidth) +"px";
		boxLayer1.style.height=(bodyObj.scrollHeight) +"px";
	}
	else{
		boxLayer1.style.width=(windCord[0]) +"px";
		boxLayer1.style.height=(windCord[1]) +"px";
	}
	//boxLayer2.id="lightBoxId";
	boxLayer2.style.display='block';
	boxLayer2.style.width=ltbxWidth+"px";
	boxLayer2.style.height=ltbxHeight+"px";
	boxLayer2.style.left=((windCord[0]/2)-(ltbxWidth/2)+scroCord[0]) + 'px';
	boxLayer2.style.top =((windCord[1]/2)-(ltbxHeight/2)+scroCord[1]) + 'px';
	//boxLayer2.innerHTML=actualBox.innerHTML;

	bodyObj.appendChild(boxLayer1);
	bodyObj.appendChild(boxLayer2);

	if(boxLayer1.addEventListener){//click background will close lightbox
		boxLayer1.addEventListener("click", closeLighbox, false);
	}
	if(boxLayer1.attachEvent){
		boxLayer1.attachEvent("onclick", closeLighbox);
	}
}

function closeLighbox(){
	var bodyObj= document.body;
	var boxLayer1= document.getElementById("rootBoxId");

	//bodyObj.childNodes[7].style.display='none';
	bodyObj.lastChild.style.display='none'
	hideDiv('lightBoxId');
	if(boxLayer1!=null){
		bodyObj.removeChild(boxLayer1);
	}
}

function clsBox_opnOthBox(oldDivId,ltbxWidth,ltbxHeight,divId){
	var bodyObj= document.body;
	var boxLayer1= document.getElementById("rootBoxId");

	document.getElementById(oldDivId).style.display='none';
	if(boxLayer1!=null){
		bodyObj.removeChild(boxLayer1);
	}

	loadLighbox(ltbxWidth,ltbxHeight,divId)
}
