var MenuHideTimer=50;


var curTimer = levelCounter = 0;
var zIndex = 100;
var menuLevels = new Array()
function activateA(cur) {
	var t = cur;
	
	if (t) {
		if (t.className.search('firstlevellink') >= 0) {
			t.className = t.className + ' hoveratag';
		}
	}
}

function deActivateA(cur) {
	var t = cur;
	if (t) {
		t=t.firstChild;
		if (t) {
			t.className=t.className.replace(/\ hoveratag/g, "");
		}
	}
}

function removeMenuTimed() {

	var m = menuLevels.pop();
	while (m) {
		deActivateA(m);
		//if (m.lastChild)
			m.lastChild.style.display="none";	
		m = menuLevels.pop();
	}
	curTimer = 0;
}

function addMenu(menu) {
	menuLevels.push(menu);
}

function removeMenu(toRemove) {
	var l = menuLevels.length;
	var tMenu = Array();
	for (var i=0; i<l; i++) {
		if (menuLevels[i] != toRemove) 
			tMenu.push( menuLevels[i] );
	}
	menuLevels = tMenu;
}

activateTopMenu = function(nav) {
	var navroot = document.getElementById(nav);
	/* Get all the list items within the menu */
	var lis=navroot.getElementsByTagName("LI");  
	for (i=0; i<lis.length; i++) {
		/* If the LI has another menu level */
		
		if(lis[i].lastChild.tagName=="UL"){
			/* assign the function to the LI */
			lis[i].onmouseover = function() {		

				/* display the inner menu */
				this.lastChild.style.display="block";
				this.lastChild.style.zIndex=zIndex++;
				activateA(this.firstChild);

				levelCounter ++;
				removeMenu(this);
				// $('debugger').innerHTML = $('debugger').innerHTML + '+' + level;
			}
			lis[i].onmouseout = function() {       
				//deActivateA(this.lastChild);
				levelCounter --;
				addMenu(this);
				if (curTimer) {
					curTimer = clearTimeout(curTimer);
					curTimer = 0;
				}
					
				if (levelCounter == 0) {
					curTimer = setTimeout("removeMenuTimed()", MenuHideTimer);
				}
				// $('debugger').innerHTML = $('debugger').innerHTML + '-' + level;
			}
		}
	}

}

