window.onerror = null;
document.onerror = null;
var menuHolder; 
var menuTimeout;
var iLoop;
var SelainIE;

// Set some global variables
menuHolder = "";
menuTimeout = "";
//window.onerror = null;
//document.onerror = null;
SelainIE = (navigator.appName != "Netscape");
//-----------------------------------------------------------------------------
//showLayer() function fires up the correct menu's depending on 
//the two elements passed. Light up the whole array
//-----------------------------------------------------------------------------
function menuViewer(menuName)
{
	if (document.getElementById && eval("document.getElementById(\"" + menuName + "\")"))
	{
		eval("document.getElementById(\"" + menuName + "\").style.visibility = 'visible';");
		return;
	}
	if (document.layers && document.layers[menuName])
	{
		document.layers[menuName].visibility = "show";
		return;
	}
	if (document.all && eval("document.all." + menuName))
	{
		eval("document.all." + menuName + ".style.visibility = \"visible\"");
		return;
	}
}



//-------------------------------------------------------------------------------------------------------------------------------
//this function initiallizes the kill menu function, if there are no mouseover events then it kills all menus
//-------------------------------------------------------------------------------------------------------------------------------
function mHdr()
{
	//set a timeout and then kill all the menu's
	//we will check in mH() to see if some stay lit.
	menuTimeout = setTimeout("menuKiller('all');",1000);
}

//----------------------------------------------------------------------------------------------
//kill appropriate menu's, if we are getting here via the mHdr() funciton
//then kill all the menu's this is known from the passed value 'apocolypse'
//----------------------------------------------------------------------------------------------
function menuDestroyer(menuName)
{
	if (document.getElementById && eval("document.getElementById(\"" + menuName + "\")"))
	{
		eval("document.getElementById(\"" + menuName + "\").style.visibility = 'hidden';");
		return;
	}
	if (document.layers && document.layers[menuName])
	{
		document.layers[menuName].visibility = "hidden";
		return;
	}
	if (document.all && eval("document.all." + menuName))
	{
		eval("document.all." + menuName + ".style.visibility = \"hidden\"");
		return;
	}
}

function menuKiller(menuName)
{
var menuArray;
var menuArrayLen;
	if(menuName == "")
		return;
	// Check if currentMenu is last position of menuHolder -list
	if(menuName == "all")
	{
		menuArray = menuHolder.split(",");
		menuArrayLen = menuArray.length;
		for(iLoop=0; iLoop < menuArrayLen; iLoop++)
		{
			if(menuArray[iLoop] != "")
				menuDestroyer(menuArray[iLoop]);
		}
		menuHolder = "";
	}
	// Kill individual menu
	else
	{
		if(menuName != "")
			menuDestroyer(menuName);
	}
}

function mHand(currentMenu, childMenu)
{
var menuArray;
var menuArrayLen;
	// currentMenu must always have name!!
	if(currentMenu == "")
		return;
	// Just kill timer and continue
	clearTimeout(menuTimeout);
	// Check if currentMenu is last position of menuHolder -list
	menuArray = menuHolder.split(",");
	menuArrayLen = menuArray.length;
	// menu is in menuHolder and deed not to be added in list. 
	if((childMenu != "" && menuArray[menuArrayLen-1] == childMenu) || (childMenu == "" && menuArray[menuArrayLen-1] == currentMenu))
	{
		return;
	}
	// childMenu is not in list. Remove existing possible existing menus 
	// that should not be visible
	while(menuArray[menuArrayLen-1] != currentMenu && menuArrayLen > 0)
	{
		// If not, remove last until there is none left or menu name is found
		menuKiller(menuArray[menuArrayLen-1]);
		menuArrayLen--;
	}
	// Recreate menuHolder, if menuArrayLen is less than menuArrau.length
	if(menuArrayLen < menuArray.length)
	{
		// Clear current menu array
		menuHolder = "";
		if(menuArrayLen > 0)
		{
			for(iLoop=0; iLoop < menuArrayLen; iLoop++)
			{
				if(menuHolder=="")
					menuHolder = menuArray[iLoop];
				else
					menuHolder = menuHolder + "," + menuArray[iLoop];
			}
		}
	}		
	// Now add currentMenu to menuHolder -list if it is not there
	if(menuArray[menuArrayLen-1] != currentMenu)
	{
		if(menuHolder=="")
			menuHolder = currentMenu;
		else
			menuHolder = menuHolder + "," + currentMenu;
		menuViewer(currentMenu);
	}
	// now add childMenu to list, which is NOT in list
	if(childMenu != "")
	{
		if(menuHolder=="")
			menuHolder = childMenu;
		else
			menuHolder = menuHolder + "," + childMenu;
		menuViewer(childMenu);
	}
}

