// Include JS for MLP
	
var t = n = count = 0;
var slideTime = 5500;
var thumbView = true; //是否显示缩略图层
var i = 0;//initialize
var int=0;//Internet Explorer Fix
$(window).bind("load", function() {//The load event will only fire if the entire page or document is fully loaded
	var int = setInterval("doThis(i)",500);//500 is the fade in speed in milliseconds
});


$(function() {
		// 统计照片总数
		count = $("#Slidelist a").size();
		
		// 如果图片数量是大于1的，则执行。
		if(count>1){
			// 插入预备层
			$("#BrandingImgStyle1 > #Slidelist").before("<div class='layer'></div><div class='thumbs'></div>");
			// 设置底层样式
			$(".layer").css({"background-color": "#333", "height": 50,"margin-top": 160,"opacity": 0.5,"position": "absolute","width": 765,"z-index": 1000,"display":"none"});
			// 复制图片至缩略图层并设定样式
			$("#BrandingImgStyle1 img").clone().prependTo($(".thumbs"));
			$('#BrandingImgStyle1 .thumbs img').wrap("<span></span>");
			$('#BrandingImgStyle1 .thumbs span').hover(
				  function () {$(this).stop(true, true).animate({opacity: 1},'fast');},function () {$(this).not($(".active")).stop(true, true).animate({opacity: 0.3},'normal');})
			$(".thumbs").css({"height": 50,"margin-top": 160,"position": "absolute","width": 765,"z-index": 1001,"display":"none"});
			
			// 鼠标覆盖显示缩略图层
			if(thumbView==true){
				$("#BrandingImgStyle1").hover(
				  function () {$(".layer,.thumbs").stop(true, true).fadeIn("Slow");},
				  function () {$(".layer,.thumbs").stop(true, true).fadeOut("fast");}
				);
			}
			// 隐藏除第一张以外的照片
			$("#Slidelist a:not(:first-child)").hide();
			// 设定第一个按钮的样式
			$(".thumbs span:first").addClass("active").siblings().css({"opacity":0.3})
			
			// 点击事件
			$(".thumbs span").click(function() { 
				var i = $(".thumbs span").index(this); 	// 为当前索引值设定为文字-1
				n = i;
				if (i >= count) return; // 如果当前索引大于总数则无动作
				
				// 让当前显示的图片渐隐然后让索引的图片渐显
				$("#Slidelist a").filter(":visible").fadeOut(500).parent().children().eq(i).fadeIn(1000);
				// 改变点击时按钮的样式，并重设其他按钮颜色
				$(this).css({"opacity":1}).addClass("active").siblings().css({"opacity":0.3}).removeClass("active");
				clearInterval(t)
				t = setInterval("showAuto()", slideTime);
			});
			// 设定自动执行时间
			t = setInterval("showAuto()", slideTime);
			/* 但鼠标覆盖时则停止自动执行，移开时继续
			$("#BrandingImgStyle1").hover(function(){clearInterval(t)}, 
				function(){t = setInterval("showAuto()", 5000);
			})*/;
		}
})
	
// 自动执行
function showAuto()
{
	// 如果n >= 总数减一则设定为0，否则+1
	n = n >= (count - 1) ? 0 : n + 1;
	// 点击切换图片（执行切换动作）
	$(".thumbs img").eq(n).trigger('click');
}

function doThis() {
	var imgs = $('#Slidelist a').length;//count the number of images on the page
	if (i >= imgs) {// Loop the images
		clearInterval(int);//When it reaches the last image the loop ends
		$("#Slidelist").removeClass("preload");
	}
	i++;//add 1 to the count
}





// Google Analytics
var pageTracker = _gat._getTracker("UA-1088076-1"); 
pageTracker._initData(); pageTracker._trackPageview(); 

