// JavaScript Document  UTF-8编码

//setTimeout延时+对象做参数
function SetTimeoutClass()
{
	this.timeOutId=null;
	
	this.call=function(func,speed)
	{
		this.timeOutId=window.setTimeout(function()
								   {
									   $.each(func,function(i,n)
										{
											var objStr=""
											$.each(n,function(j,m)
											{
												if(j==0)
												{objStr+="n["+j+"]";}
												else
												{objStr+=",n["+j+"]";}
											});
											eval(i+"("+objStr+");");
										});
								   },speed);
	};
	this.stopCall=function()
	{
		if(this.timeOutId!=null)
		{
			var timerId=this.timeOutId;
			window.clearTimeout(timerId);
		}
		this.setempty();
	};
	this.setempty=function()
	{
		this.timeOutId=null;
	};
}

//setInterval延时+对象做参数
function SetIntervalClass()
{
	this.timerId=null;
	
	this.call=function(func,speed)
	{
		this.timerId=window.setInterval(function()
								   {
									   $.each(func,function(i,n)
										{
											var objStr=""
											$.each(n,function(j,m)
											{
												if(j==0)
												{objStr+="n["+j+"]";}
												else
												{objStr+=",n["+j+"]";}
											});
											eval(i+"("+objStr+");");
										});
								   },speed);
	};
	this.stopCall=function()
	{
		if(this.timerId!=null)
		{
			var timeId=this.timerId;
			window.clearInterval(timeId);
		}
		this.setempty();
	};
	this.setempty=function()
	{
		this.timerId=null;
	};
}

//导航菜单显示判断
function testToShow(obj,showOrNot)
{
	$(".navBar h1[class!='noList']").children("a").removeClass("imgAll hover");
	$(".navBar div[class='smallList']").hide();
	if(showOrNot)
	{
		$(obj).next("div[class='posCon']").contents("div[class='smallList']").show();
		$(obj).children("a").addClass("imgAll hover");
	}
	else
	{
		$(obj).next("div[class='posCon']").contents("div[class='smallList']").hide();
		$(obj).children("a").removeClass("imgAll hover");
	}
}

//滚动广告
var rollAd={

rollAdNum:0,		//广告数量
imgHeight:258,		//图片高度
setIntervalSpeed:20,//图片滚动调用速度
imgRollSpeed:0,		//图片滚动速度
adRollSpeed:2000,	//广告滚动间隔
imgTop:0,			//当前图片位置
newTop:0,			//图片将要跳至的位置
hoverAction:null,	//图片调用请求
rollAdSetTimeOut:null,		//连续滚动时间对象
rollAdSetInterval:null,		//连续滚动调用对象
pauseSetInterval:null,		//暂停滚动对象

	//设置图片标签
setAdNum:function()	
{
	 this.rollAdNum=$(".ad_roll .roll_img li").length; 
	 var  rollNumHTML="<li class='imgAll hover' value='1'>1</li>";
	 for(var i=2;i<=this.rollAdNum;i++)
	 {
		 rollNumHTML=rollNumHTML+"<li class='imgAll' value='"+i+"'>"+i+"</li>";
	 }
	 $(".ad_roll .roll_num").html(rollNumHTML);
},
	//图片连续滚动
adRoll:function()
{
	  //初始化延时对象
	this.rollAdSetTimeOut=new SetTimeoutClass();
	this.rollAdSetInterval=new SetIntervalClass();
	this.rollAdSetInterval.call({"rollAd.adRoll_interval":[this.rollAdSetTimeOut]},this.setIntervalSpeed);
},
	//图片连续滚动核心代码
adRoll_interval:function(setTimeoutObj)
{
	if(this.hoverAction!=null)
	{
		setTimeoutObj.stopCall();
		this.newTop=this.imgHeight*(this.hoverAction-1);
		if(this.imgTop!=this.newTop)
		{
			this.hoverAction=null;
			this.adRoll_code(false,null);
		}
	}
	else
	{
		if(this.imgTop==this.newTop)
		{
			if(setTimeoutObj.timeOutId==null)
			{
				setTimeoutObj.call({"rollAd.adRoll_code":[true,setTimeoutObj]},this.adRollSpeed);
			}
		}
		else
		{
			this.adRoll_code(false,null);
		}
	}
},
adRoll_code:function(newOrNot,setTimeoutObj)
{
	if(newOrNot)
	{
		setTimeoutObj.setempty();
		if(this.newTop==this.imgHeight*(this.rollAdNum-1))
		{this.newTop=0;}
		else
		{this.newTop+=this.imgHeight;}
		$(".ad_roll .roll_num li").removeClass("hover");
		$(".ad_roll .roll_num li[value='"+(this.newTop/this.imgHeight+1)+"']").addClass("hover");
		
	}
	if(this.newTop>this.imgTop)
	{
		this.imgRollSpeed=Math.ceil((this.newTop-this.imgTop)/10);
		this.imgTop+=this.imgRollSpeed;	
	}
	if(this.newTop<this.imgTop)
	{
		this.imgRollSpeed=Math.ceil((this.imgTop-this.newTop)/10);
		this.imgTop-=this.imgRollSpeed;	
	}
	$(".ad_roll .roll_img").css({"top":"-"+this.imgTop+"px"});
},	

	//暂停滚动
stopRoll:function()
{
	if(this.pauseSetInterval==null)
	{
		this.pauseSetInterval=window.setInterval(function()
			{
				if(rollAd.imgTop==rollAd.newTop)
				{
					rollAd.rollAdSetInterval.stopCall(); 
					rollAd.rollAdSetTimeOut.stopCall();
					window.clearInterval(rollAd.pauseSetInterval);
					rollAd.pauseSetInterval=null;
				}
			},this.setIntervalSpeed);
	}
	
},

	//恢复滚动
continueRoll:function()
{
	if(this.pauseSetInterval!=null)
	{
		window.clearInterval(this.pauseSetInterval);
		this.pauseSetInterval=null;
	}
	if(this.rollAdSetInterval!=null && this.rollAdSetInterval.timerId==null)
	{
		this.rollAdSetInterval.call({"rollAd.adRoll_interval":[this.rollAdSetTimeOut]},this.setIntervalSpeed);
	}
},

	//标签覆盖时的延时操作
liHover:function(liObj)
{
	this.continueRoll();
	$(".ad_roll .roll_num li").removeClass("hover");
	$(liObj).addClass("hover");
	this.hoverAction=$(liObj).attr("value");
	this.stopRoll();
}

};


//Tab广告自动播放
var tabAuto = {

autoItems : ["hot_ad","crazy_ad","new_ad"],	//调用项目
autoOrder : 0,		//调用顺序
autoSpeed : 5000,	//调用速度
autoSetInterval  : null,		//自动播放调用对象
	
	//Tab广告mouseOver事件
tabMouseOver : function(obj,auto)
{
	$(".Tab_banner h1 a").removeClass("hover")
	$(obj).children("a").addClass("hover");
	$(".Tab_ad div").removeClass("now");
	$(".Tab_ad div."+$(obj).attr("class")).addClass("now");
	switch($(obj).attr("class"))
	{
		case "hot_ad":
			this.autoOrder=0;
			break;
		case "crazy_ad":
			this.autoOrder=1;
			break;
		case "new_ad":
			this.autoOrder=2;
			break;
	}
	if(!auto)
	{
		this.stopAuto();
	}
},

	//自动播放
tabAutoRoll : function()
{
	  //初始化延时对象
	this.autoSetInterval=new SetIntervalClass();
	this.autoSetInterval.call({"tabAuto.tab_code":[]},this.autoSpeed);
},

	//自动播放核心函数
tab_code : function()
{
	this.autoOrder=(this.autoOrder===2?0:this.autoOrder+1);
	this.tabMouseOver(jQuery(".Tab_banner h1."+this.autoItems[this.autoOrder])[0],true);
},

	//停止播放
stopAuto : function()
{
	if(this.autoSetInterval!==null)
	{
		this.autoSetInterval.stopCall();
	}	
},
	//恢复播放
continueAuto : function()
{
	if(this.autoSetInterval!==null && this.autoSetInterval.timerId===null)
	{
		this.autoSetInterval.call({"tabAuto.tab_code":[]},this.autoSpeed);
	}
}


};

//绑定事件
$(function()
  {
	  //商品列表动态菜单
	 $(".goodsList h2").hover(
		  function()
		  {
			  $(this).next("div[class='posCon']").contents("div[class='smallList']").show();
		  },
		  function()
		  {
			  $(this).next("div[class='posCon']").contents("div[class='smallList']").hide();
		  });
	  
	  $(".goodsList div[class='smallList']").hover(
		  function()
		  {
			  $(this).show();
			  $(this).parent("div[class='posCon']").prev("h2").children("a").addClass("hover");
		  },
		  function()
		  {
			  $(this).hide();
			  $(this).parent("div[class='posCon']").prev("h2").children("a").removeClass("hover");
	  
		  });
	  
	  //导航栏下拉菜单
	  	//初始化延时对象
	 var navSetTimeOut=new SetTimeoutClass();
	  	//设置延时及状态存储
	 $(".navBar h1[class!='noList']").mouseover(
		  function()
		  {
			  navSetTimeOut.stopCall();
			  navSetTimeOut.call({"testToShow":[this,true]},400);
		  });
	 $(".navBar h1[class!='noList']").mouseout(
		  function()
		  {
			  navSetTimeOut.stopCall();
			  navSetTimeOut.call({"testToShow":[this,false]},400);
		  });

	 	//菜单持续显示
	 $(".navBar div[class='smallList']").hover(
		  function()
		  {
			  navSetTimeOut.stopCall();
			  navSetTimeOut.call({"testToShow":[$(this).parent("div[class='posCon']").prev("h1")[0],true]},0);
		  },
		  function()
		  {
			  navSetTimeOut.stopCall();
			  navSetTimeOut.call({"testToShow":[$(this).parent("div[class='posCon']").prev("h1")[0],false]},400);
		  });
	 
	  //搜索栏默认值
	 $("#selectgoodsbyname_goodname").val($("#selectgoodsbyname_goodname").val()==""?$("#selectgoodsbyname_goodname").attr("alt"):$("#selectgoodsbyname_goodname").val());
	 $("#selectgoodsbyname_goodname").focus(
		  function()
		  {
			  if($(this).val()==$(this).attr("alt"))
			  {
				  $(this).val("");
			  }
		  });
	 $("#selectgoodsbyname_goodname").blur(
		  function()
		  {
			  if($(this).val()=="")
			  {
				  $(this).val($(this).attr("alt"));
			  }
		  });
	 
	  //Tab广告
	  	//初始化延时对象
	 var tabAdSetTimeOut=new SetTimeoutClass();
	 
	 tabAuto.tabAutoRoll();
	 $(".Tab_ad_ag .Tab_banner h1").hover(
		  function()
		  {
			  tabAdSetTimeOut.call({"tabAuto.tabMouseOver":[this,false]},300);
		  },
		  function()
		  {
			  tabAdSetTimeOut.stopCall();
			  tabAuto.continueAuto();
		  });
	 
		//鼠标覆盖停止播放
	 $(".Tab_ad_ag .Tab_ad").hover(
		  function()
		  {
			  tabAuto.stopAuto();
		  },
		  function()
		  {
			  tabAuto.continueAuto();
		  });
	  
	  //滚动广告
	  	//初始化延时对象
	 var rollAdTabSetTimeOut=new SetTimeoutClass();
	 
	 rollAd.setAdNum();
	 rollAd.adRoll();
	 $(".ad_roll .roll_num li").hover(
		  function()
		  {
			  rollAdTabSetTimeOut.call({"rollAd.liHover":[this]},300);
		  },
		  function()
		  {
			  rollAdTabSetTimeOut.stopCall();
		  });
	 	
		//鼠标覆盖停止动画
	 $(".ad_roll .roll_img li").hover(
		  function()
		  {
			  rollAd.stopRoll();
		  },
		  function()
		  {
			  rollAd.continueRoll();
		  });
	  
	  
	  
	  
	  
	  
	  
  });










