var subMenuCount = 0;
var menuTimer = 0;

function InitMenuSystem(pMenuCount){
	if (window.Event){
		document.captureEvents(Event.CLICK);
	}
	document.onclick = clickHandler;
	subMenuCount = pMenuCount;
}

function clickHandler(e){
	hideAllSubNav();
}

function showMenu(id){
	hideAllSubNav()
	if(document.getElementById(id) != 'undefined'){
		document.getElementById(id).style.visibility='visible';
	}
	removeTimeout();	
}

function hideMenu(id){
	document.getElementById(id).style.visibility='hidden';
}

function hideAllSubNav(){
	for(i=0;i<subMenuCount;i++){
		if(document.getElementById("sub" + i) != 'undefined'){
			hideMenu("sub" + i)
		}
	}
}

function menuTimeout(menu) {
		sTmp="hideAllSubNav()";
		menuTimer = window.setTimeout(sTmp, 300);
}

function removeTimeout(menu) {
	window.clearTimeout(menuTimer);
}

function buttonColour(id, colour){
	document.getElementById(id).style.backgroundColor = colour
}