// JavaScript Document
//Overlay function - Compiled by Brian 10/23/2009

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 (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 showOverlay() {
	// prep objects
	var objOverlay = document.getElementById('overlay');
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	// set height of Overlay to take up whole page and show
	//objOverlay.style.height = (arrayPageSize[1] + 'px');
	objOverlay.style.display = 'block';
}

function hideOverlay() {
	// get objects
	//alert("hiding ... ");
	if (document.getElementById('overlay') && document.getElementById('overlay').style.display != 'none') {
		var objOverlay = document.getElementById('overlay');
		// hide lightbox and overlay
		objOverlay.style.display = 'none';
		 
	}
}

function close_adding_layer() {
		if (document.getElementById("adding_layer")) {
			document.getElementById("adding_layer").style.display = "none";
			document.getElementById("adding_layer").innerHTML = holder;
			if (document.getElementById('overlay').style.display != 'none') hideOverlay();
			if (browser == 'Internet Explorer'){
				hideSelects('visible');
			}
			adding_id = "";
		}
}
function close_div() {
	hideOverlay();
 	document.getElementById("map_layer").style.display = "none";
  	document.getElementById("promo_layer").style.display = "none";
}
function initOverlay() {
	var objBody = document.getElementsByTagName("body").item(0);
	var objOverlay = document.createElement("div");
	objOverlay.setAttribute('id','overlay');
	objOverlay.onclick = function () {
										close_div();
										return false;
										}
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0px';
	objOverlay.style.left = '0';
	objOverlay.style.zIndex = '5000';
 	objOverlay.style.width = '100%';
	objOverlay.style.height = '903px';
	objBody.insertBefore(objOverlay, objBody.firstChild);
}

function ToggleFloatingLayer(DivID, iState, object) {
	
	
	//NEW STYLE
	if (document.getElementById("mini_cart") && page_loaded) {	
		var cur_status = document.getElementById(DivID).style.display;
		if (iState == 1 && (cur_status == "none" || cur_status == "")) {
			
			//CENTER DIV
			centerDiv('FloatingLayer', 40, 500);
			
			//LAUNCH CART
			//sendRequest("action=display","mini_cart");
			//New Style launch
			//var var_str = "action=display&type=all";
			load_cart_total("action=display&type=all");
		} else {
			if (iState == 0) {
				if (document.getElementById('overlay').style.display != 'none') {
					hideOverlay();
					hideSelects('visible');
				}
			}
		}
		
		//HIDE OR SHOW CART
		if(document.layers)	   //NN4+
		{
		   document.layers[DivID].display = iState ? "block" : "none";
		}
		else if(document.getElementById)	  //gecko(NN6) + IE 5+
		{
			var obj = document.getElementById(DivID);
			obj.style.display = iState ? "block" : "none";
		}
		else if(document.all)	// IE 4
		{
			document.all[DivID].style.dispaly = iState ? "block" : "none";
		}
	}	
}
addOnloadEvent(initOverlay);

function openCalendar() {

	if (document.getElementById('map_layer')) {

		document.getElementById("map_layer").style.display = "block";
		showOverlay();
			//alert(intW);
		
	
	}
}
function openPromo() {

	if (document.getElementById('promo_layer')) {

		document.getElementById("promo_layer").style.display = "block";
		showOverlay();
			//alert(intW);
		
	
	}
}
function addOnloadEvent(onloadToAdd){
    var prevOnLoad = window.onload;
    if(typeof window.load != "function"){
        window.onload = onloadToAdd;
    } else {
        window.onload = function(){
            if(prevOnLoad){
                prevOnLoad();
            }
            onloadToAdd();
        }
    }
}
