function hide_litebox(){
  	show_litebox(1);
  	
  	show_hide_objs("visible");
}

function show_hide_objs(val){
  	var objs = document.getElementsByTagName("select");
  	for (var i=0; i<objs.length; i++){
		objs[i].style.visibility = val;
	}
	objs = document.getElementsByTagName("object");
  	for (var i=0; i<objs.length; i++){
		objs[i].style.visibility = val;
	}
	objs = document.getElementsByTagName("embed");
  	for (var i=0; i<objs.length; i++){
		objs[i].style.visibility = val;
	}
}

function show_litebox(hide, lw){
  	var psize = getPageSize();
  	var pscroll = getPageScroll();

  	lw = parseInt(lw);
  	if (isNaN(lw)){
  		var lw = 520;
  	}
  	if (!hide) show_hide_objs("hidden");

  	var a;
  	if (a = document.getElementById("overlay")){
          	a.style.display = hide ? "none" : "";
          	if (!hide){
          		a.style.height = psize[1]+pscroll[1]+"px";
          	}
   	}
  	if (a = document.getElementById("litebox")){
          	a.style.display = hide ? "none" : "";
          	if (!hide){
                	a.style.width = lw + "px";
                	a.style.height = "0px";
               		a.style.height = "auto";
                	a.style.left = (psize[0]-getElementWidth(a))/2+"px";
                	a.style.right = a.style.left;
                	a.style.top = pscroll[1]+100+"px";
          	}
   	}
   	if (!hide){
   		window.onresize = size_litebox;
   	}else{
          	window.onresize = function(){};
    	}
}

function size_litebox(){
  	var psize = getPageSize();
  	var pscroll = getPageScroll();

  	var a;
  	if (a = document.getElementById("overlay")){
		a.style.height = psize[1]+pscroll[1]+'px';
		if (document.all){
                  	a.style.width = psize[0]+'px';
  		}
   	}
   	if (a = document.getElementById("litebox")){
            	a.style.left = Math.round((psize[0]-getElementWidth(a))/2)+'px';
    	}
}

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;
}

// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	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){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	xScr = xScroll;
	yScr = yScroll;
		
	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;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


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

function getElementHeight(pElt){
  return pElt.offsetHeight;
}
function getElementWidth(pElt){
  return pElt.offsetWidth;
}