﻿var rowid=0;
var IconList = new Array();   
	IconList[1] = new Image();
//	IconList[1].src = "../images/bg_me.gif";
	IconList[1].src = "../../../757fshyres/images/pctm/edit.gif";

var SubMenuList = new Array();
var NowSubMenu = "";
var mouseCanSound = false;
var menuSpeed=50;
var alphaStep=30;

function TopMenu(objName,L,T,objcontainer,num)
{	
	var htmlstr=""
	
	//alert(htmlstr);
	this.id="Menu_"+objName;
	this.obj=objName;
	this.length=0;
	this.L=L;
	this.T=T;
	//this.objcontainer = objcontainer;
	this.addTopMenu = addTopMenu;
	this.addTopLink = addTopLink;
	this.returnAll  = returnAll;
	
	htmlstr='<div id="temp_'+this.id+'" style="display: none;"><table id="'+this.id+'" width="171" border="0" cellspacing="0" cellpadding="0">'
	for(i=0;i<num;i++)
	{
			htmlstr+='<tr></tr>'
	}
	htmlstr+='</table></div>'
	
	eval(objcontainer).insertAdjacentHTML('afterBegin',htmlstr);
}
function returnAll(str)
{
	var obj = eval("temp_"+this.id);
	str = eval(str)
	var tempstr = obj.innerHTML
	obj.outerHTML = "";
	str.insertAdjacentHTML('beforeEnd',tempstr)
}
function SubMenu(objName,objID)
{
	this.obj = objName;
	this.id  = objID;
	this.addMenu = addMenu;
	this.addLink = addLink;
	this.addHR   = addHR;
	this.length  = 0;
}
//-------------- 主菜单对象 addTopMenu 方法 ------------//
function addTopMenu(word,icon,title,objcontainer)
{
	var subID    = this.id + "_" + this.length;
	var subObj  = this.obj+"["+this.length+"]";
	var oldID   = this.id;
	eval(subObj+"= new SubMenu('"+subObj+"','"+subID+"')");
	makeTopMenu(subID,oldID,word,icon,title,objcontainer);
	this.length++;
}
//------------- 主菜单对象 addTopLink 方法 -------------//
function addTopLink(word,icon,url,target,title)
{
	var subID    = this.id + "_" + this.length;
	var oldID  = this.id;
	makeTopLink(subID,oldID,word,icon,url,target,title);
	this.length++;	
}
//-------------- 生成 菜单 makeTopMenu 方法 -----------//
function makeTopMenu(subID,oldID,word,icon,thetitle,objcontainer)
{
	if(icon&&icon!="")
	{
		icon = '<img border="0" src="'+IconList[icon].src+'">';
	}
	else
	{
		icon = '';
	}
	
	if(!thetitle||thetitle=="")
	{
		thetitle = '';
	}
	
	
	var Oobj = document.getElementById(oldID);
	var TempTableStr = '<table width="171" height="24" border="0" cellspacing="0" cellpadding="0" style="font-size: 12px">'
					 + '<tr id="tr'+subID+'" onmousedown="TMtrClick(this)" onmouseover="MtrOver(this,1);this.MH=false" title="'+thetitle+'" onmouseup="event.cancelBubble=true">'
					 + ''
					 + '<td width="171" align="left" class="ProductCategoryExhibitLadder_div1"><nobr>'+word+'</nobr></td>'
					 + ''
					+ '</tr></table>'
	
	Oobj.rows(rowid).insertCell().innerHTML = TempTableStr;
	rowid++;
	eval(objcontainer).insertAdjacentHTML('beforeEnd','<table id="'+subID+'" border="0" cellspacing="0" cellpadding="0" style="top: 0; left: 0; visibility: hidden; filter:Alpha(Opacity=0);" class="DropdownMenuNavigationShow_menutable"><tr><td></td><td></td></tr></table>');
}
//---------------- 生成连接 makeTopLink 方法 ------------//
function makeTopLink(subID,oldID,word,icon,url,target,thetitle)
{
	var thelink = '';
	if(icon&&icon!="")
	{
		icon = '<img border="0" src="'+IconList[icon].src+'">';
	}
	else
	{
		icon = '';
	}
	
	if(!thetitle||thetitle=="")
	{
		thetitle = '';
	}
	
	
	if(url&&url!="")
	{
		thelink += '<a class="DropdownMenuNavigationShow_a" href="'+url+'" ';
		
		if(target&&target!="")
		{
			thelink += '  ';
			thelink += 'target="'+target+'" '
		}
		
		thelink += '>';
	}
	
	var Oobj = document.getElementById(oldID);
	var TempTableStr = '<table width="171" height="24" border="0" cellspacing="0" cellpadding="0" style="font-size: 12px">'
					 + '<tr id="tr'+subID+'" title="'+thetitle+'">'					 
					 + ''
					 + '<td width="171" align="left" class="ProductCategoryExhibitLadder_div1">'+thelink + word +'</a></td>'
					 + ''
					 + '</tr></table>'
	
	Oobj.rows(rowid).insertCell().innerHTML = TempTableStr		
	rowid++;
}
//-------------- 菜单对象 addMenu 方法 ------------//
function addMenu(word,icon,url,target,title,objcontainer)
{
	var subID    = this.id + "_" + this.length;
	var subObj  = this.obj+"["+this.length+"]";
	var oldID   = this.id;
	eval(subObj+"= new SubMenu('"+subObj+"','"+subID+"')");
	makeMenu(subID,oldID,word,icon,url,target,title,objcontainer);
	this.length++;
		
}
//------------- 菜单对象 addLink 方法 -------------//
function addLink(word,icon,url,target,title)
{
	var subID    = this.id + "_" + this.length;
	var oldID  = this.id;
	makeLink(subID,oldID,word,icon,url,target,title);
	this.length++;	
}
//------------ 菜单对象 addHR 方法 -----------------//
function addHR()
{
	var oldID = this.id;
	var Oobj = document.getElementById(oldID);
	Oobj.insertRow();
	Oobj.rows(Oobj.rows.length-1).insertCell();
	with(Oobj.rows(Oobj.rows.length-1))
	{
		cells(0).colSpan= 0;
		cells(0).insertAdjacentHTML('beforeEnd','<hr class="DropdownMenuNavigationShow_menuhr" size="1" width="95%">');		
	}	
	
}
//-------------- 生成 菜单 makeMenu 方法 -----------//
function makeMenu(subID,oldID,word,icon,url,target,thetitle,objcontainer)
{
	var thelink = '';
	if(icon&&icon!="")
	{
		icon = '<img border="0" src="'+IconList[icon].src+'">';
	}
	else
	{
		icon = '·';
	}
	
	if(!thetitle||thetitle=="")
	{
		thetitle = '';
	}
	if(url&&url!="")
	{
		thelink += '<a href="'+url+'" ';
		
		if(target&&target!="")
		{
			thelink += '  ';
			thelink += 'target="'+target+'" '
		}
		
		thelink += '></a>';
	}
	
	var Oobj = document.getElementById(oldID);

	Oobj.insertRow();
	

	with(Oobj.rows(Oobj.rows.length-1))
	{
		id 			= "tr"+subID;
		className	= "DropdownMenuNavigationShow_menutroutimg";
		
		title       = thetitle;

	}
	
	eventObj = "tr"+subID;
  
	eval(eventObj+'.attachEvent("onmouseover",MtrOver('+eventObj+'))');	
	eval(eventObj+'.attachEvent("onclick",MtrClick('+eventObj+'))');	
		
	var trObj = eval(eventObj);
 	for(i=0;i<4;i++)
	{
		trObj.insertCell();
	}
	
	
		thelink += '<a class="DropdownMenuNavigationShow_a" href="#">·';

		with(Oobj.rows(Oobj.rows.length-1))
	{

		cells(0).className = "ProductCategoryExhibitLadder_div12";
		cells(0).innerHTML = thelink+word+'</a><span class="DropdownMenuNavigationShow_menutd1">4</span>';
		
	}	
	//三级
	eval(objcontainer).insertAdjacentHTML('beforeEnd','<table width=100 id="'+subID+'" border="0" cellspacing="0" cellpadding="0" style="top: 0; left: 0; visibility: hidden; filter:Alpha(Opacity=0);" class="DropdownMenuNavigationShow_menutable"></table>');
}

//---------------- 生成连接 makeLink 方法 ------------//
function makeLink(subID,oldID,word,icon,url,target,thetitle)
{
	var thelink = '';
	if(icon&&icon!="")
	{
		icon = '<img border="0" src="'+IconList[icon].src+'">';
	}
	else
	{
		icon = '';
	}
	
	if(!thetitle||thetitle=="")
	{
		thetitle = '';
	}
	if(url&&url!="")
	{
		thelink += '<a class="DropdownMenuNavigationShow_a" href="'+url+'" ';
		
		if(target&&target!="")
		{
			thelink += '  ';
			thelink += 'target="'+target+'" '
		}
		
		thelink += '>·';
	}
	
	var Oobj = document.getElementById(oldID);
	Oobj.insertRow();
	with(Oobj.rows(Oobj.rows.length-1))
	{
		id 			= "tr"+subID;
		className	= "DropdownMenuNavigationShow_menutroutimg";		
		title       = thetitle;

	}
	eventObj = "tr"+subID;
	eval(eventObj+'.attachEvent("onmouseover",LtrOver('+eventObj+'))');	
	eval(eventObj+'.attachEvent("onmouseout",LtrOut('+eventObj+'))');		
	eval(eventObj+'.attachEvent("onclick",MtrClick('+eventObj+'))');	
	var trObj = eval(eventObj);
	for(i=0;i<4;i++)
	{
		trObj.insertCell();
	}

	with(Oobj.rows(Oobj.rows.length-1))
	{

		cells(0).className = "ProductCategoryExhibitLadder_div12";
		cells(0).innerHTML = thelink+word+'</a>';

	}	

}
//--------- MtrOver(obj,isTop)-------------------//
function MtrOver(obj,isTop)
{
if(isTop)
{
		var sonid = obj.id.substring(2,obj.id.length);
		var topobj = obj.parentElement.parentElement; 
		
		NowSubMenu = topobj.id;
		if(obj.className=="DropdownMenuNavigationShow_menutroutimg")
		{
			mouseWave();
		}		
		HideMenu(1);		
		SubMenuList[returnIndex(NowSubMenu)] = NowSubMenu;
		if(isTop)
		{
			ShowTheMenu(sonid,100)		
		}
		else
		{
				ShowTheMenu(sonid,MPreturn(sonid))		
		}		
		
		SubMenuList[returnIndex(obj.id)] = sonid;
		if(topobj.oldTR)
		{ 
			eval(topobj.oldTR+'.className = "DropdownMenuNavigationShow_menutroutimg"'); 
		} 
    //obj.className = "DropdownMenuNavigationShow_menutrinimg"; 
    topobj.oldTR = obj.id; 
}
else
{
	return sub_over;
	
	function sub_over()
	{
	
		var sonid = obj.id.substring(2,obj.id.length);
		var topobj = obj.parentElement.parentElement; 
    NowSubMenu = topobj.id;
		if(obj.className=="DropdownMenuNavigationShow_menutroutimg")
		{
			mouseWave();
		}		
	  HideMenu(1);		
		SubMenuList[returnIndex(NowSubMenu)] = NowSubMenu;
		if(isTop)
		{
			ShowTheMenu(sonid,100)		
		}
		else
		{
				ShowTheMenu(sonid,MPreturn(sonid))		
		}		
		SubMenuList[returnIndex(obj.id)] = sonid;
		if(topobj.oldTR)
		{ 
			eval(topobj.oldTR+'.className = "DropdownMenuNavigationShow_menutroutimg"'); 
		}
    //obj.className = "DropdownMenuNavigationShow_menutrinimg"; 
    topobj.oldTR = obj.id; 
}
}	
}
//--------- LtrOver(obj,isTop)-------------------//
function LtrOver(obj,isTop)
{
if(isTop)
{
		var topobj = obj.parentElement.parentElement; 
		NowSubMenu = topobj.id;
		HideMenu(1);
		SubMenuList[returnIndex(NowSubMenu)] = NowSubMenu;
		if(topobj.oldTR)
		{ 
			eval(topobj.oldTR+'.className = "DropdownMenuNavigationShow_menutroutimg"'); 
		} 
		//obj.className = "DropdownMenuNavigationShow_menutrinimg"; 
		topobj.oldTR = obj.id; 
}
else
{
	return sub_over;
	
	function sub_over()
	{
		var topobj = obj.parentElement.parentElement; 
		NowSubMenu = topobj.id;
		HideMenu(1);
		SubMenuList[returnIndex(NowSubMenu)] = NowSubMenu;
		if(topobj.oldTR)
		{ 
			eval(topobj.oldTR+'.className = "DropdownMenuNavigationShow_menutroutimg"'); 
		} 
    //obj.className = "DropdownMenuNavigationShow_menutrinimg"; 
    topobj.oldTR = obj.id; 
    }
}	
}

//--------- LtrOut(obj,isTop)-------------------//
function LtrOut(obj,isTop)
{
if(isTop)
{
		var topobj = obj.parentElement.parentElement; 
		//obj.className = "DropdownMenuNavigationShow_menutroutimg"; 
		topobj.oldTR = false; 
}
else
{
	return sub_out;
	
	function sub_out()
	{
		var topobj = obj.parentElement.parentElement; 
		//obj.className = "DropdownMenuNavigationShow_menutroutimg"; 
		topobj.oldTR = false; 
	}
}	
}

//----------MtrClick(obj,isTop)-----------------//

function MtrClick(obj,isTop)
{
if(isTop)
{
		if(obj.cells(1).all.tags("A").length>0)
		{
			obj.cells(1).all.tags("A")(0).click();
		}	
}
else
{
	return sub_click;
	function sub_click()
	{
		if(obj.cells(1).all.tags("A").length>0)
		{
			obj.cells(1).all.tags("A")(0).click();
		}	
		
	}
}	
}


//----------TMtrClick(obj)-----------------//

function TMtrClick(obj)
{
	if(obj.MH)
	{
		MtrOver(obj,1)
		obj.MH = false;
	}
	else
	{	
		document.onmouseup()
	  obj.MH = true;
	}
}

//---------- returnIndex(str)--------------//

function returnIndex(str)
{
	return (str.split("_").length-3)
}


//---------ShowTheMenu(obj,num)-----------------//

function ShowTheMenu(obj,num)
{
	var oxwidth=document.body.clientWidth;
	var topobj = eval(obj.substring(0,obj.lastIndexOf("_")));
  	var SrcObj  = eval(topobj.id.split("_")[1])
	var ML      = 0

	var oxk=0.5
	//alert(oxwidth);
	oxwidth=(1008-(oxwidth<778?778:oxwidth))*oxk;

	if(SrcObj.L)
	{
		ML			+= eval(SrcObj.L)
	}		
	var MT      = 0
	if(SrcObj.T)
	{
		MT			+= eval(SrcObj.T)
	}
	//alert(num);
	var trobj  = eval("tr"+obj);
	var obj = eval(obj);
	var TheTDLeftSelf = trobj.parentElement.parentElement.parentElement.offsetLeft;
	var TheTDLeft = trobj.parentElement.parentElement.parentElement.offsetLeft;
	var TheTDTop = 	trobj.parentElement.parentElement.parentElement.offsetTop;
	if(num==0)
	{
		with(obj.style)
		{
			pixelLeft = topobj.style.pixelLeft + topobj.offsetWidth;
			pixelTop  = topobj.style.pixelTop + trobj.offsetTop;
		}
	}
	if(num==1)
	{
		with(obj.style)
		{
			pixelLeft = topobj.style.pixelLeft + topobj.offsetWidth;
			pixelTop  = topobj.style.pixelTop  + trobj.offsetTop;// + trobj.offsetHeight - obj.offsetHeight;
		}
	}
	if(num==2)
	{
		with(obj.style)
		{
			pixelLeft = topobj.style.pixelLeft -  obj.offsetWidth;
			pixelTop  = topobj.style.pixelTop + trobj.offsetTop;
		}	
	}
	if(num==3)
	{
		with(obj.style)
		{
			pixelLeft = topobj.style.pixelLeft -  obj.offsetWidth;
			pixelTop  = topobj.style.pixelTop  + trobj.offsetTop + trobj.offsetHeight - obj.offsetHeight;
		}	
	}
	
	if(num==100)
	{
		
		with(obj.style)
		{
			var TheTDLeft = trobj.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.offsetLeft;	
	                var TheTDTop = trobj.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.offsetTop;
			pixelLeft = topobj.offsetLeft + TheTDLeftSelf + TheTDLeft + ML + 290-oxwidth;
			pixelTop  = topobj.clientTop  + MT +210;	
		}
	}
	
	obj.style.visibility  = "visible";
	if(obj.alphaing)
	{
		clearInterval(obj.alphaing);
	}
	
	obj.alphaing = setInterval("menu_alpha_up("+obj.id+","+alphaStep+")",menuSpeed);	
}
function HideMenu(num)
{
	var thenowMenu = "";
	var obj = null;
	if(num==1)
	{
		thenowMenu = NowSubMenu
	}
	
	for(i=SubMenuList.length-1;i>=0;i--)
	{
		if(SubMenuList[i]&&SubMenuList[i]!=thenowMenu)
		{
			obj = eval(SubMenuList[i]);
			if(obj.alphaing)
			{
				clearInterval(obj.alphaing);
			}	
      obj.alphaing = setInterval("menu_alpha_down("+obj.id+","+alphaStep+")",menuSpeed);
			obj.style.visibility = "hidden";		//-----如果想缓慢隐藏，请去掉这项---------------//------------//
			eval("tr"+SubMenuList[i]).className = "DropdownMenuNavigationShow_menutroutimg";
			SubMenuList[i] = null;
		}
		else
		{
			if(SubMenuList[i]==thenowMenu)
			{
				return;
			}
		}
	}
	
	NowSubMenu = "";
}

//-----------MenuPosition return(obj)--------------//

function MPreturn(obj)
{
	var topobj = eval(obj.substring(0,obj.length-2));
  var trobj  = eval("tr"+obj);
  var x = topobj.style.pixelLeft + topobj.offsetWidth;
	var y = topobj.style.pixelTop  + trobj.offsetTop;
	obj = eval(obj);
	var judgerY =  obj.offsetHeight + y;
	var judgerX =  obj.offsetWidth  + x;
	var py = 0;
	var px = 0;
	if(judgerY>=document.body.clientHeight)
	{
		py = 1;
	}
	
	if(judgerX>= document.body.clientWidth)
	{
		px = 2;
	} 
			
	return (px+py);
}

//-----------mouseWave()-------------//

function mouseWave()
{
	if(mouseCanSound)
	{
		theBS.src= "sound/sound.wav";
	}	
}

//----------- menu_alpha_down -------//

function menu_alpha_down(obj,num)
{
		var obj = eval(obj);
		if(obj.filters.Alpha.Opacity > 0 )
		{
			obj.filters.Alpha.Opacity += -num;
		}	
		else
		{	
			clearInterval(obj.alphaing);
			obj.filters.Alpha.Opacity = 0;
			obj.alphaing = false;			
			obj.style.visibility = "hidden";
		}	
}


//------------ menu_alpha_up --------//

function menu_alpha_up(obj,num)
{
		var obj = eval(obj);
		if(obj.filters.Alpha.Opacity<80)
			obj.filters.Alpha.Opacity += num;
		else
		{	
			clearInterval(obj.alphaing);
			obj.filters.Alpha.Opacity = 80;
			obj.alphaing = false;
		}
}

//---------- IE mouseup --------//

function document.onmouseup()
{
	HideMenu();
}