decalage = 115;

getTop = function(element) {
	var cursor;
	var baseTop = 0;
	for (cursor=element;cursor.offsetParent;cursor = cursor.offsetParent) {
		baseTop += cursor.offsetTop;
	}
	return baseTop;
}
getLeft = function(element) {
	var cursor;
	var baseLeft = 0;
	for (cursor=element;cursor.offsetParent;cursor = cursor.offsetParent) {
		baseLeft += cursor.offsetLeft;
	}
	return baseLeft;
}

activateMenu = function(nav) {
	var i,j;

	var navroot = document.getElementById(nav);
	
	var navpointer = document.getElementById("educnav-pointer"); 
		/* ^ has to be hardcoded here because we don't know who's the parent menu */
	
	/* Get all the list items within the menu */
	var lis=navroot.getElementsByTagName("LI");  
	for (i=0; i<lis.length; i++) {
		for (j=0; j<lis[i].childNodes.length; j++) {
			if (lis[i].childNodes[j].tagName=="UL") {
				/* calculate base top and left coordinates */
				var baseLeft = getLeft(lis[i]);
				var baseTop = getTop(lis[i]);

				/* calculate sub menu absolute coordinates */
				lis[i].childNodes[j].style.left = (baseLeft+decalage) + "px";
				lis[i].childNodes[j].style.top = (baseTop-20)+"px";

				/* FIXME : correct the -20 to -44 if offsetHeight is enough high. will need test menus */

				/* assign the function to the LI */
				
				lis[i].onmouseover=function() {	
					currentmenu = lis[i];
					/* display the inner menu */
					for (j=0; j<this.childNodes.length; j++) 
						if (this.childNodes[j].tagName=="UL") {
							this.childNodes[j].style.display="block";
					
							/* position and display the pointer */
							for (k=0;k<this.childNodes[j].childNodes.length;k++) 
								if (this.childNodes[j].childNodes[k].tagName=="DIV") {
									var navpointer = this.childNodes[j].childNodes[k];
									//navpointer.style.left = (getLeft(this)) + "px";
									navpointer.style.left = (0) + "px";
									navpointer.style.top = (20) + "px";
								}
							/*
							var navpointer = document.getElementById("educnav-pointer"); 
							navpointer.style.left = (this.childNodes[j].offsetLeft+7) + "px";
							navpointer.style.top = (getTop(this)+1) + "px";
							navpointer.style.display = "block";*/
						}
				}

				lis[i].onmouseout=function() {   
					for (j=0; j<this.childNodes.length; j++) {
						if (this.childNodes[j].tagName=="UL") {
							this.childNodes[j].style.display="none";
						}
					}
	
					/* hide pointer */
					var navpointer = document.getElementById("educnav-pointer"); /* name has to be hardcoded here because we don't know who's the parent menu */
					navpointer.style.display = "none";
				
				}
			}
		}
	}
}
