lastmenufocus=-1;
prevmenuobj=null;
prevmenurootobj=null;

function hidesubmenu(amenuobj) {
	adivlist=amenuobj.getElementsByTagName("DIV");
	j=0;
	while (j!=adivlist.length) {
		if (adivlist[j].className=="submenu") {
			adivlist[j].style.display="none";
			
		}
		if (adivlist[j].mousefuncbackup) {
			adivlist[j].onmouseover=adivlist[j].mousefuncbackup;
			adivlist[j].mousefuncbackup=null;
			adivlist[j].style.backgroundColor="#f7f6f1";
		}
		j++;
	}
	if (amenuobj.mousefuncbackup) {
		amenuobj.onmouseover=amenuobj.mousefuncbackup;
		amenuobj.mousefuncbackup=null;
		amenuobj.style.backgroundColor="#f7f6f1";
	}
}

function menugetrootitem(amenu) {
	while (amenu.parentNode.tagName=="DIV") { amenu=amenu.parentNode; }
	return amenu;
}

function menumouseover(aobj,amenuid) {
	//alert("over : "+String(amenuid));
	//alert(aobj.parentNode.id+" - "+lastmenufocus);
	if (lastmenufocus==amenuid) {
		if (prevmenurootobj && (aobj.id.indexOf("rootitem")==0) && (aobj.id!=prevmenurootobj.id)) {
			hidesubmenu(prevmenurootobj);
			lastmenufocus=-1;
			prevmenurootobj=null;
		}
		else {
			return; 
		}
	}

	submenuselected=aobj.parentNode.tagName=="DIV";
	
	if (aobj.parentNode.parentNode.mouseclickbackup) {
		aobj.parentNode.parentNode.onclick=aobj.parentNode.parentNode.mouseclickbackup;
		aobj.parentNode.parentNode.mouseclickbackup=null;
	}
	
	if ((lastmenufocus>=0) && (lastmenufocus!=amenuid)) {
		prevmenu=document.getElementById("menuitem"+String(lastmenufocus));
		if (!prevmenu) {
			prevmenu=document.getElementById("rootitem"+String(lastmenufocus));
		}
		if (!submenuselected) {
			prevmenu.style.backgroundColor="#f7f6f1";
		}
		selmenurootobj=menugetrootitem(aobj);
		if (selmenurootobj!=prevmenurootobj) { 
			hidesubmenu(prevmenurootobj); 
		}
		else {
			//divlist=aobj.parentNode.getElementsByTagName("DIV");
			divlist=aobj.parentNode.childNodes;
			i=0;
			while (i!=divlist.length) {
				if (divlist[i].className=="menuitemdiv") {
					hidesubmenu(divlist[i]);
				}
				i++;
			}
		}
	}
	prevmenuobj=aobj;
	prevmenurootobj=menugetrootitem(prevmenuobj);
	if (prevmenurootobj.onmouseover) {
		prevmenurootobj.mousefuncbackup=prevmenurootobj.onmouseover;
		prevmenurootobj.onmouseover=null;
	}
	if (aobj.onmouseover) {
		aobj.mousefuncbackup=aobj.onmouseover;
		aobj.onmouseover=null;
	}
	aobj.style.backgroundColor="#b3b2af";
	offsetx=0;
	offsety=0;
	if (submenuselected) {
		offsetx=offsetx+prevmenuobj.offsetLeft;
		offsety=offsety+prevmenuobj.offsetTop;
	}
	else {
		while (prevmenuobj.offsetParent) {
			offsetx=offsetx+prevmenuobj.offsetLeft;
			offsety=offsety+prevmenuobj.offsetTop;
			prevmenuobj=prevmenuobj.offsetParent;
		}
	}
	lastmenufocus=amenuid;
	achildlist=aobj.getElementsByTagName("DIV");
	if (aobj.id.indexOf("rootitem")!=0) {
		aobj.parentNode.parentNode.mouseclickbackup=aobj.parentNode.parentNode.onclick;
		aobj.parentNode.parentNode.onclick=null;
	}
	
	oldbodywidth=parseInt(document.body.scrollWidth);
	
	if (achildlist.length>0) {
		achildlist[0].style.position="absolute";
		if (aobj.id.indexOf("rootitem")==0) {
			achildlist[0].style.left=offsetx;
			achildlist[0].style.top=offsety+aobj.offsetHeight;
		}
		else {
			achildlist[0].style.left=offsetx+150;
			achildlist[0].style.top=offsety+10;
		}
		achildlist[0].style.display="block";
		asubmenu = achildlist[0].getElementsByTagName("DIV");
		
		if (iebrowser) {
			asublist=achildlist[0].getElementsByTagName("DIV");
			for (i=0; i!=asublist.length; i++) {
				if (asublist[i].className=="submenu") {
					asublist[i].style.display="block";
					asublist[i].style.display="none";
				}
			}
		}
		
		if ((achildlist[0].style.left+170+10)>parseInt(document.body.scrollWidth)) {
			achildlist[0].style.left=(offsetx-achildlist[0].offsetWidth)+20;
		}
		
		if (asubmenu[0].style.display=="none") {
			rightshadowobj=asubmenu[0];
			if (rightshadowobj.id=="rightshadow") {
				bottomshadowobj=asubmenu[1];
				awidth=achildlist[0].clientWidth;
				aheight=achildlist[0].clientHeight;
				
				rightshadowobj.style.left=awidth;
				rightshadowobj.style.width=6;
				rightshadowobj.style.top=6;
				rightshadowobj.style.height=aheight-6;
				rightshadowobj.style.display="block";
				
				bottomshadowobj.style.top=aheight;
				bottomshadowobj.style.height=6;
				bottomshadowobj.style.left=6;
				bottomshadowobj.style.width=awidth;
				bottomshadowobj.style.display="block";
			}
		}
	}
}

function documentmousemove(event) {
	e=(!event ? window.event : event);
	if (iebrowser) {
		posx=e.clientX+document.body.scrollLeft;
		posy=e.clientY+document.body.scrollTop;
		obj=document.elementFromPoint(posx,posy);
	}
	else {
		obj=e.target;
	}
	if ((obj.className!=null) && ((obj.className=="menuitemdiv") || (obj.className=="menuitemlink") || (obj.className=="rootmenuitemlink") || (obj.className=="submenu"))) { 
	}
	else if (lastmenufocus!=-1) {
		hidesubmenu(prevmenurootobj);
		lastmenufocus=-1;
		prevmenurootobj=null;
	}
}

function menuclick(aobj) {
	if (lastmenufocus==-1) { return; }
	lastmenufocus=0;
	anchorlist = aobj.getElementsByTagName("A");
	anchor = anchorlist[0];
	window.location=anchor.href;
}

