function buildSubmenu(obj){
	lastOverId = obj.id;
	menuPath = obj.id.split('_');
	x = "div";
	for(i=0;i<menuPath.length;i++){
		x+= '_' + menuPath[i];
		if(document.getElementById(x)){
			if(tmr[x])
				window.clearTimeout(tmr[x]);
			document.getElementById(x).style.visibility = 'visible';
		}
	}
	if(submenu[obj.id]){
		//check if allready build...
		c = document.getElementById('div_' + obj.id);
		if(c){
			c.style.visibility = 'visible';
			c.style.zIndex = last_zIndex++;
		}else{
			d = obj;
			if(d){
				L_pos = d.offsetLeft + d.offsetWidth - 1;
				T_pos = d.offsetTop - 1;
				while(d.offsetParent){
					d = d.offsetParent;
					L_pos+= d.offsetLeft;
					T_pos+= d.offsetTop;
				}
			}
			if(obj.className.indexOf('menuItem') < 0 && alignSubmenu == 'bottom'){
				L_pos-= obj.offsetWidth;
				T_pos+= obj.offsetHeight;
			}
			subObj = document.createElement('div');
			subObj.id = 'div_' + obj.id;
			subObj.className = 'submenu';
			subObj.style.position = 'absolute';
			subObj.style.zIndex = last_zIndex++;
			subObj.style.width = menuWidth;
			subObj.style.top = T_pos-4;
			subObj.style.left = L_pos;
			document.getElementsByTagName('body')[0].appendChild(subObj);
			content = "";
			m = submenu[obj.id];
			for(i=0;i<m.length;i++){
				if(!m[i][2] || m[i][2] == '_self'){
					act = "self.location.href='" + m[i][1] + "';";
				}else if(m[i][2] == '_top'){
					act = "top.location.href='" + m[i][1] + "';";
				}else if(m[i][2] == '_blank'){
                    act = "window.open('" + m[i][1] + "');";
				}else{
					//get javascript target (not tested yet)
					//TODO: check how to do this cleanly
					act = "window.frames['"+m[i][2]+"'].location.href='" + m[i][1] + "';";
				}
				content+= "<div onmouseout=\"hideSubmenu(this)\" onmouseover=\"buildSubmenu(this)\" "+ (m[i][1] ? "onclick=\""+ act + "\" " : "") +"class=menuItem" + (i==0 ? 'First' : (i==(m.length -1) && useLastItemCSS ? 'Last' : '')) + " id=\"" + obj.id + "_" + i +"\">" + m[i][0] + "</div>";
				adj[i] = obj.id + "_" + i;
			}
			subObj.innerHTML = content;
			for(i=0;i<adj.length;i++)
				document.getElementById(adj[i]).style.width = subObj.style.width;
		}
	}
}
function hideSubmenu(obj){
	//get common part of div id
	closePath = obj.id.split('_');
	x = "div";
	for(i=0;i<closePath.length;i++){
		x+= '_' + closePath[i];
		if(document.getElementById(x))
			tmr[x] = window.setTimeout("document.getElementById('"+x+"').style.visibility = 'hidden';",500);
	}
}
function menuItem(txt,url,tar){
	return new Array(txt,url,tar);
}
function iFramePatch(){
	if(!document.all && lastOverId)
		hideSubmenu(document.getElementById(lastOverId));
}
if(navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('Opera')==-1){
	document.onmouseover = function(){
		obj = event.srcElement;
		if(obj.className == 'menuItemFirst' || obj.className == 'menuItem' || obj.className == 'menuItemLast')
			obj.className+='Over';
	}
	document.onmouseout = function(){
		obj = event.srcElement;
		if(obj.className == 'menuItemFirstOver' || obj.className == 'menuItemOver' || obj.className == 'menuItemLastOver')
			obj.className = obj.className.substring(0,(obj.className.length - 4));
	}
}