﻿var imgList;
var index=0;
var indexSet;
var isFirst=true;
$(function(){
	var locking=true;
	var loading=$("#loading");
	var bigImg=$("#bgImg");
	imgList=$("#imgShowCenter img");
	var flashTextContainer=$("#flashTextContainer");
	$("#imgShowCenter").imgHLRShow({
		lid:"imgShowLeft",
		rid:"imgShowRight",
		imgClick: function() {
		if(locking){
		if($(this).width()==57){
			locking=false;
			index=$(this).index();
			clearTimeout(indexSet);
		   //更改边框
		   imgList.css("border","0px").width(57).height(39);
		   $(this).css("border","1px solid #1d1a5a").width(55).height(37);
		   //属性
		   var bigSrc=$(this).attr("bigSrc");
		   var flashUrl=$(this).attr("flashUrl");
		   var left=$(this).attr("flashX");
		   var top=$(this).attr("flashY");
		   //动态加载图片
		   loading.removeClass("no");
		   loadImage(bigSrc,function(){
			  loading.addClass("no");
			  $("#flashText").replaceWith('<embed id="flashText" src="flash/null.swf" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="502" height="198"></embed>');
			  if(isFirst){
				  bigImg.css("opacity",0.3);
				  bigImg.attr("src",bigSrc);
				  flashTextContainer.css("left",left).css("top",top);
				  bigImg.animate({opacity:1},700,function(){
					  $("#flashText").replaceWith('<embed id="flashText" src="'+flashUrl+'" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="502" height="198"></embed>');
					  locking=true;
					  indexSet=setTimeout("imgclick()",4000);
				  });
			  }else{
				  bigImg.animate({opacity:0.3},800,function(){
					  bigImg.attr("src",bigSrc);
					  flashTextContainer.css("left",left).css("top",top);
					  bigImg.animate({opacity:1},700,function(){
						  $("#flashText").replaceWith('<embed id="flashText" src="'+flashUrl+'" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="502" height="198"></embed>');
						  locking=true;
						  indexSet=setTimeout("imgclick()",4000);
					  });
				  });
			  }
			  isFirst=false;
		   });
		 }
		}
	  }
	});
	//遮罩层
	function flashPosition(){
   	 var layer=$("#layer");
   	 var indexSwfDiv=$("#indexSwfDiv");
        //layer.width($(window).width());
      //  layer.height($(window).height());
        indexSwfDiv.css("margin-left",($(window).width()-indexSwfDiv.width())/2);
        indexSwfDiv.css("margin-top",($(window).height()-indexSwfDiv.height())/2);
      }
    flashPosition();
    $(window).resize(flashPosition);
    
});
function imgclick(){
	if(index+1==imgList.size()){
		index=0;
	}else{
		index=index+1;
	}
	imgList.eq(index).click();
}
function load(){
	$("#layer").css("display","none");
	imgList.eq(0).click();
}
