//*********版权所有：飞速电子商务 陈伟峰********//
//*********任意弹出菜单代码*******//
//=========================================================
function killErrors()
{
	return true;
}
window.onerror = killErrors;
var pos_x=new Array(5);//弹出菜单距所在表格左边的距离
pos_x[0]=460;
pos_x[1]=548;
pos_x[2]=638;
pos_x[3]=723;
pos_x[4]=807;

var windowWidth;			        // 窗口可见宽度
var tableWidth = 1000;				// 要弹出菜单的表格宽度，改变这里控制位置
var offsetWidth = 0;				// 表格到第一个弹出菜单的距离(不清楚)
var layoutSize = 200;				// 网站宽度，如果窗口宽度小于该值，取该值

// 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 (windowWidth);	
	// 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 (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;
}
//=========================================================
var menu_width=150;//菜单宽度
var nbottom=0,speed=15;//底部高度，展开速度
var x=0,y=0;//菜单弹出位置
var mode=1;//显示方式：
rnd.today=new Date(); 
rnd.seed=rnd.today.getTime(); 
function rnd()
{ 
	rnd.seed = (rnd.seed*9301+49297) % 233280; 
	return rnd.seed/(233280.0); 
}
function rand(number)
{ 
	return Math.ceil(rnd()*number); 
}
function hideAllMenu()
{
	for (var i=0; i<pos_x.length; i++)
	{
		var layerObj = MM_findObj("menu_" + (i+1));
		layerObj.style.display="none";
	}
}
function menuControl(show)
{
	//window.event.cancelBubble=true;
	var objID=event.srcElement.id;
	var numID=objID.substring(objID.length-1,objID.length);
	var menu=eval("menu_"+numID);
	if(x==0)
	{
		x=event.clientX-menu_width/3;
		//y=event.y;
		y=32;
	}
	//menu.style.left=pos_x[numID];
	//menu.style.top=pos_y[numID];
	//menu.style.left=x;
	//menu.style.top=y;
	if(show==1)
	{
		eval("showMenu("+"menu_"+numID+")");
	}
	else
	{
		eval("hideMenu("+"menu_"+numID+")");
	}
}

function displayMenu(obj)
{
	//clip=rect(top,right,bottom,left)
	//---------显示效果-----------
	switch(mode)
	{
		case 1:
			obj.style.clip="rect(0 100% "+ nbottom + "% 0)";  //1、从上到下显示
			break;
		case 2:
	    	obj.style.clip="rect(0 " + nbottom + "% 100% 0)";//2、从左到右显示
			break;
		case 3:
			obj.style.clip="rect(" + (100-nbottom) + "% 100% " + nbottom+"% 0)";  //3、从中间往上下显示
			break;
		case 4:
	    	obj.style.clip="rect(0 " + nbottom + "% " + nbottom+"% 0)";//4、从左上到右下显示
			break;
		case 5:
	    	obj.style.clip="rect(" + (100-nbottom) + "% " + nbottom + "% " + nbottom+"% 0)";//5、从左边一点往上、下、右喷射显示
			break;
		case 6:
	    	obj.style.clip="rect(" + (100-nbottom) + "% " + nbottom + "% " + nbottom+"% " + (100-nbottom) + "%)";//6、从正中间一点往四方喷射显示
			break;
	}
	nbottom+=speed;
	if(nbottom<=100) 
	{
		timerID=setTimeout("displayMenu("+obj.id+"),70");
	}
	else
	{
		clearTimeout(timerID);
	}
}
function showMenu(obj)//效果显示
{
	hideAllMenu();
	obj.style.display="block";
	//obj.style.clip="rect(0 0 0 0)";
	//nbottom=9;//底部的高度
	//mode=rand(6);//显示效果随机
	//displayMenu(obj);
}
function hideMenu(obj)//隐藏
{
	x=0;
	y=0;
	nbottom=0;
	obj.style.display="none";
}
function keepMenu(obj)//显示
{
	obj.style.display="block";
}
window.onload=updateLayers
//window.onresize=updateLayers
