// JavaScript Document
	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;
	}

  $(function(){
	  var i = 3;  //已知显示的<a>元素的个数
	  var m = 3;  //用于计算的变量
	  var mumbs = 50*3+"px" ;//翻页个数
      var $content = $("#myImagesSlideBox .scrollableDiv");
	  var count = $content.find("a").length;//总共的<a>元素的个数
	  //下一张
	  $(".next").live("click",function(){
			var $scrollableDiv = $(this).siblings(".items").find(".scrollableDiv");
			if( !$scrollableDiv.is(":animated")){  //判断元素是否正处于动画，如果不处于动画状态，则追加动画。
				if(m<count){  //判断 i 是否小于总的个数
					m++;
					$scrollableDiv.animate({left: "-="+mumbs}, 600);
					$(this).parents(".myImagesSlideBox").find(".prev").css({'background-image':'url(images/go_down.jpg)'}) ;	
				}
				if(m>=count){
				    $(this).parents(".myImagesSlideBox").find(".next").css({'background-image':'url(images/go_up_grey.jpg)'}) ;	
			    }
			}
			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: "+="+mumbs}, 600);
					$(this).parents(".myImagesSlideBox").find(".next").css({'background-image':'url(images/go_up.jpg)'}) ;	
				}
				if(m<=i){
				   $(this).parents(".myImagesSlideBox").find(".prev").css({'background-image':'url(images/go_down_grey.jpg)'}) ;	
				}
			}
			return false;
	  });

	  $(".scrollableDiv a").live("click",function(){
			var src = $(this).find("img").attr("imgb");
			var bigimgSrc = $(this).find("img").attr("bigimg");
			$(this).parents(".myImagesSlideBox").find(".myImages").find("img").loadthumb({src:src}).attr("bigimg",bigimgSrc);
			$(this).addClass("active").siblings().removeClass("active");
			return false;
	  });
	  $(".scrollableDiv a:nth-child(1)").trigger("click");
		
	  $(".myTxts a").live("click",function(){
			var bigimgSrc =$(this).parents(".myImagesSlideBox").find(".myImages").find("img").attr("bigimg");
			popZoom( bigimgSrc , screen.width*0.5 , screen.height*0.5);
			return false;
	  });

		//以新窗口的方式打开图片
		var windowWidth  =$(window).width();
		var windowHeight  =$(window).height();
		function popZoom(pictURL, pWidth, pHeight) {
			var sWidth = windowWidth;
			var sHeight = windowHeight;
			var x1 = pWidth;
			var y1 = pHeight;
			var opts = "height=" + y1 + ",width=" + x1 + ",left=" + ((sWidth-x1)/2) +",top="+ ((sHeight-y1)/2)+",scrollbars=1,menubar=0";
			pZoom = window.open("","", opts);
			pZoom.document.open();
			pZoom.document.writeln("<html><body bgcolor=\"skyblue\"" +" onblur='self.close();' style='margin:0;padding:0;'>");
			pZoom.document.writeln("<img src=\"" + pictURL + "\">");
			pZoom.document.writeln("</body></html>");
			pZoom.document.close();
		} 
		
		/*关闭遮罩层*/
		$(".closeMyDiv a").live("click",function(){
			$("#MyDiv").empty().hide();
			$("#BigDiv").hide();
			return false;
		}).focus(function(){
			$(this).blur();
			return false;
		});

		/*使用遮罩层*/
		$("#myImagesSlideBox .myImages img").click(function(){
			/*遮罩层居中 和 宽度 高度设置 */
			$("#BigDiv").css({
						width:  $("body").width() , 
						height: (   $("body").height()  >  $("html").height() ) ? $("body").height() : $("html").height()  
					});
			$("#MyDiv").css({left: (($(window).width()-300)/2)  ,top: (($(window).height()-390)/2)  });

			var $myDiv = $("#MyDiv").html( $("#myImagesSlideBox").html() ).show();
			$('<div class="closeMyDiv"><a href="#">Close</a></div>').prependTo( $myDiv );
			$("#BigDiv").show();
			return false;
		});
  })
