//////////////////////////////
// Written by West Anderson //
// 2005-2-2					//
//////////////////////////////

///////////////////////////////////////
// Handle centering the heading text //
///////////////////////////////////////
function MainCenterHeading()
{
	var width = MainGetWindowWidth();
	var headerelement = document.getElementById("h3");
	var newleft = width/2-116;
	
	if (newleft > 200)
		headerelement.style.left = width/2-116;
	else
		headerelement.style.left = 200;

	headerelement.style.top = 22;

	// Call the AlignAllMenu //
	AlignMenu();

	// Also handle the vertical shade bar //	
	//var shadebarelement = document.getElementById(2);
	//shadebarelement.style.height = "100%";
}

//////////////////////////////////
// Get the width of the window  //
//////////////////////////////////
function MainGetWindowWidth()
{	
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' )
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} 
	else if( document.documentElement &&
		  ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
	{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	//window.alert( 'Width = ' + myWidth );
	//window.alert( 'Height = ' + myHeight );	
	return (myWidth);
}

// Do the animation of the boxes //
function MainAnimation(idtop, idside, idtext, maxwidth, maxheight, textendy)
{
	maxheight = "100";

	// Grab reference to the id's //
	var topelement = document.getElementById(idtop);
	var sideelement = document.getElementById(idside);

	//alert("sideelement.style.heighta = "+sideelement.style.heighta);

	var textelement = document.getElementById(idtext);	

	//var texttop = topelement.style.top.replace("px", ""); // Remove px from the top location //

	// Add 1/2 the difference each time //
	var widthdiff = (maxwidth-topelement.width)/4;
	//var heightdiff = (maxheight-sideelement.style.height.replace("px", ""))/4;
	var heightdiff = (maxheight-sideelement.style.height.replace("%", ""))/4;
	//var textdiff = (textendy-texttop)/2;
	
	// Compensate for the last jump //
	if (widthdiff <= 1)
	{
		topelement.width = maxwidth;
		sideelement.style.height = "100%"; //maxheight;
	}
	else
	{
		//textelement.style.top = texttop-1+2; //textdiff; // -1 needed to prevent string appending //

		// The -1 +1 fixes appending strings //
		topelement.width = topelement.width*1 + widthdiff*1; // -1 needed to prevent string appending //
		//sideelement.style.height = sideelement.style.height.replace("px", "")-1 + heightdiff+1; // -1 needed to prevent string appending //
		sideelement.style.height = sideelement.style.height.replace("%", "")*1 + heightdiff+1 + "%";
		setTimeout("MainAnimation('"+idtop+"', '"+idside+"', '"+idtext+"', "+maxwidth+", "+maxheight+", "+textendy+")", 10);
	}
}

//////////////////////////////////
// Display Horizontal Shade Bar //
//////////////////////////////////
function MainDisplayHorizontalShadeBar(startred, startgreen, startblue,	endred, endgreen, endblue, stepred, stepgreen, stepblue, height)
{
	// Retain a place to put the color //
	var tempred; 
	var tempgreen;
	var tempblue;
	var finalcolor; 
	var alternate = true;

	// Display the shade lines //
	for (index=0; index < height; index++)
	{
		// Build the color //
		tempred = ColorLengthCheck(d2h(startred-(stepred*index)));
		tempgreen = ColorLengthCheck(d2h(startgreen-(stepgreen*index)));
		tempblue = ColorLengthCheck(d2h(startblue-(stepblue*index)));
		
		// Re-assemble the color //
		finalcolor = tempred+tempgreen+tempblue;
		
		if (alternate == true)
		{
			// Write the color out //
			document.write("<tr bgcolor=#"+finalcolor+"><td></td></tr>");
			alternate = false;
		}
		else
		{
			document.write("<tr bgcolor=#FFFFFF><td></td></tr>");
			alternate = true;
		}
	}

	// Close the table //
	document.write("</table>");
}

////////////////////////////////
// Display Vertical Shade Bar //
////////////////////////////////
function MainDisplayVerticalShadeBar(startred, startgreen, startblue, endred, endgreen, endblue, stepred, stepgreen, stepblue, width)
{
	// Retain a place to put the color //
	var tempred; 
	var tempgreen;
	var tempblue;
	var finalcolor; 
	var temp;
	var alternate = true;

	// Display the shade lines //
	for (index=0; index < width; index++)
	{
		// Build the color //
		tempred = ColorLengthCheck(d2h(startred-(stepred*index)));
		tempgreen = ColorLengthCheck(d2h(startgreen-(stepgreen*index)));
		tempblue = ColorLengthCheck(d2h(startblue-(stepblue*index)));
		
		// Re-assemble the color //
		finalcolor = tempred+tempgreen+tempblue;
		
		//alert("tempred = "+tempred+", tempgreen = "+tempgreen+", tempblue = "+tempblue);
		
		if (alternate == true)
		{
			// Write the color out //
			document.write("<td height=100% bgcolor=#FFFFFF></td>");	
			alternate = false;
		}
		else
		{
			document.write("<td height=100% bgcolor=#"+finalcolor+"></td>");	
			alternate = true;
		}
	}

	// Close out the table //
	//document.write("</tr></table>");
}

////////////////////////////
// Convert decimal to hex //
////////////////////////////
function d2h(d)
{
	var hD="0123456789ABCDEF"; // This needed to convert to hexidecimal //

	var h = hD.substr(d&15,1);	
	while(d>15)
	{
		d>>=4;
		h=hD.substr(d&15,1)+h;
	}	
	return h;
}

////////////////////////////
// Convert hex to decimal //
////////////////////////////
function h2d(h)
{
	return parseInt(h,16);
} 

///////////////////////////////////
// Check the length of the color //
///////////////////////////////////
function ColorLengthCheck(color)
{
	if (color.length == 2)
		return color;
	if (color.length == 1)
		return "0"+color;
	if (color.length == 0)
		return "00";
}