//////////////////////////////
// Created by West Anderson //
// 2/6/2006					//
// Handle managing a hover	//
// menu						//
//////////////////////////////

// 25 - is number of individual menus open to be created //

// Retain the starting base id //
var g_basemenuid = 56300;
var g_menudelay = 300;
var g_timerhide = new Array(5); // Retain the hide timer //

// Retain the colors from the start menu //
var g_colorbase;
var g_colorhigh;
//var g_colortext;
var g_colorlinks;

// Retain the menu information //
var g_MenuXOffset = new Array(5);
var g_MenuID = new Array(5);
var g_CurrCount = 0;

//////////////////////////////////////////
// Do the alignment for the menu system //
//////////////////////////////////////////
function AlignMenu()
{
	var winwidth = GetWindowWidthMenu();

	// Cycle through all the menus //
	var index;
	for (index=0; index < g_CurrCount; index++)
	{		
		// Calculate the new xpos //
		var xpos = (winwidth/2)+g_MenuXOffset[index];

		// Grab the element //
		var element = document.getElementById(g_MenuID[index]);		
		
		// Set the new x position //
		element.style.left = xpos;
	}
}

////////////////////
// Start the menu //
////////////////////
function StartMenu(heading, xoffset, ypos, link, colorbase, colorhigh, colorlinks)
{
	// Retain the colors //	
	g_colorbase = colorbase;
	g_colorhigh = colorhigh;
	//g_colortext = colortext;
	g_colorlinks = colorlinks;
	
	// Retain menu information //
	g_MenuXOffset[g_CurrCount] = xoffset;
	g_MenuID[g_CurrCount] = g_basemenuid;
	
	// Change the color for all the a href tags //
	//document.write("<style>a {text-decoration: none;color:'#"+g_colortext+"'}</style>");

	// Use absolute paths for hovering menu //
	// bgcolor='#"+colorframe+"' 
	document.write("<table align=center width=100% height=100% cellspacing=0 cellpadding=0><tr><td align=center bgcolor='#"+colorbase+"' ");
	document.write("onmouseover='BGColorMenu(this, \""+g_colorhigh+"\");DisplayMenu("+g_basemenuid+");' ");
	document.write("onmouseout='HideMenu("+g_basemenuid+");BGColorMenu(this, \""+g_colorbase+"\");'>");
	document.write("<b><a class='style1' href='"+link+"'><font color="+colorlinks+">"+heading+"</font></a></b></td></tr></table>");
	document.write("<table cellspacing=0 cellpadding=0 id="+g_basemenuid+" onmouseover='DisplayMenu("+g_basemenuid+")' ");
	document.write("onmouseout='HideMenu("+g_basemenuid+")' style='display:none;position:absolute; top:"+ypos+"; left:0'>"); 
	
	g_basemenuid++;
	g_CurrCount++;
}

//////////////////////////////////////
// Change the background cell color //
//////////////////////////////////////
function BGColorMenu(element, color)
{
	//alert("color = "+color);
	element.bgColor = color;
}

////////////////////////////
// Add a link to the menu //
////////////////////////////
function AddLinkMenu(text, link)
{	
	// Display the dividing lines //
	document.write("<tr bgcolor='#"+g_colorhigh+"'><td></td></tr>");
	
	// Display the entry //
	document.write("<tr bgcolor='#"+g_colorbase+"'><td onmouseover='BGColorMenu(this, \""+g_colorhigh+"\");' ");
	document.write("onmouseout='BGColorMenu(this, \""+g_colorbase+"\");'><a class='style1' href='"+link+"'>&nbsp;<font color="+g_colorlinks+">"+text+"</font>&nbsp;</a></td></tr>");
}

//////////////////////////
// End the current menu //
//////////////////////////
function EndMenu()
{
	document.write("</table>");
}

///////////////////////////////////
// Display the menu on mouseover //
///////////////////////////////////
function DisplayMenu(menuid)
{
	// Check to see if the timer is still running //
	if (g_timerhide[menuid] != "undefined")
	{
		clearTimeout(g_timerhide[menuid]);
		g_timerhide[menuid] = "undefined";
	}	

	// Grab the element //
	var element = document.getElementById(menuid);
		
	// Display the menu //
	element.style.display = "inline";
}

///////////////////////////////
// Hide the menu on mouseout //
///////////////////////////////
function HideMenu(menuid)
{
	// Check to see if the timer is still running //
	if (g_timerhide[menuid] != 0)
	{
		clearTimeout(g_timerhide[menuid]);
		g_timerhide[menuid] = "undefined";
	}

	// Delay the menu hiding //
	g_timerhide[menuid] = setTimeout("TimerHideMenu("+menuid+")", g_menudelay);	
}

////////////////////////////////////////////////
// Handle the delay of the hiding of the menu //
////////////////////////////////////////////////
function TimerHideMenu(menuid)
{
	// Grab the element //
	var element = document.getElementById(menuid);
		
	// Display the menu //
	element.style.display = "none";
}

//////////////////////////
// Get the window width //
//////////////////////////
function GetWindowWidthMenu()
{	
	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);
}
