/* 
	File:		/js/menu.js
	Author:		Mindcast Software
	Copyright:	© 1996-2005  The GCRH Corporation  All rights reserved.
	Notes:		manages the vars and functions for the main menu and tips functionality
*/
	
	//vars for current header and menu
	var activeHeader = null;
	var activeMenu = null;
	
	//Sets the current header and menu
	function setMenu(menuHeaderID,menuID)
	{
		var top = 0;
		var left = 0;
		var currentEle;
		
		//if(document.all)
		//{
			if(activeHeader != null && activeMenu != null)
			{
				if(activeMenu.style.visibility != 'hidden')
				{
					menuHide();
					showSelect();
				}
			}
		
			//alert(menuID);
			//alert(menuHeaderID);
			activeHeader = eval("document.getElementById('" + menuHeaderID + "');");
			activeMenu = eval("document.getElementById('" + menuID + "');");
			menuChange(activeHeader);
			currentEle = activeHeader;
				
			//Find the top and left of header and its parent elements
			while(currentEle.tagName.toLowerCase() != 'body')
			{
				top += currentEle.offsetTop;
				left += currentEle.offsetLeft;
				currentEle = currentEle.offsetParent;
			}
			
			//Add the width of the header, and width of extra image.
			top += (activeHeader.offsetHeight);
						
			//alert(left);
			activeMenu.style.left = left;
			activeMenu.style.top = top;
			
			hideSelect();
			menuShow();
			
			event.cancelBubble = true;
		//}
	}
	
	//Show the current menu
	function menuShow()
	{
		//alert(document.all);
		//alert(document.getElementById('activeMenu'));
		if(document.getElementById)
		{
			//activeHeader.className = 'over';
			
			activeMenu.style.visibility = 'visible';
		}
	}
	
	//Hide the current menu
	function menuHide()
	{
		if(document.getElementById)
		{
			//activeHeader.className = 'norm';
			activeMenu.style.visibility = 'hidden';
		}
	}
	
	//Hide the current menu and reset vars
	//if the moved to element is not contained
	//within the menu.
	function hideMenu()
	{
		if(document.getElementById)
		{
			if(activeHeader != null && activeMenu != null)
			{
				//Check if the "moved to" element is not 
				//contained within activeMenu.
				if(!activeMenu.contains(event.toElement)) 
				{
					activeMenu.style.visibility = 'hidden';
					//activeHeader.className = 'norm';
					menuChange(activeHeader);
					//alert("error")
					activeHeader = null;
					activeMenu = null;
					showSelect();
				}
			}
		}
	}
	
	//show dropdown when menu is hidden
	function showSelect()
	{
		var obj;
		
		for(var i = 0; i < document.getElementsByTagName("select").length; i++)
		{
			obj = document.getElementsByTagName("select")[i];
			//alert(obj.id);
			if(!obj || !obj.offsetParent)
				continue;
			obj.style.visibility = 'visible';
		}
	}
	
	//hide dropdown so menu can cover it when menu is visible
	function hideSelect()
	{
		var obj;
		var currentEle;
		var top = 0;
		var left = 0;
		var menuHeight;
		var timeout;
		
		for(var i = 0; i < document.getElementsByTagName("select").length; i++)
		{
			obj = document.getElementsByTagName("select")[i];
			currentEle = obj;
		
			while(currentEle.tagName.toLowerCase() != 'body')
			{
				top += currentEle.offsetTop;
				left += currentEle.offsetLeft;
				currentEle = currentEle.offsetParent;
			}
			if(activeMenu != null)
			{
				menuHeight = (activeMenu.offsetTop + activeMenu.offsetHeight);
				
				if(top < menuHeight)
				{			
					if((left < (activeMenu.offsetLeft + activeMenu.offsetWidth)) && (left + obj.offsetWidth > activeMenu.offsetLeft)) 
						obj.style.visibility = 'hidden';
				}
			}
			top = 0;
			left = 0;
		}
	}
/***************************************************************************************************************/
	//Hightlight the menu option
	function menuChange(srcEle)
	{				
		if(srcEle.className.toLowerCase() == 'menuregular')
		{
			srcEle.className = 'menuHighlight';
		}
		else
		{
			srcEle.className = 'menuRegular';
		}
	}
/***************************************************************************************************************/


	//vars for current tip header and tip
	var activeTip = null;
	
	//Sets the current header and menu
	function setTip(tipID,tipLocID,x,y)
	{
		var top = 0;
		var left = 0;
		
		if(document.getElementById)
		{
		
			activeTip = eval("document.getElementById('" + tipLocID + "');");
				
			activeTip.style.left = x + 25;
			activeTip.style.top = y - 50;
						
			activeTip.style.visibility = 'visible';
			
			event.cancelBubble = true;
			
			var innerTip = eval("document.getElementById('myTip');");
			innerTip.innerText = arrTips[tipID][1];
		}
	}
	
	
	//Hide the current menu and reset vars
	//if the moved to element is not contained
	//within the menu.
	function hideTip()
	{
		if(document.getElementById)
		{
			if(activeTip != null)
			{
				if(!activeTip.contains(event.toElement)) 
				{
					activeTip.style.visibility = 'hidden';
					activeTip = null;
				}
			}
		}
	}
	
