window.onload = function ()
{
	var oBox = document.getElementById("flash");
	var oList = oBox.getElementsByTagName("ul")[0];
	var aImg = oBox.getElementsByTagName("img");
	var timer = playTimer = null;
	var index = i = 0;
	var bOrder = true;
	var aTmp = [];
	var aBtn = null;
	
	//生成数字按钮
	for (i = 0; i < aImg.length; i++) aTmp.push("<li></li>");
	
	//插入元素
	var oCount = document.createElement("ul");
	oCount.className = "count";
	oCount.innerHTML = aTmp.join("");
	oBox.appendChild(oCount);	
	aBtn = oBox.getElementsByTagName("ul")[1].getElementsByTagName("li");
	
	//初始化状态
	cutover();
	
	//按钮点击切换
	for (i = 0; i < aBtn.length; i++)
	{
		aBtn[i].index = i;
		aBtn[i].onmousedown = function ()
		{
			index = this.index;
			cutover()
		}
	}
	
	function cutover()
	{
		for (i = 0; i < aBtn.length; i++) aBtn[i].className = "";
		aBtn[index].className = "current";			
		startMove(-(index * aImg[0].offsetHeight))
	}
	
	function next()
	{
		/*bOrder ? index++ : index--;
		index <= 0 && (index = 0, bOrder = true);
		index >= aBtn.length - 1 && (index = aBtn.length - 1, bOrder = false)*/
		index++;
		if (aImg.length-1 < index) index=0;		
		cutover()
	}
	
	playTimer = setInterval(next, 5000);
	
	//鼠标移入展示区停止自动播放
	oBox.onmouseover = function ()
	{
		clearInterval(playTimer)
	};
	
	//鼠标离开展示区开始自动播放
	oBox.onmouseout = function ()
	{
		playTimer = setInterval(next, 5000)
	};
	function startMove(iTarget)
	{
		clearInterval(timer);
		timer = setInterval(function ()
		{
			doMove(iTarget)
		}, 30)	
	}
	function doMove (iTarget)
	{		
		var iSpeed = (iTarget - oList.offsetTop) / 10;
		iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);		
		oList.offsetTop == iTarget ? clearInterval(timer) : oList.style.top = oList.offsetTop + iSpeed + "px"
	}
};
//flash轮播
$(function(){	   
	//裸钻右侧体验店	   
	$(".index_shop").mouseover(function(){
		$(this).addClass("on");		
	});
	$(".index_shop").mouseout(function(){
		$(this).removeClass("on");
	});		   
		   
	//计算宽度 TTP广告位
	var num = $(".ul_ttp li").size();
	var w = num*273;
	var left_end = (num-1)*(-273);
	$(".ul_ttp").css("width",w+"px");	
	//点击播放
	$("#prev").click(function(){				
		var left = parseInt($(".ul_ttp").css("left").replace("px",""));
		if(left % 273 != 0) return;
		if(left<0){
			var left = left+273;
			$(".ul_ttp").animate({left:left+"px"},{queue:false,duration:300});
		}else{
			$(".ul_ttp").animate({left:left_end+"px"},{queue:false,duration:500});
		};
	});
	//点击播放
	$("#next").click(function(){		
		var left = parseInt($(".ul_ttp").css("left").replace("px",""));
		if(left % 273 != 0) return;
		if(left>left_end){ 
			var left = left-273;
			$(".ul_ttp").animate({left:left+"px"},{queue:false,duration:300});
		}else{
			$(".ul_ttp").animate({left:0+"px"},{queue:false,duration:500});
		};
	});

	//计算宽度 体验店文字列表
	var tiyan_num = $(".tiyan_box span").size();
	var tiyan_w = tiyan_num*30;
	var tiyan_end = (tiyan_num-5)*(-30);
	$(".tiyan_box").css("width",w+"px");	
	//点击播放
	$(".tiyan_left").click(function(){				
		var left = parseInt($(".tiyan_box").css("left").replace("px",""));
		if(left % 30 != 0) return;
		if(left<0){
			var left = left+30;
			$(".tiyan_box").animate({left:left+"px"},{queue:false,duration:300});
		}else{
			$(".tiyan_box").animate({left:tiyan_end+"px"},{queue:false,duration:500});
		};
	});
	//点击播放
	$(".tiyan_right").click(function(){		
		var left = parseInt($(".tiyan_box").css("left").replace("px",""));
		if(left % 30 != 0) return;
		if(left>tiyan_end){ 
			var left = left-30;
			$(".tiyan_box").animate({left:left+"px"},{queue:false,duration:300});
		}else{
			$(".tiyan_box").animate({left:0+"px"},{queue:false,duration:500});
		};
	});
	//微博
	$(".weibo").each(function(){
		var dl_tab = this;	
		$('dt', dl_tab).mouseover(function(){
			$('dt', dl_tab).removeClass("un");	
			$(this).addClass("un");
			$('dd', dl_tab).css("display","none");
			$(this).next().css("display","block");
		})
	});
	//友情链接
	$(".links").mouseover(function(){	
		$(this).animate({height:"38px"},{queue:false,duration:300});
	});
	$(".links").mouseout(function(){		
		$(this).animate({height:"19px"},{queue:false,duration:300});
	});
	
});
