//首页左侧分类菜单
$("#category ul").find("li").each(
	function() {
		$(this).mouseover(
			function() {
				menu = $("#" + this.id + "_menu");
				menu_height = menu.height();
				if (menu_height < 40) menu.height(60);
				menu.show();
				$(this).addClass("a");
			}
		);
		$(this).mouseout(
			function() {
				$(this).removeClass("a");
				$("#" + this.id + "_menu").hide();
			}
		);
	}
);
showAllCategory = false;
$("#more_cat").click(function() {
	showAllCategory = !showAllCategory;
	cat_count = 0;
	if (showAllCategory) {
		$(this).addClass("close");
		$("#category ul").find("li").each(function() {
			cat_count ++;
			cat_count > 8 ? $(this).show("slow") : "";
		});
	} else {
		$(this).removeClass("close");
		$("#category ul").find("li").each(function() {
			cat_count ++;
			cat_count > 8 ? $(this).hide("slow") : "";
		});
	}
});


//幻灯片广告控制	
	$(function(){
		$("#KinSlideshow").KinSlideshow({
			moveStyle:"left",
			titleBar:{titleBar_height:30,titleBar_bgColor:"#FFF",titleBar_alpha:0.5},
			titleFont:{TitleFont_size:12,TitleFont_color:"#FFFFFF",TitleFont_weight:"normal"},
			btn:{btn_bgColor:"#FFFFFF",btn_bgHoverColor:"#1072aa",btn_fontColor:"#000000",btn_fontHoverColor:"#FFFFFF",btn_borderColor:"#cccccc",btn_borderHoverColor:"#1188c0",btn_borderWidth:1}
		});
	})

//精选推荐左右按钮控制显示
	$(function(){
         
	     var $obj = $('#slideshow ul');
		 var len  = $obj.length;
		 var i = 0;
		 $("#next").click(function(){
		      i++;
			  if(i==len){
			    i = 0;
			  }
			  $obj.stop(true,true).hide().eq(i).fadeIn(2000);
			  return false;
		 });	
		 $("#previous").click(function(){
		      i--;
			  if(i==-1){
			    i = len-1;
			  }
             $obj.stop(true,true).hide().eq(i).fadeIn(2000);
			  return false;
		 });
         
		 //滑入div 停止动画，滑出开始动画.
         $('#slideshow').hover(function(){
		      if(MyTime){
			     clearInterval(MyTime);
			  }
		 },function(){
              MyTime = setInterval(function(){
				 $("#next").trigger("click");
			  } , 5000);
		 })

		 //每2秒，自动切换。触发".next"的click事件.
		 var MyTime = setInterval(function(){
		    $("#next").trigger("click");
		 } , 5000);
	})


//品牌区域鼠标触及更替li样式
	$(document).ready(function(){
		$('.brands').children('li').bind('mouseenter',function(){
			$('.brands').children('li').attr('class','c1');
			$(this).attr('class','c2');
		});
		$('.brands').children('li').bind('mouseleave',function(){
			$('.brands').children('li').attr('class','c1');
		});
})

//首页优惠券琴键式隐藏显示
$.fn.extend({     
   AdAdvance:function(){
	var listobj=this;
        var objs =$('dt',this);
	var view =objs.length-1;//parseInt( Math.random()*objs.length);
	objs.each(function(i){
	$(this).mouseover(function(){ $('dd',listobj).hide();$('.coupons-list-hover',listobj).attr("class",""); $(this).attr("class","coupons-list-hover");$(this).next().show()})
	if(i!=view)
	{
		$(this).next().hide();
	}
	else
	{
		$(this).next().show();
		$(this).attr("class","coupons-list-hover");
	}
	});
    }
}); 

//品牌区域鼠标触及更替li样式
	$(document).ready(function(){
		$('.showcase').children('ul').children('li').bind('mouseenter',function(){
			$('.showcase').children('ul').children('li').attr('class','c1');
			$(this).attr('class','c2');
		});
		$('.showcase').children('ul').children('li').bind('mouseleave',function(){
			$('.showcase').children('ul').children('li').attr('class','c1');
		});
})

//品牌区域鼠标触及更替li样式
	$(document).ready(function(){
		$('.category-side').children('dl').bind('mouseenter',function(){
			$('.category-side').children('dl').attr('class','c1');
			$(this).attr('class','c2');
		});
		$('.category-side').children('dl').bind('mouseleave',function(){
			$('.category-side').children('dl').attr('class','c1');
		});
})


//每日精选可控制轮换展示

$(document).ready(function() {
	$(".pagenext").show();
	$(".pagenext a:first").addClass("active");
	var imageWidth = $(".all-choice").width();
	var imageSum = $(".show-choice li").size();
	var imageReelWidth = imageWidth * imageSum;
	$(".showimagelist").css({'width' : imageReelWidth});
	rotate = function(){	
		var triggerID = $active.attr("rel")-1; 
		var showimagelistPosition = triggerID * imageWidth;
		$(".pagenext a").removeClass('active');
		$active.addClass('active'); 
		$(".show-choice").animate({ 
			left: -showimagelistPosition
		}, 00);
	}; 
	rotateSwitch = function(){		
		play = setInterval(function(){ 
			$active = $('.pagenext a.active').next();
			if ( $active.length === 0) { 
				$active = $('.pagenext a:first'); 
			}
			rotate(); 
		}, 4000); 
	};
	rotateSwitch(); 
	$(".show-choice img").hover(function() {
		clearInterval(play); 
	}, function() {
		rotateSwitch(); 
	});	
	$(".pagenext a").click(function() {	
		$active = $(this); 
		clearInterval(play); 
		rotate(); 
		rotateSwitch(); 
		return false; 
	});	
	$(".cprev").click(function() {	
	$active = $('.pagenext a.active');
	if($active.attr("rel")==1){
		$active = $('.pagenext a:last');
		}else{
		$active = $('.pagenext a.active').prev();	
		}
		clearInterval(play); 
		rotate(); 
		rotateSwitch(); 
		return false; 
	});	
	$(".cnext").click(function() {	
	$active = $('.pagenext a.active');
	if($active.attr("rel")==$('.show-choice li').size()){
		$active = $('.pagenext a:first');
		}else{
		$active = $('.pagenext a.active').next();	
		}
		clearInterval(play); 
		rotate(); 
		rotateSwitch(); 
		return false; 
	});	
});

	// 页面返回顶部控制
		$(function() {
	    var $backToTopTxt = "返回顶部", $backToTopEle = $('<div class="backToTop"></div>').appendTo($("body"))
	        .text($backToTopTxt).attr("title", $backToTopTxt).click(function() {
	            $("html, body").animate({ scrollTop: 0 }, 120);
	    }), $backToTopFun = function() {
	        var st = $(document).scrollTop(), winh = $(window).height();
	        (st > 0)? $backToTopEle.show(): $backToTopEle.hide();
	        //IE6下的定位
	        if (!window.XMLHttpRequest) {
	            $backToTopEle.css("top", st + winh - 166);
	        }
	    };
	    $(window).bind("scroll", $backToTopFun);
	    $(function() { $backToTopFun(); });
		});




		$(function(){
		var i = 0;
		$('#navbar').children('ul').children('li').mouseover(function(){
			if($(this).children('a')[0].className == 'link'){
				i = 1;
			}
			$(this).children('a').removeClass();
			$(this).children('a').addClass('link');
		}).mouseout(function(){
			if(i != 1){
				$(this).children('a').removeClass();
				$(this).children('a').addClass('hover');
			}
			i = 0;
		});
		//search
		$("#details").children('ul').children('li').click(function(){
			$(this).parent().children('li').removeClass("current");
			$(this).addClass("current");
			$('#search_act').attr("value",$(this).attr("act"));
		});
		var search_act = $("#details").find("li[class='current']").attr("act");
		$('#search_act').attr("value",search_act);
		$("#keyword").blur();
	});
	//EASY TABS 1.2 - MENU SETTINGS
	//Set the id names of your tablinks (without a number at the end)
	var tablink_idname = new Array("tabLinkOne","tabLinkTwo")
	//Set the id names of your tabcontentareas (without a number at the end)
	var tabcontent_idname = new Array("tabContentOne","tabContentTwo") 
	//Set the number of your tabs in each menu
	var tabcount = new Array("4","4")
	//Set the Tabs wich should load at start (In this Example:Menu 1 -> Tab 2 visible on load, Menu 2 -> Tab 5 visible on load , Menu 3 -> Tab 1 visible on load)
	var loadtabs = new Array("1","1")  
	//Set the Number of the Menu which should autochange (if you dont't want to have a change menu set it to 0)
	var autochangemenu = 0;
	//the speed in seconds when the tabs should change
	var changespeed = 2;
	//should the autochange stop if the user hover over a tab from the autochangemenu? 0=no 1=yes
	var stoponhover = 1;
	//END MENU SETTINGS

	/*Swich EasyTabs Functions - no need to edit something here*/
	function easytabs(menunr, active) {if (menunr == autochangemenu){currenttab=active;}if ((menunr == autochangemenu)&&(stoponhover==1)) {stop_autochange()} else if ((menunr == autochangemenu)&&(stoponhover==0))  {counter=0;} menunr = menunr-1;for (i=1; i <= tabcount[menunr]; i++){document.getElementById(tablink_idname[menunr]+i).className='tab'+i;document.getElementById(tabcontent_idname[menunr]+i).style.display = 'none';}document.getElementById(tablink_idname[menunr]+active).className='tab'+active+' tabactive';document.getElementById(tabcontent_idname[menunr]+active).style.display = 'block';}var timer; counter=0; var totaltabs=tabcount[autochangemenu-1];var currenttab=loadtabs[autochangemenu-1];function start_autochange(){counter=counter+1;timer=setTimeout("start_autochange()",1000);if (counter == changespeed+1) {currenttab++;if (currenttab>totaltabs) {currenttab=1}easytabs(autochangemenu,currenttab);restart_autochange();}}function restart_autochange(){clearTimeout(timer);counter=0;start_autochange();}function stop_autochange(){clearTimeout(timer);counter=0;}

	window.onload=function(){
	var menucount=loadtabs.length; var a = 0; var b = 1; do {easytabs(b, loadtabs[a]);  a++; b++;}while (b<=menucount);
	if (autochangemenu!=0){start_autochange();}
	}

// 首页图片延时加载
	$(function() {
		$(".showcase img").lazyload({
			placeholder : "./templates/default/images/loading.gif", 
			event : "sporty" 
		});
		$(".showcase img").lazyload({
			placeholder : "./templates/default/images/loading.gif",
			event : "scroll"
		});
	});
	$(window).bind("load", function() { 
		var timeout = setTimeout(function() {$("img").trigger("sporty")}, 5000);
	});



