﻿$(document).ready(function(){
	seachsub();//搜索跳转
	headmenu();//头部导航链接样式
	sideNav();//侧栏菜单显示
	Tab();//中栏滑动面显示
	FocusIMG();//焦点图轮番
	BuyTime();//限时购时间
	note();//公告
});


//限时购时间
function BuyTime(){
	//定义公函数
	var timeFns = function(_OBJ){
		var NowTime = new Date();
		var timedate = new Date(_OBJ.replace(/\-/g,"/"));
		var nMS = timedate.getTime() - NowTime.getTime();
		var nD = Math.floor(nMS/(1000 * 60 * 60 * 24));
		var nH = Math.floor(nMS/(1000*60*60)) % 24;
		var nM = Math.floor(nMS/(1000*60)) % 60;
		var nS = Math.floor(nMS/1000) % 60;
		if(nMS>0){ //对比现在时间和结束时间差		    
		   return "剩余<span>"+ (nH+nD*24) +"</span>时<span>"+ nM +"</span>分<span>"+ nS +"</span>秒";
		}else{		   		    		    
		   return "已结束";
		};
	};
	for(i=0; i<6; i++ ){
		var str = $("#timebuy").find(".time:eq("+i+")").text();				
		$("#timebuy").find(".iBuytime:eq("+i+")").html(timeFns(str));//循环输出显示每个产品的购买剩余时间		
	};
	setTimeout("BuyTime()", 1000);
}

//搜索跳转
function seachsub(){
	$("#seachval").keydown(function(){
			if(event.keyCode==13){$("#seachpost").focus();}
	});
	//点击搜索按钮
	$("#seachpost").click(function(){
		if($("#seachval").val().length==0)
		{
			alert("请输入搜索关键字!");
			return;
		}else{
			//_url是搜索页的路径,例http://www.itgonow.com/search.aspx?id=,这为完整路径;
			var _url = "/Research.asp?searchkey=" 
			location.href= _url + escape($.trim($("#seachval").val()));
		}
	});
}

//头部导航链接样式
function headmenu(){
	//导航栏目
	$(".nav>ul>li:not(#n0)").hover(function(){
		//鼠标移动该栏目
		$(".nav>ul>li:not(#n0)").removeClass("on");					
		$(this).addClass("on");	
		$(this).find("ul").show();
	},function(){
		//鼠标离开该栏目
		$(this).removeClass("on");
		$(this).find("ul").hide();
	});
	
	//购物车
	$("#mycart").hover(function(){				
		//鼠标移动
		$(".cars").slideDown(200);
	},function(){
		//鼠标离开
		$(".cars").fadeOut(200);
	});
	$(".cars>ul>li").hover(function(){				
		//鼠标移动
		$(".cars>ul>li").removeClass("index");
		$(this).addClass("index");
	},function(){
		//鼠标离开
		$(this).removeClass("index");
	});
	//顶部菜单
	$(".menu>li:first").hover(function(){
		//鼠标移动
		$(this).addClass("index");						   
		$(".droplist").slideDown(250);
	},function(){
		//鼠标离开
		$(this).removeClass("index");
		$(".droplist").fadeOut(250);
	});	
	
	//顶部菜单弹出后,鼠标移动样式替换
	$(".droplist>li").hover(function(){
		//鼠标移动							 
		$(this).addClass("hover");						   
	},function(){
		//鼠标离开
		$(this).removeClass();
	});	
}

//侧栏菜单显示
function sideNav(){
	$(".pMod>ul>li").hover(function(){
		//鼠标移动
		$(this).find("i").addClass("index");
		$(this).find(".plist").show();
	},function(){
		//鼠标离开
		$(this).find("i").removeClass();
		$(this).find(".plist").hide();
	});
	//弹出分类鼠标移动样式替换
	$(".plist>dl>dd").hover(function(){
		//鼠标移动							 
		$(this).addClass("index");
	},function(){
		//鼠标离开
		$(this).removeClass();
	});
}

//中栏滑动面显示
function Tab(){
	var _OBJ = $("#buyact").find(".tab0>li");
	var _OBJ2 = $("#buyact").find(".tbody");
	//点击
	$(_OBJ).click(function(){
		var _ID = $(_OBJ).index(this);
		$(_OBJ).removeClass();				   
		$(this).addClass("index");
		$("#buyact").find(".tbody>div").removeClass().addClass("none");
		$("#buyact").find(".tbody>div:eq("+ _ID +")").removeClass().addClass("block");
	});
}


//焦点图轮番
function FocusIMG(){
	//定义函数组
	var fns={
		//向左
		_left : function(){
				  $("#finfo>div>ul>li:last").clone().show().prependTo($("#finfo>div>ul"));
		          $("#finfo>div>ul").css("marginLeft","-101px");
				  $("#finfo>div>ul").stop().animate({marginLeft:0},500,'', function(){
						$("#finfo>div>ul>li:last").remove();
						fns._img("#finfo>div>ul>li:eq(0)");
						$("#finfo>div>ul>li").removeClass();
						$("#finfo>div>ul>li:eq(0)").addClass("index");
			     });
			
		},
		//向右
		_right : function(){
				 $("#finfo div ul").stop().animate({marginLeft:"-101px"},500,'', function(){
				        $("#finfo div ul li:lt(1)").appendTo($("#finfo div ul"));
				        $("#finfo div ul").css("marginLeft",0);
						var _ID = $("#finfo div ul li:eq(0)").find("img").attr("rel");
						fns._img(_ID);
						$("#finfo div ul li").removeClass();
						$("#finfo div ul li:eq(0)").addClass("index");
			     });
				 
		},
		//鼠标移动替换样式
		_hover : function(_OBJ){
			$(_OBJ).hover(function(){
				$("#finfo div ul li").removeClass();	
				$(this).addClass("index");
				var _ID = $(this).find("img").attr("rel");
				fns._img(_ID);
			},function(){
				//
			});						 
		},
		//小图替换大图片
		_img : function(_OBJ){
			$("#fImg>a").hide();
			$(".loading").show();
			setTimeout(function(){				
				$(".loading").hide();
				$("#fImg>a:eq("+ _OBJ +")").show();
			},100);
		}
	};
	    fns._hover("#finfo>div>ul>li");
		var _L,_R;
		$("#fleft").hover(function(){
			_L = setInterval(function(){fns._left()},2500);// 1500是鼠标移动向左滑动时间,单位毫秒
		},function(){
			clearInterval(_L);
			_L = null;
		});
	    $("#fright").hover(function(){
			_R = setInterval(function(){fns._right()},2500);// 1500是鼠标移动向右滑动时间,单位毫秒
		},function(){
			clearInterval(_R);
			_R = null;
		});
		var _autoR = null;
		$("#fmenu").mouseover(function(){
			autoStop();
		});
		$("#fmenu").mouseout(function(){
			_autoR = setInterval(function(){fns._right();},4000);//鼠标离开后再重新恢复自动播放时间,单位毫秒
		});	
		var autoPlay = function(){_autoR = setInterval(function(){fns._right()},4000);};//自动播放时间,单位毫秒
		var autoStop = function(){clearInterval(_autoR);_autoR = null;};	
		//自动播放
		autoPlay();
		$("#fImg").append("<div class=\"loading\"></div>");
}

//公告
function note(){
	//定义函数组
	var fns={
		//向上
		_up : function(){
				 $(".note>div>ul").stop().animate({marginTop:"-30px"},500,'', function(){
				        $(".note>div>ul>li:lt(1)").appendTo($(".note>div>ul"));
				        $(".note>div>ul").css("marginTop",0);
			     });
			
		}
	};
		var _autoUp = null;
		$(".note").mouseover(function(){
			autoStop2();
		});
		$(".note").mouseout(function(){
			_autoUp = setInterval(function(){fns._up();},2500);//鼠标离开后再重新恢复自动播放时间,单位毫秒
		});	
		var autoPlay2 = function(){_autoUp = setInterval(function(){fns._up()},2500);};//自动播放时间,单位毫秒
		var autoStop2 = function(){clearInterval(_autoUp);_autoUp = null;};	
		//自动播放
		autoPlay2();
}

