function EMenu()
{
	this.container=null; //容器
	this.isIE=(navigator.appName.toLowerCase()=="microsoft internet explorer"); //是否ie浏览器
	this.topMenuPadding=12;
	this.isTopMenu=true; //是否为顶层菜单
	this.showContainer=null; //显示在定义的容器中
	this.width=170; //宽度
	this.itemPadding=2; //菜单项缩进
	this.shadowPadding=6; //阴影缩进
	this.shadowPaddingTop=0; //头部阴影部分
	this.shadowPaddingBottom=10; //底部缩进
	this.backgroundImage="/ETSOO/Eajax/Menu/Skin/dropdown.png"; //背景图片路径
	this.backgroundColor="#ffffff";
	this.borderDarkColor="#666666";
	this.borderLightColor="#cccccc";
	this.arrowImage="/ETSOO/Eajax/Calendar/n.gif";
	this.lastPopMenu=null;
}
EMenu.prototype._initLevel=function(oUL, iLevel)
{
	var shadowPadding=this.shadowPadding+"px";
	var topMenuPaddingHalf=(this.topMenuPadding/2)+"px";
	var topMenuPadding=this.topMenuPadding+"px";
	var itemPadding=this.itemPadding+"px";
	var isIE=this.isIE;
	var isTopMenu=this.isTopMenu;
	if(iLevel>0)oUL.setAttribute("menu_item_container","Y");
	with(oUL.style)
	{
		listStyleType="none";
		padding="0px";
		margin="0px";
		
		if(iLevel>0)
		{
			width=this.width+"px";
			paddingBottom=this.shadowPaddingBottom+"px";
			position="absolute";
			zIndex=9999+iLevel;
			if(isIE&&window.XMLHttpRequest==null)
			{
				paddingTop=this.shadowPaddingBottom+"px";
				background=this.backgroundColor;
				borderLeft="1px solid "+this.borderLightColor;
				borderTop="1px solid "+this.borderLightColor;
				borderRight="1px solid "+this.borderDarkColor;
				borderBottom="1px solid "+this.borderDarkColor;
			}
			else
			{
				paddingTop=this.shadowPaddingTop+"px";
				background="transparent url("+this.backgroundImage+") no-repeat bottom center";
			}
			visibility="hidden";
		}
	}
	var len=oUL.childNodes.length;
	var o=this;
	for(var i=0;i<len;i++)
	{
		var child=oUL.childNodes[i];
		if(child.nodeType!=1)continue;
		
		child.setAttribute("menu_item_flag","Y");
		child.setAttribute("menu_item_level",iLevel);
		if(isIE)
		{
			child.attachEvent("onmouseover",function(event){o.doMouseOver(event)});
			child.attachEvent("onmouseout",function(event){o.doMouseOut(event)});
		}
		else
		{
			child.addEventListener("mouseover",function(event){o.doMouseOver(event)},false);
			child.addEventListener("mouseout",function(event){o.doMouseOut(event)},false);
		}
		with(child.style)
		{
			margin="0px";
			if(iLevel==0&&isTopMenu)
			{
				if(isIE)styleFloat="left";
				else cssFloat="left";
			}
			paddingLeft=topMenuPadding;
			paddingRight=topMenuPadding;
		}
		if(iLevel>0)
		{
			child.style.paddingTop=itemPadding;
			child.style.paddingBottom=itemPadding;
			child.style.marginLeft=shadowPadding;
		}
		var childMenu=this.getChildMenu(child);
		if(childMenu!=null)
		{
			childMenu.setAttribute("parentMenu",oUL);
			if(iLevel>0)
			{
				child.style.marginRight=(4+this.shadowPadding)+"px";
				child.style.background="transparent url("+this.arrowImage+") no-repeat center right";
			}
			this._initLevel(childMenu,iLevel+1);
		}
		else
		{
			if(iLevel>0)child.style.marginRight=shadowPadding;
		}
	}
}
EMenu.prototype.getChildMenu=function(child)
{
	var clen=child.childNodes.length;
	for(var h=1;h<clen;h++)
	{
		var childMenu=child.childNodes[h];
		if(childMenu.nodeType==1)
		{
			return childMenu;
		}
	}
	return null;
}
EMenu.prototype.init=function(menuContainer)
{
	this.container=menuContainer;
	if(menuContainer.style.visibility=="hidden")menuContainer.style.visibility="visible";
	if(menuContainer.childNodes.length==0)return;
	var topUL=menuContainer.childNodes[0];
	this._initLevel(topUL,0);
}
EMenu.prototype.getMenuItem=function(event)
{
	var target=event.target||event.srcElement;
	do
	{
		if(target.getAttribute("menu_item_flag")=="Y")return target;
		target=target.parentNode;
	}
	while(target!=null)
	return target;
}
EMenu.prototype.getPos=function(eE){
	var iLeft=0,iTop=0;
	if(eE.style.position=="absolute")
	{
		iLeft=parseInt(eE.style.left);
		iTop=parseInt(eE.style.top);
	}
	else
	{
		while(eE)
		{
			iLeft+=eE.offsetLeft;
			iTop+=eE.offsetTop;
			eE=eE.offsetParent;
			if(eE==null||eE.style.position=="absolute")break;
		}
	}
	return [iLeft,iTop];
}
EMenu.prototype.doMouseOver=function(event)
{
	var menuItem=this.getMenuItem(event);
	if(menuItem==null)return;
	var classNames=menuItem.className.split(/\s+/g);
	if(menuItem.className.indexOf(" menuItemOver")==-1)
	{
		classNames.push("menuItemOver");
		menuItem.className=classNames.join(" ");
	}
	var childMenu=this.getChildMenu(menuItem);
	if(childMenu==null)return;
	if(this.showContainer!=null)this.showContainer.appendChild(childMenu.cloneNode());
	else
	{
		var level=parseInt(menuItem.getAttribute("menu_item_level"));
		var pos=this.getPos(menuItem);
		var iLeft=pos[0]-this.shadowPadding+(level==0?0:(this.width-2*this.shadowPadding));
		var iTop=pos[1]+(level==0?menuItem.clientHeight:4);
		with(childMenu.style)
		{
			left=iLeft+"px";
			top=iTop+"px";
			visibility="visible";
		}
		this.lastPopMenu=childMenu;
	}
}
EMenu.prototype.contains=function(from,to)
{
    var bC=false;
    if(from){
        if(from.contains)bC=from.contains(to);
        else{while(to){if(to==from){bC=true;break;}to=to.parentNode;}}
    }
    return bC;
}
EMenu.prototype.collapseAll=function(collapseFrom)
{
	if(collapseFrom==null)collapseFrom=this.lastPopMenu;
	while(collapseFrom)
	{
		if(collapseFrom.getAttribute("menu_item_container")=="Y")collapseFrom.style.visibility="hidden";
		collapseFrom=collapseFrom.parentNode;
		if(collapseFrom==this.container)break;
	}
}
EMenu.prototype.doMouseOut=function(event)
{
	var menuItem=this.getMenuItem(event);
	if(menuItem==null)this.collapseAll();
	var classNames=menuItem.className;
	classNames=classNames.replace(" menuItemOver","");
	menuItem.className=classNames;

	if(this.showContainer!=null)this.showContainer.innerHTML="";
	else
	{
		var target=event.toElement||event.relatedTarget;
		if(target==null||(!this.contains(menuItem,target)&&menuItem.getAttribute("menu_item_level")==0))this.collapseAll();
		else if(!this.contains(menuItem,target))
		{
			//同级移动，关闭移出菜单项的子菜单
			if(this.contains(menuItem.parentNode,target))
			{
				var childMenu=this.getChildMenu(menuItem);
				if(childMenu!=null)childMenu.style.visibility="hidden";
			}
			else this.collapseAll();
		}
	}
}