var menucount = 9;
var smtimer = false;
var holdmenu = false; // If true, the mouseout event doesn't reset the submenu back to default. Used to ensure Searchbox stays on screen

function swapsubmenu_over (menuid, newhold) {
	holdmenu = newhold;
	clearTimeout (smtimer);
	// Swap the mainmenu button class
	removemainmenuhighlights ();
	var menu = document.getElementById ('mm'+menuid);
	if (menu) menu.className = 'mainmenucellhighlight';
	
	hideallsubmenus (menuid);
}

function swapsubmenu_out (menuid) {
	clearTimeout (smtimer);
	if (!holdmenu) smtimer = setTimeout ('swapsubmenu_out_action ('+menuid+')', 1000);
}
function swapsubmenu_out_action (menuid) {
	removemainmenuhighlights ();
	
	// Set the highlight back to the default (current) page
	hideallsubmenus (thismenu);
	var menu = document.getElementById ('mm'+thismenu);
	if (menu) menu.className = 'mainmenucellhighlight';
}

function removemainmenuhighlights () {
	// Set all mainmenu buttons back to basic (no highlight)
	for (index = 1; index <= menucount; index ++) {
		if (document.getElementById ('mm'+index)) {
			var menu = document.getElementById ('mm'+index);
			menu.className = 'mainmenucell';
		}
	}
}
function hideallsubmenus (thismenu) {
	// Hide all the submenus
	for (index = 1; index <= menucount; index ++) {
		if (document.getElementById ('sm'+index)) {
			var submenu = document.getElementById ('sm'+index);
			submenu.style.display = 'none';
		}
	}
	// Reveal the chosen submenu
	if (document.getElementById ('sm'+thismenu)) {
		var submenu = document.getElementById ('sm'+thismenu);
		submenu.style.display = 'block';
	}
}