
//Level,ID,Text,Url,children direction
function MenuItem(level,id,text,url,cd)
{
    this.level = level;
    this.id = id;
    this.text = text;
    this.url = url;
    this.direction = cd;
    
    //Children Area
    this.area = document.createElement("DIV");    
    this.area.className = "childrenarea";
    this.area.style.visibility = "hidden";
	this.area.style.position = "absolute";
	this.area.style.left = "0px"; 
    this.focus = Item_Focus;
    this.add = Item_Add;
    this.blur = Item_Blur;
    this.bind = Item_Bind;

	//MenuItem Html Object
	if(level == 1)
		this.bind(document.createElement("A"));
    else
		this.bind(document.createElement("DIV"));
    
    
    //Child menus
    this.children = new Array();   
}

//Bind a html object to the menu item
function Item_Bind(e)
{
    e.obj = this;
    e.innerText = this.text;
    e.type = "menu";
    e.className = "menuitem";
    e.attachEvent("onmouseover", Menu_MouseOver);
    e.attachEvent("onmouseout", Menu_MouseOut);
    e.attachEvent("onclick", Menu_Click);
    this.element = e;
}

//Get focus
function Item_Focus()
{
    if( this.area != null)
    {
        //Close the same level actived menus
        CloseMenu(this.level);
        
        //Save actived menu of all levels to window.activeMenuArea
        if( !window.activeMenuArea )
        {
            window.activeMenuArea = new Array();
        }
        
        //Set active menu of current level
        window.activeMenuArea[this.level] = this.area;
        
        //Expand child area if has children
        if( this.children.length > 0)
        {
			if( this.direction == "h") //horizontal
			{
				this.area.style.left = getoffset(this.element)[1] + this.element.offsetWidth;
				this.area.style.top = getoffset(this.element)[0];	
			}
			else	//vertical
			{				
				this.area.style.left = getoffset(this.element)[1];
				this.area.style.top = getoffset(this.element)[0] + this.element.offsetHeight;
			}
            this.area.style.visibility = "visible";
        } 
    }
    
    this.element.className = "menuover";
}

//Lost focus,(the close function put on document.onclick event)
function Item_Blur()
{
    this.element.className = "menuitem";        
}

//Add child menu
function Item_Add(child)
{
    this.children.push(child);
    this.area.insertBefore(child.element);
}

//Event on mouse over menuitem
function Menu_MouseOver()
{
    if( event.srcElement.obj)
        event.srcElement.obj.focus();
}

//Event on mouse out menuitem
function Menu_MouseOut()
{
    if( event.srcElement.obj)
        event.srcElement.obj.blur();
}

//Click item menu
function Menu_Click()
{
    if( event.srcElement.obj && event.srcElement.obj.url != null && event.srcElement.target != "_blank")
    {
        window.navigate(event.srcElement.obj.url);
    }
}

//Close the active menu of a special level
function CloseMenu(level)
{      
    if( window.activeMenuArea != null)
    {
        if( level == 0)
        {
            for(i=0;i<window.activeMenuArea.length;i++)
            {
                if( window.activeMenuArea[i])
                    window.activeMenuArea[i].style.visibility = "hidden";        
            }
        }
        else
        {
            if( window.activeMenuArea[level])
                window.activeMenuArea[level].style.visibility = "hidden";
        }
    }
}

function getoffset(e) 
{  
 var t=e.offsetTop;  
 var l=e.offsetLeft;  
 while(e=e.offsetParent) 
 {  
  t+=e.offsetTop;  
  l+=e.offsetLeft;  
 }  
 var rec = new Array(1); 
 rec[0]  = t; 
 rec[1] = l; 
 return rec; 
} 


//Close all menus on document.onclick
document.onclick = function(){
    if(!event.srcElement.type || event.srcElement.type !="menu")
    {
        CloseMenu(0);
    }    
}

var menus = new Array();
		var menuContainer = document.getElementById('mainmenu'); 
		var menu; 
							menu = new MenuItem(1, "0","首页", "/");menu.bind(document.getElementById("HomeMenu_lnk0")); menus.push(menu);
											menu = new MenuItem(1, "1","关于我们", "/other/aboutus.html");menu.bind(document.getElementById("HomeMenu_lnk1")); menus.push(menu);
											menu = new MenuItem(1, "2","产品信息", "/showroom-list.html");menu.bind(document.getElementById("HomeMenu_lnk2")); menus.push(menu);
															menu.add( new MenuItem(2, "54683", "搅拌站", "/搅拌站-c465.html"));
									menu.add( new MenuItem(2, "54683", "搅拌楼", "/搅拌楼-c466.html"));
									menu.add( new MenuItem(2, "54683", "混凝土搅拌机", "/混凝土搅拌机-c468.html"));
									menu.add( new MenuItem(2, "54683", "配料机", "/配料机-c493.html"));
									menu.add( new MenuItem(2, "54683", "沙石分离机", "/沙石分离机-c494.html"));
									menu.add( new MenuItem(2, "54683", "电磁选矿设备", "/电磁选矿设备-c495.html"));
									menu.add( new MenuItem(2, "54683", "螺旋输送机", "/螺旋输送机-c496.html"));
									menu.add( new MenuItem(2, "54683", "皮带输送机", "皮带输送机-c497.html"));
									menu.add( new MenuItem(2, "54683", "水泥仓", "/水泥仓-c498.html"));
									menu.add( new MenuItem(2, "54683", "混凝土输送泵", "/混凝土输送泵-c843.html"));
									menu.add( new MenuItem(2, "54683", "塔式提升机", "/塔式提升机-c844.html"));
									menu.add( new MenuItem(2, "54683", "吊篮", "/吊篮-c845.html"));
												menu = new MenuItem(1, "3","资讯中心", "/al.html");menu.bind(document.getElementById("HomeMenu_lnk3")); menus.push(menu);
												menu.add( new MenuItem(2, "54683", "企业资讯", "/a502.html"));
									menu.add( new MenuItem(2, "54683", "行业信息", "/a503.html"));
															menu = new MenuItem(1, "4","企业荣誉", "/Ujiaobanzhan/502-2335.html");menu.bind(document.getElementById("HomeMenu_lnk4")); menus.push(menu);
											menu = new MenuItem(1, "5","生产现场", "/Ujiaobanzhan/502-2337.html");menu.bind(document.getElementById("HomeMenu_lnk5")); menus.push(menu);
											menu = new MenuItem(1, "6","招聘信息", "/other/job.html");menu.bind(document.getElementById("HomeMenu_lnk6")); menus.push(menu);
											menu = new MenuItem(1, "7","信息反馈", "/other/SiteMessage.html");menu.bind(document.getElementById("HomeMenu_lnk7")); menus.push(menu);
											menu = new MenuItem(1, "8","联系我们", "/other/ConactUs.html");menu.bind(document.getElementById("HomeMenu_lnk8")); menus.push(menu);
											menu = new MenuItem(1, "9","English", "http://en.yujianjx.com/");menu.bind(document.getElementById("HomeMenu_lnk9")); menus.push(menu);
										for(i = 0; i< menus.length; i++) { menuContainer.insertBefore(menus[i].area); }
