$(document).ready(function(){
	$(".images li").eq(0).show();
	var images=$(".images li");
	var imageslength = images.length;
	if(imageslength>3)imageslength=3;
	if(images.length>1)
	{	
		 //自动开始
		 var MyTime = setInterval(function(){
			showImg(index)
			index++;
			if(index==images.length){index=0;}
		 } , 3000);

		$(".buttons").empty();
		for(var i=0;i<imageslength;i++)
		{
			$(".buttons").append("<span>"+(i+1)+"</span>");
		}
		
		 var index = 0;
		 $(".buttons span").mouseover(function(){
			index  =  $(".buttons span").index(this);
			showImg(index);
		});	
		 //滑入 停止动画，滑出开始动画.
		 $('#imgnav').hover(function(){
				  if(MyTime){
					 clearInterval(MyTime);
				  }
		 },function(){
				  MyTime = setInterval(function(){
					showImg(index)
					index++;
					if(index==imageslength){index=0;}
				  } , 3000);
		 });
	}
	else
	{
		if($(".images img")[0].src.indexOf("images/no_pic.gif")	>-1 || imageslength==0)
		{
			$(".images li").empty().append("<span class=\"nopic\">暂无预览</span>");
		}
	}
	
})


function showImg(i){
		$(".images img")
			.eq(i).stop(true,true).fadeIn(800)
			.parent().siblings().find("img").hide();
		$(".images li")
			.eq(i).stop(true,true).fadeIn(800)
			.siblings().hide();
		 $(".buttons span")
			.eq(i).addClass("hov")
			.siblings().removeClass("hov");
}

