/*
Easy Images Slider
build time: Jan 07 20:17 
Author: Lain
幻灯片效果
HTML:
<div class="slider">
	<ol>
		<li><img src="path/img01.jpg"></li>
		....
	</ol>
</div>
Javascript:
$('.slider').imgSlider();	
*/ 

(function($){
$.extend($.easing,{
	easeOutQuint:function (x, t, b, c, d){
		return c*((t=t/d-1)*t*t*t*t + 1) + b;
	}
});
$.fn.imgSlider = function(Onevent){
		var box=$(this).find('ol');
		var height=$(this).height();
		var length=box.find('li').length;
		var j=1;
		var gonext=setInterval(next,8000);//3000
		
		//生成按钮
		var ButtonUL=document.createElement("ul");
		$(this).append(ButtonUL);
		for(var i=1;i<=length;i++){
			var ButtonLI="<li>" + i + "</li>";
			$(this).find('ul').append(ButtonLI);
		}
		
		var button=$(this).find('ul');
		button.find('li').eq(0).addClass("current");
		
		//hover切换延迟
		var timer;
		var hoverDelay=function(){
			var Num=button.find('.focus').text();
			var top=-height*(Num-1);
			button.find('.current').removeClass('current');
			button.find('li').eq(Num-1).addClass("current");
			box.animate({'top':top},500,"easeOutQuint");
			j=parseInt(Num)+1;
		};
		
		button.find('li').mouseover(function(){
			clearInterval(gonext);
			button.find('li').removeClass("focus");
			$(this).addClass("focus");
			clearTimeout(timer);
			timer=setTimeout(hoverDelay,150);
		}).mouseout(function(){
			clearTimeout(timer);
			gonext=setInterval(next,8000);//3000
		});
		//下一屏
		function next(){
			if(j>length) j=1;
			var top=-height*(j-1);
			button.find('.current').removeClass('current');
			button.find('li').eq(j-1).addClass("current");
			box.animate({'top':top},500,"easeOutQuint");
			j=j+1;
		}
}	
})(jQuery);	
