
function rvt_menu (navRoot) {
	this.menuLevels = new Array()
	this.removeTimeout = 1000;
	this.curTimer = 0;
	this.levelCounter = 0;
	this.zIndex = 100;
	this.init = init;
	this.navRoot = navRoot;
	this.clicked = 0;	
	byId(this.navRoot).obj = this;
	this.removeMenu = removeMenu;
	this.removeMenuTimed = removeMenuTimed;
	this.addMenu = addMenu;

	function init() {

		var lis=byId(this.navRoot).getElementsByTagName("LI");  
		for (i=0; i<lis.length; i++) {
			/* If the LI has another menu level */
			
			if(lis[i].lastChild.tagName=="UL") {

				// Kep act open
				atag = previousSibling(lis[i].lastChild, 'A');
				if (atag.className.indexOf('leftmenul1-act')>-1) {
					lis[i].lastChild.style.display="block";

				} else {
					lis[i].navRoot = this.navRoot;
					lis[i].wipe = 0;
	
					/* assign the function to the LI */
					lis[i].onclick = function() {		
						var navRoot = byId(this.navRoot);
						/* display the inner menu */
						navRoot.obj.clicked = 1;
						//atag = previousSibling(navRoot.current.lastChild, 'A');
						//atag.className = 'cur';
						//atag.blur();
					}				
					
					/* assign the function to the LI */
					lis[i].onmouseover = function() {
						var navRoot = byId(this.navRoot);
						this.lastChild.style.display="block";
						this.lastChild.style.zIndex=navRoot.zIndex++;
						navRoot.obj.levelCounter ++;
						navRoot.obj.removeMenu(this);
	
					//alert(this);
						/* display the inner menu */
	//					this.lastChild.style.height=1 + '%';
						if (this.wipe == 10)  {
							//dojo.lfx.html.wipeIn(this.lastChild, 400).play();
							m.lastChild.style.display="block"
							this.wipe=1;
						}
					}
					/* assign the function to the LI */
					lis[i].onmouseout = function() {		
						var navRoot = byId(this.navRoot);
						navRoot.obj.levelCounter --;
						navRoot.obj.addMenu(this);
						if (navRoot.obj.curTimer) {
							navRoot.obj.curTimer = clearTimeout(navRoot.obj.curTimer);
							navRoot.obj.curTimer = 0;
						}
							
						if (navRoot.obj.levelCounter == 0) {
							var thisObj = navRoot.obj;
							navRoot.obj.curTimer = setTimeout( function(){navRoot.obj.removeMenuTimed()}, navRoot.obj.removeTimeout);
						}
		
						//if ((this.getAttribute('state') != 'ACTIFSUB') && (this.obj.clicked == 0) ){
							/* hide the inner menu */
						//	this.lastChild.style.display="none"
						//}
					}
				}

			}
		}
	}	

	/* 
	 * Find next Siblings untill a tag is found
	 */
	function nextSibling(start, searchTag) {
		if (start)
			if (start.nextSibling.tagName == searchTag)
				return start.nextSibling;
			else
				return nextSibling(start.nextSibling, searchTag)
		return false;
	}
	
	/* 
	 * Find previoisSiblings untill a tag is found
	 */
	function previousSibling(start, searchTag) {
		if (start)
			if (start.previousSibling.tagName == searchTag)
				return start.previousSibling;
			else
				return previousSibling(start.previousSibling, searchTag)
		return false;
	}
	
	function removeMenuTimed() {
		var m = this.menuLevels.pop();
		while (m) {

		//	alert(m.getAttribute('state'));
			if ((m.getAttribute('state') != 'CUR') && (m.getAttribute('state') != 'ACTIFSUB') && (this.clicked == 0) ) {
				m.lastChild.style.display="none"
				//dojo.lfx.html.wipeOut(m.lastChild, 400).play();
			}
			m = this.menuLevels.pop();
			//m.lastChild.style.display="none";	
		}
		this.curTimer = 0;
	}
	
	function addMenu(menu) {
		this.menuLevels.push(menu);
	}
	
	function removeMenu(toRemove) {
		var l = this.menuLevels.length;
		var tMenu = Array();
		for (var i=0; i<l; i++) {
			if (this.menuLevels[i] != toRemove) 
				tMenu.push( this.menuLevels[i] );
		}
		this.menuLevels = tMenu;
	}


}

                                                                                                          