function setOverlayHeight() {
	var arrayPageSize = getPageSize();
	document.getElementById('overlay').style.height = arrayPageSize[1]+"px";
}
function showBrandColors(brand_id) {
	// stretch overlay to fill page and fade in
    var scrollArray = getPageScroll();
    var arrayPageSize = getPageSize();

	document.getElementById('overlay').style.height = arrayPageSize[1]+"px";
	document.getElementById("response_div").parentNode.style.height=arrayPageSize[3]+"px";
	new Effect.Appear('overlay', { duration: 0.2, from: 0.0, to: 0.8 });
	
	document.getElementById("response_div").innerHTML = '<img id="loadingImg" src="/shop/includes/lightbox/images/loading.gif" align="center" style="margin: 20px;">';
	ajaxpage('/shop/color_ace.php?flag=search&showAll=1&listGrid=2&groups=&brand='+brand_id,'response_div','setOverlayHeight()');
	
	if (navigator.appName=='Microsoft Internet Explorer' && navigator.appVersion.substr(0,1) < 7) {
		document.getElementById("response_div").parentNode.style.width=(arrayPageSize[0])+"px";
	}
	document.getElementById("response_div").parentNode.style.paddingTop=(scrollArray[1]+20)+"px";
	showLayer('response_div_container');
	showLayer('response_div');
	
	// hide offending elements
	var inputElems = document.body.getElementsByTagName('input');
	for (i=0; i<inputElems.length; i++) {
		inputElems[i].style.visibility = 'hidden';
	}
	inputElems = document.body.getElementsByTagName('select');
	for (i=0; i<inputElems.length; i++) {
		inputElems[i].style.visibility = 'hidden';
	}

}
function closeBrandColors(e) {
// show offending elements
	var inputElems = document.body.getElementsByTagName('input');
	for (i=0; i<inputElems.length; i++) {
		inputElems[i].style.visibility = 'visible';
	}
	inputElems = document.body.getElementsByTagName('select');
	for (i=0; i<inputElems.length; i++) {
		inputElems[i].style.visibility = 'visible';
	}
	hideLayer('response_div_container');
	hideLayer('response_div');
	if (navigator.appName=='Microsoft Internet Explorer' && navigator.appVersion.substr(0,1) < 7) {
		if ((e.srcElement.id == 'closeImage' || e.srcElement.id == 'loadingImg' || (e.srcElement.tagName!='A' && e.srcElement.tagName!='IMG')) && document.getElementById('lightbox').style.display=='none')
			new Effect.Fade('overlay', { duration: 0.2});
	}
	else {
		if ((e.target.id == 'closeImage' || e.target.id == 'loadingImg' || (e.target.tagName!='A' && e.target.tagName!='IMG')) && document.getElementById('lightbox').style.display=='none')
			new Effect.Fade('overlay', { duration: 0.2});
	}
}
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;
}



//layer visibility functions
function toggleLayer(obj) {
    if(document.getElementById(obj).style.visibility == "visible") {
	    document.getElementById(obj).style.visibility = "hidden";
	    document.getElementById(obj).style.display = "none";
    }
    else {
document.getElementById(obj).style.visibility = "visible";
	    document.getElementById(obj).style.display = "";
    }
}
function hideLayer(obj) {
	    document.getElementById(obj).style.visibility = "hidden";
	    document.getElementById(obj).style.display = "none";
    } 
function showLayer(obj) {
	document.getElementById(obj).style.visibility = "visible";
	document.getElementById(obj).style.display = "";
}


//ajax stuff
var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)
var loadedobjects=""
var rootdomain="http://"+window.location.hostname
var bustcacheparameter=""
function ajaxpage(url, cid, callback_func){
var page_request = false
if (window.XMLHttpRequest) // if Mozilla, Safari etc
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){ // if IE
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, cid, callback_func)
}
if (bustcachevar) //if bust caching of external page
bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime()
page_request.open('GET', url+bustcacheparameter, true)
page_request.send(null)
}

function loadpage(page_request, cid, callback_func){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) {
	document.getElementById(cid).innerHTML=page_request.responseText;
	if(callback_func)
		setTimeout(callback_func,10);
}
}

function loadobjs(){
if (!document.getElementById)
return
for (i=0; i<arguments.length; i++){
var file=arguments[i]
var fileref=""
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
if (file.indexOf(".js")!=-1){ //If object is a js file
fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", file);
}
else if (file.indexOf(".css")!=-1){ //If object is a css file
fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", file);
}
}
if (fileref!=""){
document.getElementsByTagName("head").item(0).appendChild(fileref)
loadedobjects+=file+" " //Remember this object as being already added to page
}
}
}


//ajax post functions
var http_request = false;
function makePOSTRequest(url, parameters, callback_func) {
	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			// set type accordingly to anticipated content type
			//http_request.overrideMimeType('text/xml');
			http_request.overrideMimeType('text/html');
		}
		} else if (window.ActiveXObject) { // IE
			try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
					try {
						http_request = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e) {}
					}
				}
				if (!http_request) {
					alert('Cannot create XMLHTTP instance');
					return false;
				}

		http_request.onreadystatechange = function() { 
		  		if (http_request.readyState == 4) {
					if (http_request.status == 200) {
					result = http_request.responseText;
					document.getElementById('response_div').innerHTML = result;
					if (callback_func)
			    		setTimeout(callback_func,10);
					} else {
						alert('There was a problem with the request.');
					}
				}
	    }
		
		http_request.open('POST', url, true);
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http_request.setRequestHeader("Content-length", parameters.length);
		http_request.setRequestHeader("Connection", "close");
		http_request.send(parameters);
	}
