﻿function class_TopMenu($)
{
	var box=$("#pageHead_ulMenuBox");
	var menus=box.find(">li");
	var preMenu=null;

	this.Init=function()
	{
		var channel=$("body").attr("channel");

		for(var i=0;i<menus.length;i++)
		{
			var li=menus.eq(i);
			if(li.attr("menu")!=null)
			{
				var menu=$("#"+li.attr("menu"));
				li[0].menu=menu;
				menu[0].li=li;
				menu.hide();
				li.hover(li_MouseOver,li_MouseOut);
				menu.hover(menu_MouseOver,menu_MouseOut);
				$("#pagetop").after(menu);
			}
			var text=li.text();
			if(text.toLower()==channel.toLower())
			{
				li.addClass("active");
			}
		}
	}

	function li_MouseOver(e)
	{
		if($(this.menu).css("display")!="none")
		{
			this.getfocus=true;
			return;
		}
		if(preMenu!=null)
			preMenu.hide();
		this.getfocus=true;
		var li=$(this);
		var menu=$(this.menu);
		var pos=li.offset();
		var left=pos.left+"px";
		var top=(pos.top+li.height())+"px";
		menu.css("left",left);
		menu.css("top",top);
		menu.show();
		preMenu=menu;
	}

	function li_MouseOut(e)
	{
		this.getfocus=null;
		var li=this;
		var menu=$(this.menu);
		window.setTimeout(function(){
			if(menu[0].getfocus==null&&li.getfocus==null)
			{
				menu.hide();
			}
		},200);
	}

	function menu_MouseOver(e)
	{
		this.getfocus=true;
	}

	function menu_MouseOut(e)
	{
		this.getfocus=null;
		var li=this.li[0];
		var menu=$(this);
		window.setTimeout(function(){
			if(li.getfocus==null&&menu[0].getfocus==null)
			{
				menu.hide();
			}
		},200);
	}
}

$(function()
{
	var cls=new class_TopMenu($);
	cls.Init();
});