// -------------------------------------------------------------
// Client-side global variables
// -------------------------------------------------------------
var sOpenMenuID = "";

var iChunk = 0;
var iChunkStep = 15;
var iChunkDelay = 10;

var sMenuPos = "below";   // values: "right", "below"
var sMenuStyle = "down";	// values: "down", "across", "diagonal"

leftX = 0;
rightX = 0;
var topY = 0;
var bottomY = 0;
	
// ----------------------------------------------------------------
//  hide all displayed menus on a mouseclick
// ----------------------------------------------------------------
function hideMenu()
{
	if(sOpenMenuID != "")
		document.all[sOpenMenuID].style.visibility = "hidden";
}

// ----------------------------------------------------------------
//   main function, doMenu, that hides any open pop-up menus, determines 
//   which menu DIV to access, and starts its display 
//	---------------------------------------------------------------
function DoMenu()
{
	if (typeof event != "undefined") {
		window.event.cancelBubble = true;
		var eSrc = window.event.srcElement;
		var inMenu = false;
		var cX = event.clientX
		var cY = event.clientY
	
		// ----------------------------------------------------------
		// If moving from global to local menu, don't close
		// ----------------------------------------------------------
		if((cX > leftX && cX < rightX) && (cY > topY && cY < bottomY))
			inMenu = true;
	
		if(!inMenu && (eSrc.className != "clsGlbMnu" || eSrc.className != "clsLocMnu") && sOpenMenuID != "")
				hideMenu();
		
		// ----------------------------------------------------------
		// If a global menu (other than that of an open menu) was rolled over
		// ----------------------------------------------------------
		if("clsGlbMnu" == eSrc.className) 
		{
	
			// ----------------------------------------------------------
			// Cancel default link behavior
			// ----------------------------------------------------------
			window.event.returnValue = false;
	
			// ----------------------------------------------------------
			// Get Menu associated with the Menu Title and make sure it exists
			// If it does, show the Menu
			// ----------------------------------------------------------
			// Close menu if open
			if(sOpenMenuID != "")
				document.all[sOpenMenuID].style.visibility = "hidden";
	
			sOpenMenuID = eSrc.id.replace("glbMenu","divMenu")
			if ("object" == typeof(document.all[sOpenMenuID])) 
			{
				var eMenu = document.all[sOpenMenuID];
				iChunk = iChunkStep;
	
				// ----------------------------------------------------------
				// Get the offset of the parent TD and TR for menu positioning
				// Also, determine window width
				// ----------------------------------------------------------
				var eDIV = eSrc.parentElement;
				var eGlbDIV = eDIV.parentElement;
				var eBODY = document.body
	
			
			//HARDCODE LEFT VALUE
				// ----------------------------------------------------------
				// Set the right and top offsets
				// ----------------------------------------------------------
				
				//if((eSrc.offsetLeft + eGlbDIV.offsetLeft + eMenu.offsetWidth) > eBODY.clientWidth)
				//	eMenu.style.left = eBODY.clientWidth - eMenu.offsetWidth;
				//else
				//	eMenu.style.left = eSrc.offsetLeft + eGlbDIV.offsetLeft;
	
				if (sOpenMenuID == "divMenu01")
					eMenu.style.left = 90;
				else if	(sOpenMenuID == "divMenu02")
					eMenu.style.left = 210;
				else if	(sOpenMenuID == "divMenu03")
					eMenu.style.left = 335;
				else if	(sOpenMenuID == "divMenu04")
					eMenu.style.left = 456;
				else if	(sOpenMenuID == "divMenu05")
					eMenu.style.left = 577;
				
				
			//HARDCODE TOP VALUE
				//eMenu.style.top = eSrc.offsetTop + eSrc.offsetHeight + 10;
				eMenu.style.top = 100;
				
				leftX = eMenu.style.posLeft;
				rightX = leftX + eMenu.offsetWidth;
				
				topY = 0;
				bottomY = eMenu.offsetHeight + eMenu.offsetTop;
	
				//alert(leftX);
				
				
				// ----------------------------------------------------------
				// Zero out the Menu size and start the ShowMenu process
				// ----------------------------------------------------------
	
				eMenu.style.clip = "rect(0 0 0 0)";
				eMenu.style.visibility = "visible";
				return window.setTimeout("ShowMenu(" + eMenu.id + ")", iChunkDelay);
			}
		}
	}
}

// ----------------------------------------------------------
// Function which returns the appropriate menu diplay animation
// ----------------------------------------------------------
function GetShowStyle()
{
	if ("down" == sMenuStyle)
		return "rect(0 100% " + iChunk + "% 0)";
	if ("across" == sMenuStyle)
		return "rect(0 " + iChunk + "% 100% 0)";
	if ("diagonal" == sMenuStyle)
		return "rect(0 " + iChunk + "% " + iChunk + "% 0)";
	else
		return "rect(0 100% " + iChunk + "% 0)";
}

// ----------------------------------------------------------
// Function which incrementally displays Menu in appropriate style
// ----------------------------------------------------------
function ShowMenu(eMenu)
{
	eMenu.style.clip = GetShowStyle();
	if (100 >= iChunk)
		window.setTimeout("ShowMenu(" + eMenu.id + ")", iChunkDelay);

	iChunk += iChunkStep;
}

function browserResize()
{
	hideMenu();
	
	var imgOffset = 220;
	var minWidth = 350;
	var imgWidth = 0;
	var imgHeight = 0;
	var clientWidth = document.body.clientWidth;
	var clientHeight = document.body.clientHeight;

	var leftPos = Math.max(clientWidth, minWidth) - minWidth;

	leftPos = Math.max(clientWidth - minWidth, imgWidth + 15);
	leftPos = Math.max(minWidth, clientWidth) - minWidth;
	
	// Position global menu
	idGlbMenu.style.left = (clientWidth / 2) - (idGlbMenu.offsetWidth / 2);
	idGlbMenu.style.top = 5;
	
}

// ----------------------------------------------------------
// Global document event handlers
// ----------------------------------------------------------
document.onmouseover = DoMenu;
//document.onclick = hideMenu;
//window.onresize = browserResize;
//window.onload = browserResize;