var menuTimer, subMenuTimer, objectReference;
function mgMenuHandler(switchValue)
{
	if(switchValue == 'on')
	{
		if(menuTimer != null) { clearTimeout(menuTimer); }
		showMenu('menu-list', 'on');
	}
	else if(switchValue == 'off')
	{
		clearTimeout(menuTimer);
		menuTimer = window.setTimeout("showMenu('menu-list', 'off')", 300);
	}
}
function showMenu(menuName, switchValue)
{
	if(switchValue == true || switchValue == 1 || switchValue == 'on') { adjustStyle(document.getElementById(menuName), 'right', 0); }
	else if(switchValue == false || switchValue == 0 || switchValue == 'off') { adjustStyle(document.getElementById('menu-list'), 'right', '10000px'); closeSubMenus(); }
}
function showSubMenu(callingElement)
{
	var subList = callingElement.parentNode.getElementsByTagName("ul"); // sub list to show
	objectReference = subList[0];
	//if(callingElement.parentNode.parentNode.className != "menu_show") { closeSubMenus(); }
	clearTimeout(subMenuTimer);
	subMenuTimer = window.setTimeout("showSubMenu_MakeItHappen()", 300);
}
function showSubMenu_MakeItHappen() // Called from within showSubMenu() as a workaround for setTimeout not being able to evaluate parameters within the function string
{
	changeClass(objectReference, 'menu_show');
}
function closeSubMenus()
{
	var rootElement = document.getElementById("menu-list"); // the root element that forms the menu list
	var subLists = rootElement.getElementsByTagName("ul"); // all sub-list elements
	for(x = 0; x < subLists.length; x++)
	{
		if(subLists[x].className == "menu_show") { changeClass(subLists[x], "menu_hide"); }
	}
}
function clearSubMenuTimer() {
	clearTimeout(subMenuTimer);	
}
function changeClass(elementRef, newClassName)
{
	elementRef.className = newClassName;
}
function adjustStyle(elementName, styleName, value)
{
	e = elementName;
	e.style[styleName] = value;
}