// JavaScript Document

 

$(function(){
	
	jQuery.fn.loadthumb = function(options) {
		options = $.extend({
			 src : ""
		},options);
		var _self = this;
		_self.hide();
		var img = new Image();
		$(img).load(function(){
			_self.attr("src", options.src);
			_self.fadeIn("slow");
		}).attr("src", options.src);  //.atte("src",options.src)要放在load后面，
		return _self;
	}
	

	  var i = 4;  //已知显示的<a>元素的个数
	  var m = 4;  //用于计算的变量
      var $content = $("#scrollable .scrollableDiv");
	  var count = $content.find("a").length;//总共的<a>元素的个数
	  if(count<=4){
		 $(".prev").hide();
		 $(".next").hide();
		}
	  $(".scrollableDiv a").live("click",function(){
			var src = $(this).find("img").attr("imgb");
			var bigimgSrc = $(this).find("img").attr("bigimg");
			$(this).parents(".prodShow").find(".prodImgs").loadthumb({src:src});
			$(".zImges").find(".zimg").loadthumb({src:bigimgSrc});
			$(this).addClass("active").siblings().removeClass("active");
			return false;
	  });
	  $(".scrollableDiv a:nth-child(1)").trigger("click");
	  
	  //下一张
	  $(".next").live("click",function(){
			var $scrollableDiv = $(this).siblings(".items").find(".scrollableDiv");
			if( !$scrollableDiv.is(":animated")){  //判断元素是否正处于动画，如果不处于动画状态，则追加动画。
				if(m<count){  //判断 i 是否小于总的个数
					m++;
					$scrollableDiv.animate({left: "-=55px"}, 600);
				}
			}
			return false;
	  });
	   //上一张
	  $(".prev").live("click",function(){
			var $scrollableDiv = $(this).siblings(".items").find(".scrollableDiv");
			if( !$scrollableDiv.is(":animated")){
				if(m>i){ //判断 i 是否小于总的个数
					m--;
					$scrollableDiv.animate({left: "+=55px"}, 600);
				}
			}
			return false;
	  });
	  
	  //view big img
	  
	  $(".viewZimg").click(function(){
			$(".zImges").show();							
	  })
	  
	  $(".closeZ").click(function(){
			$(".zImges").hide();					  
		})
	  
	  //product information view
	  
	  $(".tabTitle li").click(function(){
			var num=$(this).attr("id");
			$(".tabTitle li").css("background","none");
			$(this).css({"background":"url(/img/catalog/tabs-bg.gif) repeat-x"});
			$(".tabInfo").hide();
			$("#infor"+num.substr(3)).show();
			
	  })
	  
	  //relate prod
	  
	  $(".relateProdImg").hover(
			function(){
				var thisdiv=$(this);
				$(this).next().fadeIn();
				 $(this).next().positionBy({
					target:thisdiv,
					targetPos: 3,
					elementPos:0
				}).show("fast");
				},
			function(){
				var thisdiv=$(this);
				$(this).next().hide("fast");
			}
	   )
	  
	  $("#popSearchAgain").positionBy({
			target:$("#popSearch"),
			targetPos: 3,
			elementPos:0
		}).show("fast");
	  
	  //sharePopUp show
	  $(".showSharePop").click(function(){
			$(".sharePopUp").fadeIn();							  
	  })
	  
	  
	   $(".shareClose").click(function(){
			$(".sharePopUp").hide();							  
	   })
  
})

