$(function(){
	
	//以下代码为简易图片轮播

	/*=== start ===*/
	
	//获取大图轮播容器
	var bigImgBox = $(".tuanjian-dep .imgList .bigImg ul");
	
	//获取小图轮播容器
	var smallImgBox = $(".tuanjian-dep .imgList .smallImg ul");
	
	//获取轮播个数
	var imgNum = bigImgBox.children("li").length;
	
	//设置自动滚动时间
	var autoScrollTime = 4000;
	
	//大图容器 664   小图容器167
	
	//设置大图容器宽度
	bigImgBox.width(imgNum*664);
	
	//设置小图容器宽度
	smallImgBox.width(imgNum*167);
	
	var imgIndex = 0;
	var bigImgleft;
	var smallImgleft;
	
	function imgChange(){
		//获取大图偏移量
		bigImgleft = -imgIndex*664;
		
		//获取小图偏移量
		if( imgIndex < 4 ){
			smallImgleft = 0;
		}else{
			smallImgleft = -( imgIndex - 3 )*167;
		}
		
		//设置大图偏移
		bigImgBox.animate({"left":bigImgleft});
		
		//设置小图偏移
		
		smallImgBox.animate({"left":smallImgleft});
		
		smallImgBox.children("li").eq(imgIndex).addClass("cur").siblings("li").removeClass("cur");
		
	}
	
	imgChange();
	
	function imgRight(){
		if( !bigImgBox.is(":animated") || !smallImgBox.is(":animated") ){
			if( imgIndex < imgNum - 1 ){
				imgIndex++;
			}else{
				imgIndex = 0;
			}
			imgChange();
		}else{
			
			return false;
		}
	}
	
	function imgLeft(){
		 if( !bigImgBox.is(":animated") || !smallImgBox.is(":animated") ){
			if( imgIndex > 0 ){
				imgIndex--;
			}else{
				imgIndex = imgNum - 1;
			}
			imgChange();
		}else{
			return false;
		}
	}
	
	$(".tuanjian-dep .imgList .prev").click(function(){
	   imgLeft();
	});
	
	$(".tuanjian-dep .imgList .next").click(function(){
		imgRight();
	});
	
	
	
	smallImgBox.children("li").click(function(){
		imgIndex = $(this).index();
		imgChange();
	});
	
	var dingshiqi = setInterval(imgRight,autoScrollTime);
	
	$(".tuanjian-dep .imgList").hover(
		function(){
			clearInterval(dingshiqi);
		},
		function(){
			dingshiqi = setInterval(imgRight,autoScrollTime);
		}
	);
	
	/*=== end ===*/
	
});
