$(document).ready(function() {
		infiniteCarousel();
		function infiniteCarousel(){
			var length = $('.shop_infinite ul li').length;
			var w = $('.shop_infinite').width();
			var num ;
			if(w>=1120){
				num = 10;
			}else if(w>=860){
				num = 7;
			}else if(w>=620){
				num = 6;   
			}else if(w>=380){
				num = 4;   
			}else{
				num = 3;  
			}
			// 包含padding,margin
			var visible = $('.shop_infinite').innerWidth(); 
			var eachWidth = w/num;
			$('.shop_infinite ul li').css({width: eachWidth+'px'});
			// 共有页数
			var pages = Math.ceil(length / num);
			// 当前页数 
			var currentPage = 1; 
			$('.shop_infinite').scrollLeft(0);
			$('.shop_back').click(function() {
				if(currentPage>1){
					currentPage = currentPage - 1;
					gotoPage(currentPage); 
				}else{
					currentPage = pages;
					gotoPage(currentPage);
				}
			});
			$('.shop_forward').click(function() {
				if(currentPage <= pages){ 
					currentPage+=currentPage;
					gotoPage(currentPage); 
				}else{ 
					currentPage = 1;
					gotoPage(currentPage);
				}							
			});
			function gotoPage(page){
				var left = page-1;
				console.log(left);
				if(page == 0){
					var n = pages-1; 
					$('.shop_infinite').scrollLeft(eachWidth * n * num);
					page = pages;
				} else if ( page > pages ){ 
					$('.shop_infinite').animate({scrollLeft : 0}, 500);
					// $('.shop_infinite').scrollLeft(0); 
					return currentPage = 1;
				}else { 
					$('.shop_infinite').animate({scrollLeft : w * left}, 500);  
				}
			} 
			/*$('.shop_infinite ul li').click(function(){
				$(this).siblings('li').find('a').removeClass('active')
				$(this).find('a').addClass('active');
			});*/
		}
		
		$('.product-image').mouseover(function(){
			$(this).find('img').addClass('shop_cate_scale'); 
		  });
		$('.product-image').mouseout(function(){
			$(this).find('img').removeClass('shop_cate_scale');
		});
  });
    
 