//
// global variables
//
var isMozilla;
var objDiv = null;
var originalDivHTML = "";
var DivID = "";
var over = false;


function getPageScroll(){

	var yScroll, xScroll;

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

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

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;
	}
	
	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) 
	return arrayPageSize;
}

function buildDimmerDiv()
{
    document.write('<div id="dimmer" class="dimmer" style="width:'+ window.screen.width + 'px; height:' + window.screen.height +'px"></div>');
}

function displayDiv(divId, width, height) 
{
	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	DivID = divId;
	
	//do this to make sure the entire page is dimmed, not just the screen height -- or whichever is greater	
	resizeDiv("dimmer",arrayPageSize[1]);

	document.getElementById('dimmer').style.visibility = "visible";
    
    	document.getElementById(divId).style.width = width + 'px';
    	document.getElementById(divId).style.height = height + 'px';
    
	document.getElementById(divId).style.top =  ( arrayPageScroll[1] + ((arrayPageSize[3] - height) / 2) + 'px');
	document.getElementById(divId).style.left = ( arrayPageScroll[0] + ((arrayPageSize[2] - width) / 2) + 'px');
	
    	originalDivHTML = document.getElementById(divId).innerHTML;
	
	document.getElementById(divId).innerHTML = originalDivHTML;
	
	document.getElementById(divId).className = 'dimming';
	document.getElementById(divId).style.display = "block";
	document.getElementById(divId).style.visibility = "visible";
	
	//Hide the menu so it's div doesn't float act immune to the dimming effect
	//code should go within the page itself
	document.getElementById("qm0").style.visibility = "hidden";

}

function hiddenDiv(divId) 
{
	document.getElementById(divId).innerHTML = originalDivHTML;
	document.getElementById(divId).style.visibility='hidden';
	document.getElementById(divId).style.display = "none";
	document.getElementById('dimmer').style.visibility = 'hidden';

	//Show the menu again
	//code should go within the page itself
	document.getElementById("qm0").style.visibility = "visible";
	
	DivID = "";
}


function resizeDiv(divID, pageheight)
{  
	var div = document.getElementById(divID);  
	var windowheight = window.screen.height;  
	
	if ( pageheight < windowheight ) 
	{ 
		document.body.style.height = windowheight + "px"; 
		div.style.height = windowheight + "px"; 
	}  
	else 
	{ 
		document.body.style.height = pageheight + "px"; 
		div.style.height = pageheight + "px"; 
	}  

}

function init()
{
	buildDimmerDiv();
}

init();
