//--------版权所有：飞速电子商务--------
//-------------www.zowee.cn-------------
var pos_x=new Array(9);//弹出菜单距网页左边的距离
pos_x[0]=0;
pos_x[1]=0;
pos_x[2]=0;
pos_x[3]=0;
pos_x[4]=0;
pos_x[5]=0;

//=========================================================
var windowWidth;			        //窗口宽度(自动计算)
//var tableWidth = 1002;				// 要弹出菜单的表格宽度(一般取网页宽度)
var tableWidth=document.body.clientWidth; //可用区宽度
//if(tableWidth<1000)tableWidth=1002;
//var offsetWidth = 0;				// 第一个弹出菜单和表格左边距离的修正值
var offsetWidth=(document.body.clientWidth - 950)/2 //修正值
var layoutSize = 950;				// 网页宽度

// Is this Netscape version 4 or earlier?
var v4 =(parseInt(navigator.appVersion) < 5) ? 1 : 0;
var ns =(navigator.appName.match(/Netscape/) && v4) ? 1 : 0;
// Is this Netscape 6+ or Mozilla?
var ns6 = (navigator.appName.match(/Netscape/) && !v4) ? 1 : 0;
// Is this Opera?
var opera = (navigator.userAgent.indexOf("Opera") != -1 ? 1 : 0);
// Is this Mozilla only?
var mozilla = (navigator.userAgent.indexOf("Gecko") != -1 && navigator.userAgent.indexOf("Netscape") == -1? 1 : 0);
// Is this IE 4? - Not used
var ie = (navigator.appName.match(/Microsoft Internet Explorer/) && v4) ? 1 : 0;
function updateLayers()
{
	// Check if browser is wider than the menu table (760 width)
	windowWidth = (ns || opera || ns6 ? window.innerWidth : document.body.clientWidth);
	//alert (tableWidth);	
	// This prevents the layers from redrawing incorrectly if the window size is less than the layout size
	if (windowWidth < layoutSize+16) {
		if (ns) windowWidth = layoutSize + 16;
		else windowWidth = layoutSize;
	}else{
		if (ns6) windowWidth -= 16;
	}
	// 更新所有层的位置
	for (var i=0; i<pos_x.length; i++){
		var layerObj = MM_findObj("menu_" + (i+1));
	//alert (layerObj.style.left);
	if(layerObj!=null){
		if (ns) layerObj.left = pos_x[i] + (windowWidth/2) - (tableWidth/2) + offsetWidth;
		else layerObj.style.left = pos_x[i] + (windowWidth/2) - (tableWidth/2) + offsetWidth;
		//alert (layerObj.style.left);
	}
	}
	
	if (opera) resizeHandler();
}
function resizeHandler() {
	var winWidth = window.innerWidth;
	if (winWidth < layoutSize+16) winWidth = layoutSize;
	for (var i=0; i<pos_x.length; i++){
		var layerObj = MM_findObj("menu_" + (i+1));
		layerObj.style.left = pos_x[i] + (winWidth/2) - ((tableWidth-offsetWidth)/2);
	}

	setTimeout("resizeHandler()",500);	// Check if change in window size every 1/2 of second
}
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
//=========================================================

function menuControl(numID,show)
{
	if(show==1)
	{
		//alert(show);
		eval("showMenu("+"menu_"+numID+")");
	}
	else
	{
		eval("hideMenu("+"menu_"+numID+")");
	}
}

var nbottom=0,speed=6;

function displayMenu(obj)
{
	obj.style.clip="rect(0 100% "+nbottom+"% 0)";
	nbottom+=speed;
	if(nbottom<=100) 
	{
		timerID=setTimeout("displayMenu("+obj.id+"),70");
	}
	else
	{
		clearTimeout(timerID);
	}
}
function showMenu(obj)
{
	//obj.style.left=0;
	obj.style.display="block";
	obj.style.clip="rect(0 0 0 0)";
	nbottom=9;
	displayMenu(obj);
}
function hideMenu(obj)
{
	nbottom=0;
	obj.style.display="none";
}
function keepMenu(obj)
{
	obj.style.display="block";
}
window.resize=updateLayers();
