
var menuTimer = {'andre' : null, 'tredje' : null, 'fjerde' : null, 'femte' : null, 'sjette' : null};
var rootId    = 'toppmeny';

function showMenu(menuItem){
	document.getElementById('under' + menuItem).style.display = 'block';
	clearTimeout(menuTimer[menuItem]);
	
	menuItems = document.getElementById(rootId).childNodes;
	for(var x = 0; x < menuItems.length; x++){
		if(menuItems[x].nodeName.toUpperCase() == "LI" && menuItems[x].id != 'forste' && menuItems[x].id != menuItem){
			doHide(menuItems[x].id);
		}
	}
}

function delayedHideMenu(menuItem){
	clearTimeout(menuTimer[menuItem]);
	menuTimer[menuItem] = window.setTimeout('doHide("' + menuItem + '")', 1000)
}

function doHide(menuItem){
	clearTimeout(menuTimer[menuItem]);
	document.getElementById(menuItem).style.backgroundColor='#336AC4';
	document.getElementById('under' + menuItem).style.display = 'none';
}


function init(){
	menuItems = document.getElementById(rootId).childNodes;
	for(var x = 0; x < menuItems.length; x++){
		if(menuItems[x].nodeName.toUpperCase() == "LI" && menuItems[x].id != 'forste'){
			menuItems[x].onmouseover = function(){this.style.backgroundColor='#2650DD'; this.style.cursor='pointer'; showMenu(this.id);}
			menuItems[x].onmouseout  = function(){delayedHideMenu(this.id);}
			
			document.getElementById('under' + menuItems[x].id).onmousemove = function(){showMenu(this.parentNode.id);}
			document.getElementById('under' + menuItems[x].id).onmouseout  = function(){delayedHideMenu(this.parentNode.id);}
			
			subMenues = document.getElementById('under' + menuItems[x].id).childNodes;
			for(var i = 0; i < subMenues.length; i++){
				if(subMenues[i].nodeName.toUpperCase() == "LI"){
					subMenues[i].onmouseover = function(){this.style.backgroundColor='#2650DD'; this.style.cursor='pointer';}
					subMenues[i].onmouseout  = function(){this.style.backgroundColor='#336AC4';}
					subMenues[i].onclick     = function(){window.location = this.getElementsByTagName('A')[0].href;}
				}
			}
		}else if(menuItems[x].id == 'forste'){
			menuItems[x].onmouseover = function(){this.style.backgroundColor='#2650DD';this.style.cursor='pointer';}
			menuItems[x].onmouseout = function(){this.style.backgroundColor='#336AC4';}
		}
	}
}
window.onload = function(){
	
	init();
}
