//========================================================//
//	Javascript functions used for displaying horizontal   //
//	menu bars.                                            //
//========================================================//


//	Global Variables
var subMenuOpened = null;

//--------------------------------------------------------//
//	Function:	OpenMenu()                                //
//                                                        //
//	Purpose:	Called when the mouse has moved over a    //
//				menu item on the main menu bar.  This     //
//				function cause the sub menu associated    //
//				with the menu item to be displayed.       //
//--------------------------------------------------------//

function OpenMenu(menuItem, subMenu)
{
	menuID = document.getElementById("Banner1_Menu1_MenuBar");
	subMenu.style.left = menuItem.offsetLeft + menuID.offsetLeft;
	subMenu.style.top = menuID.offsetHeight + menuID.offsetTop;
	subMenu.style.visibility = "visible";
	subMenuOpened = subMenu;
}

//--------------------------------------------------------//
//	Function:	CloseMenu()                               //
//                                                        //
//	Purpose:	Called when the mouse has moved away from //
//				a menu item on the main menu bar.  This   //
//				function will cause the sub menu          //
//				associated with the menu item to be       //
//				hidden.                                   //
//--------------------------------------------------------//

function CloseMenu(subMenu)
{
	subMenu.style.visibility = "hidden";
	subMenuOpened = null;
}

//--------------------------------------------------------//
//	Function:	document.onmouseover()                    //
//                                                        //
//	Purpose:	Called when the mouse has moved over a    //
//				menu item on the main menu bar.  This     //
//				function will first check to see if       //
//				another sub menu is open and close it and //
//				then it will call the OpenMenu() function //
//				to display the selected sub menu.         //
//--------------------------------------------------------//

document.onmouseover = MouseOver;

function MouseOver(e)
{
	var eSrc = GetSourceElement(e);

	if (eSrc.className == "MenuBarItem")
	{
		eSrc.style.color = "moccasin";
		var menuID = eSrc.id.replace("Banner1_Menu1_", "SubMenu");

		if (document.all)
			eMenu = document.all[menuID];
		else if (document.getElementById)
			eMenu = document.getElementById(menuID);
	
		if (subMenuOpened &&
			subMenuOpened != eMenu) 
			CloseMenu(subMenuOpened);

		if (eMenu)
			OpenMenu(eSrc, eMenu);
	}
	else if (subMenuOpened &&
		!subMenuOpened.contains(eSrc) &&
		!Banner1_Menu1_MenuBar.contains(eSrc)) 
		CloseMenu(subMenuOpened);
}

//--------------------------------------------------------//
//	Function:	document.onmouseout()                     //
//                                                        //
//	Purpose:	Called when the mouse has moved away from //
//				a menu item on the main menu bar.  This   //
//				function removes the Mocassin color that  //
//				was applied when the mouse hovered over   //
//				the menu item.                            //
//--------------------------------------------------------//

document.onmouseout = MouseOut;

function MouseOut(e)
{
	var eSrc = GetSourceElement(e);
	
	if (eSrc.className == "MenuBarItem")
		eSrc.style.color = "";
}

//--------------------------------------------------------//
//	Function:	GetSourceElement()                        //
//                                                        //
//	Purpose:	Returns the source element of the event   //
//				or target passed.  For browsers that do   //
//				not support window.event such as Netscape //
//				and Opera, the target is returned to      //
//				assure cross-browser compatability.       //
//--------------------------------------------------------//

function GetSourceElement(e)
{
	if (window.event)
		return window.event.srcElement;
		
	if (e && e.target)
	{
		if (typeof e.target.nodeType == 'undefined')
			return e.target;
		else if (e.target.nodeType == 3)
			return e.target.parentNode;
		else
			return e.target;
	}
}
