﻿



//==================图片详细页函数=====================
//鼠标经过预览图片函数
function preview(img){
	$("#preview .jqzoom img").attr("src",$(img).attr("mimg"));
	$("#preview .jqzoom img").attr("jqimg",$(img).attr("bimg"));
	$(img).parent('li').addClass('active').siblings().removeClass('active');
}

//图片放大镜效果
$(function(){
	$(".jqzoom").jqueryzoom({xzoom:380,yzoom:410});
});


//图片预览小图移动效果,页面加载时触发
$(function(){
	var tempLength; //临时变量,当前移动的长度
	var viewNum; //设置每次显示图片的个数量

	var moveNum; //每次移动的数量
	var moveTime; //移动速度,毫秒
	var scrollDiv;  //进行移动动画的容器
	var scrollItems;  //移动容器里的集合
	var moveLength; //计算每次移动的长度
	var countLength;
	function init(){
		if($(window).width()<=432){
			tempLength = 0; //临时变量,当前移动的长度
			viewNum = 3; //设置每次显示图片的个数量

			moveNum = 1; //每次移动的数量
			moveTime = 300; //移动速度,毫秒
			scrollDiv = $(".spec-scroll .items ul"); //进行移动动画的容器
			scrollItems = $(".spec-scroll .items ul li"); //移动容器里的集合
			moveLength = scrollItems.eq(0).width() * moveNum; //计算每次移动的长度
			countLength = (scrollItems.length - viewNum) * scrollItems.eq(0).width();
		}else{
			tempLength = 0; //临时变量,当前移动的长度
			viewNum = 4; //设置每次显示图片的个数量

			moveNum = 1; //每次移动的数量
			moveTime = 300; //移动速度,毫秒
			scrollDiv = $(".spec-scroll .items ul"); //进行移动动画的容器
			scrollItems = $(".spec-scroll .items ul li"); //移动容器里的集合
			moveLength = scrollItems.eq(0).width() * moveNum; //计算每次移动的长度
			countLength = (scrollItems.length - viewNum) * scrollItems.eq(0).width();
		}
	}
	init();
	
	 //计算总长度,总个数*单个长度
	$(window).resize(function(){
		init();
	})

	//下一张
	$(".spec-scroll .next").bind("click",function(){
		if(tempLength < countLength){
			if((countLength - tempLength) > moveLength){
				scrollDiv.animate({left:"-=" + moveLength + "px"}, moveTime);
				tempLength += moveLength;
			}else{
				scrollDiv.animate({left:"-=" + (countLength - tempLength) + "px"}, moveTime);
				tempLength += (countLength - tempLength);
			}
		}
	});
	//上一张
	$(".spec-scroll .prev").bind("click",function(){
		if(tempLength > 0){
			if(tempLength > moveLength){
				scrollDiv.animate({left: "+=" + moveLength + "px"}, moveTime);
				tempLength -= moveLength;
			}else{
				scrollDiv.animate({left: "+=" + tempLength + "px"}, moveTime);
				tempLength = 0;
			}
		}
	});
});
//==================图片详细页函数=====================