/*
GETTIN' PRETTY SICK OF JAVASCRIPT AT THIS POINT!!!
*/

function changeBackColor(iColor)
	{
	if (iColor != curColor)
		{
		showOverlayLoading();
		setTimeout("doColorChange('"+iColor+"');", 500);
		}
	}

function centerOverlayLoading()
	{
	document.getElementById('overlayLoading').style.left = getPageSize()[0] / 2 - 35 + getPageScrollTop()[0] + 'px';
	document.getElementById('overlayLoading').style.top = getPageSize()[1] / 2 - 18 + getPageScrollTop()[1] + 'px';
	}

function showOverlayLoading()
	{
	//placeOverlay();	
	centerOverlayLoading();
	
	document.getElementById('screenOverlay').style.display = '';
	document.getElementById('overlayLoading').style.display = '';
	
	opacity('screenOverlay', 0, 90, 500);
	opacity('overlayLoading', 0, 100, 500);
	}

function placeOverlay()
	{
	//this version places the overlay just on the viewable screen....not scrolled
	document.getElementById('screenOverlay').style.top = getPageScrollTop()[1]+'px';
	document.getElementById('screenOverlay').style.left = getPageScrollTop()[0]+'px';
	
	document.getElementById('screenOverlay').style.height = getPageSize()[1]+'px';
	document.getElementById('screenOverlay').style.width = getPageSize()[0]+'px';
	
	/*
	//this version places the overlay over entir scrollable area...meaning we only have to call it once
	if (window.innerHeight && window.scrollMaxY || window.innerWidth && window.scrollMaxX)
		{
		yScroll = window.innerHeight + window.scrollMaxY;
		xScroll = window.innerWidth + window.scrollMaxX;
		var deff = document.documentElement;
		var wff = (deff&&deff.clientWidth) || document.body.clientWidth || window.innerWidth || self.innerWidth;
		var hff = (deff&&deff.clientHeight) || document.body.clientHeight || window.innerHeight || self.innerHeight;
		xScroll -= (window.innerWidth - wff);
		yScroll -= (window.innerHeight - hff);
		}
	else if (document.body.scrollHeight > document.body.offsetHeight || document.body.scrollWidth > document.body.offsetWidth)
		{ // all but Explorer Mac
		yScroll = document.body.scrollHeight;
		xScroll = document.body.scrollWidth;
		}
	else
		{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		yScroll = document.body.offsetHeight;
		xScroll = document.body.offsetWidth;
		}
	document.getElementById('screenOverlay').style.height = yScroll+'px';
	document.getElementById('screenOverlay').style.width = xScroll+'px';
	*/
	}

function hideOverlayLoading()
	{	
	opacity('overlayLoading', 100, 0, 500);
	opacity('screenOverlay', 90, 0, 500);
	
	setTimeout("document.getElementById('screenOverlay').style.display = 'none';", 600);
	setTimeout("document.getElementById('overlayLoading').style.display = 'none';", 600);
	}

function initChange(iColor)
	{
	if (loaded1 == true && loaded2 == true && loaded3 == true && loaded4 == true && ranChange == false)
		{
		ranChange = true;
		document.getElementById('tlGears').src = '/Images/TLGears_'+iColor+'.jpg';
		document.getElementById('kusaText').src = '/Images/KusaText_'+iColor+'.jpg';
		document.getElementById('synergyText').src = '/Images/Synergy_'+iColor+'.jpg';
		document.getElementById('contactImg').src = '/Images/Contact_'+iColor+'.jpg';
		document.getElementById('news_loadingImg').src = '/Images/kusa_loading_'+iColor+'.gif';
		for (i=1;i<=2;i++)
			{
			document.getElementById('backColored'+i).style.backgroundColor = '#'+iColor;
			}
		setTimeout("hideOverlayLoading();", 500);
		curColor = iColor.toUpperCase();
		}
	}

function doColorChange(iColor)
	{
	ranChange = false;
	loaded1 = false;
	loaded2 = false;
	loaded3 = false;
	loaded4 = false;
	loaded5 = false;
	//preload the images
	var img = new Array();
	
	img[1] = new Image();
	img[1].onload = function()
		{
		loaded1 = true;
		setTimeout("initChange('"+iColor+"');", 500);
		}
	img[1].src = '/Images/TLGears_'+iColor+'.jpg';
	
	img[2] = new Image();
	img[2].onload = function()
		{
		loaded2 = true;
		setTimeout("initChange('"+iColor+"');", 500);
		}
	img[2].src = '/Images/KusaText_'+iColor+'.jpg';
	
	img[3] = new Image();
	img[3].onload = function()
		{
		loaded3 = true;
		setTimeout("initChange('"+iColor+"');", 500);
		}
	img[3].src = '/Images/Synergy_'+iColor+'.jpg';
	
	img[4] = new Image();
	img[4].onload = function()
		{
		loaded4 = true;
		setTimeout("initChange('"+iColor+"');", 500);
		}
	img[4].src = '/Images/Contact_'+iColor+'.jpg';
	/*
	//don't really need to load the loading image, since they don't see it anyway
	img[5] = new Image();
	img[5].onload = function()
		{
		loaded5 = true;
		setTimeout("initChange('"+iColor+"');", 500);
		}
	img[5].src = '/Images/kusa_loading_'+iColor+'.gif';
	*/
	//set the cookie saying what color it is
	self.xmlHttpReq.open('GET', '/setColor.asp?iColor='+iColor, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'text/html');
	self.xmlHttpReq.onreadystatechange = null;
	self.xmlHttpReq.send('');
	}