(function($) {
	$.fn.syFocus = function(options){  
		// 默认配置属性
		var defaults = {
			prevCls:		'prevBtn',
			nextCls:		'nextBtn',
			auto:			true,     //是否自动播放
			speed: 			1000,
			pause:			5000
		}; 
	    var options = $.extend(defaults, options);
		var Me = this;
		var that = $("a",this);
		var scrol = true;
		that.each(function(e){$(this).attr("autoindex",e);if(e != 0){$(this).hide();}})
		$(this).append('<div class="btns"><ul></ul></div>');
		this.append('<div class="'+options.prevCls+' mypng"><img src="images/index/prevbg.png" /></div>');
		this.append('<div class="'+options.nextCls+' mypng"><img src="images/index/nextbg.png" /></div>');
		var btnLi="";
		for(var i=0;i<that.length;i++){
			btnLi+='<li></li>';
		}
		$(".btns ul").html(btnLi);
		$(".btns li").eq(0).addClass("hov");
		var n = 0;
		var timeout; 
		if(options.auto){
			me();
		}
		that.hover(function(){
			Me.stopTime(); 
		},function(){
			me();
		});
				
		$(".btns li").each(function(e){
			$(this).mouseover(function(){
				 if(scrol){
					 Me.stopTime();
					 var len = e;
					 show(len,100);
				 }
			}).mouseout(function(){
				 me();
			})
		})
		
		$("."+options.nextCls).click(function(){
			Me.stopTime();
			if(scrol){autotime();}
			scrol = false;
		}).hover(function(){$(this).addClass("hov");},function(){$(this).removeClass("hov");})
		
		$("."+options.prevCls).click(function(){
			Me.stopTime();
			if(scrol){autotime("prev");}
			scrol = false;
		}).hover(function(){$(this).addClass("hov");},function(){$(this).removeClass("hov");})
		
		function me(){
			Me.everyTime(options.pause,function(){
				if(scrol){autotime();}		  
			});	
		}
		function show(e,pauses){
			$(".btns li").removeClass();
			$(".btns li").eq(e).addClass("hov");
				that.hide();
				that.removeClass("show");
				that.eq(e).fadeIn(function(){scrol = true;});
				that.eq(e).addClass("show");
			n = e;
		}
		function autotime(prev){
				if(prev=="prev"){
					n--;if(n<0){n=that.length-1;}
					show(n,500);
				}else{
					n++;if(n==that.length){n=0;}
					show(n,500);	
				}
		} 
	}
})(jQuery);

$(function(){
	$("#focus").syFocus();	
})
