var gflag, gflag2 = 0;
var to, to2 = null;
var prev, prev2 = 0;

function showMenu(m) {
	var menu = document.getElementById("menu"+m);
	var tm = document.getElementById("tm"+m);
	if (!menu) return true;
	hideMenu(prev);
	prev = m;
	menu.className = "show";
	if(tm) { tm.className = "act"; }
	gflag = 1;
}

function hideMenu(m) {
	var menu = document.getElementById("menu"+m);
	var tm = document.getElementById("tm"+m);
	if (!menu) return true;
	if (gflag==0) {
		menu.className = "hide";
		if(tm) { tm.className = "none"; }
		clearTimeout(to);
		gflag = 0;
	}
}

function hideMenuTimed(m) {
	gflag = 0;
	to = setTimeout('hideMenu('+m+')', 800);
}

/* --- */

function showSubMenu(m) {
	var menu = document.getElementById("menu"+m);
	if (!menu) return true;
	hideSubMenu(prev2);
	prev2 = m;
	menu.className = "show";
	gflag2 = 1;
}

function hideSubMenu(m) {
	var menu = document.getElementById("menu"+m);
	if (!menu) return true;
	if (gflag2==0) {
		menu.className = "hide";
		clearTimeout(to2);
		gflag2 = 0;
	}
}

function hideSubMenuTimed(m) {
	gflag2 = 0;
	to2 = setTimeout('hideSubMenu('+m+')', 10);
}