var menuids=["menuid","menuid2"] //Enter id(s) of SuckerTree UL menus, separated by commas

function buildsubmenus(){
	for (var i=0; i<menuids.length; i++){
	var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul");
	for (var t=0; t<ultags.length; t++){
	  ultags[t].parentNode.getElementsByTagName("a")[0].className="subfolderstyle";
	  ultags[t].parentNode.onmouseover=function(e){
		this.getElementsByTagName("ul")[0].isMouseOver=true;
		this.getElementsByTagName("ul")[0].style.display="block";
		//this.getElementsByTagName("ul")[0].style.left="165px";
		this.getElementsByTagName("ul")[0].style.visibility="visible";
		//this.getElementsByTagName("ul")[0].style.left = this.getElementsByTagName("a")[0].offsetWidth+"px";
		this.getElementsByTagName("ul")[0].style.left = this.parentNode.offsetWidth+"px";
		
			
		var absPosNavi = 0;
		elementId=document.getElementById("navi");
		while( elementId != null ){
			absPosNavi += elementId.offsetTop;
			elementId = elementId.offsetParent;
		}
		
		var absPosSubNavi = 0;
		elementTag=this.getElementsByTagName("ul")[0];
		while( elementTag != null ){
			absPosSubNavi += elementTag.offsetTop;
			elementTag = elementTag.offsetParent;
		}
		
		
		var bottomNavi = absPosNavi + document.getElementById("navi").offsetHeight;
		var bottomSubNavi = absPosSubNavi + this.getElementsByTagName("ul")[0].offsetHeight;
		var diffNavis = bottomNavi - bottomSubNavi -10; // -10, automatic offset of submenu
		
		if (bottomSubNavi > bottomNavi){
			this.getElementsByTagName("ul")[0].style.top = diffNavis+"px";
		}			
		//alert("Bottom of Menu Container:  "+ bottomV +" px     Bottom of SubMenu: " + bottomV2 + " px    Move up: " + diffY + " px");

		hideAllOther(this);
	
		if(this.toref)
			window.clearTimeout(this.toref);
	  }
	  ultags[t].parentNode.onmouseout=function(){
		var saveref=this.getElementsByTagName("ul")[0];
		saveref.isMouseOver=false;
		if(this.toref)
			window.clearTimeout(this.toref);
		
		this.toref=window.setTimeout(function(e){
		  if(!saveref.isMouseOver)
			saveref.style.display="none"
		},300);
	  }
	}
	}
}

function hideAllOther(liobj){
  var p=liobj.parentNode.childNodes;
  
  //alert(liobj.parentNode.childNodes[3]);
  //alert(p);
  var i;
try{
  for (i=0; i<p.length; i++){
    if (liobj != p[i] && "LI"==p[i].tagName && p[i].getElementsByTagName("ul").length)
      p[i].getElementsByTagName("ul")[0].style.display="none";
  }
  }catch(e){
    alert(p[i].innerHTML)
  }

}

if (window.addEventListener)
  window.addEventListener("load", buildsubmenus, false)
else if (window.attachEvent)
  window.attachEvent("onload", buildsubmenus)
