(function($){
$.fn.extend({        
        Scroll:function(opt,callback){                
                          
                if(!opt) var opt={};                
                var _BtnRight = $("#"+ opt.right);               
                var _BtnLeft = $("#"+ opt.left);              
                var timerID; 
				var timer; 
                var _this=this.eq(0).find("ul:first");                
                var     lineW=_this.find("li:first").width(), 
                        line=1,//opt.line?parseInt(opt.line,10):parseInt(this.width()/lineW,10),           
												speed=opt.speed?parseInt(opt.speed,10):500;                                               
												timer=opt.timer?parseInt(opt.timer,10):3000;               
								if(line==0) line=1;                
								var rightWidth=0-line*lineW;                
								          
								var scrollLeft=function(){                        
								        _BtnLeft.unbind("click",scrollLeft);       
								        _this.animate({                                
								                marginLeft:rightWidth
												},speed,function(){                                
												        for(i=1;i<=line;i++){                                        
												                _this.find("li:first").appendTo(_this);                             
												        }                                
												        _this.css({marginLeft:0});
												        _this.find("li").removeClass("flon");
												        _this.find("li:first").addClass("flon");
												       $(".panel a").html(_this.find("li:first").html());                               
												        _BtnLeft.bind("click",scrollLeft);                       
												});                 
								}                
								               
								var scrollRight=function(){
									_BtnRight.unbind("click",scrollRight);
									for(i=1;i<=line;i++){
										_this.find("li:last").show().prependTo(_this);
									}
									_this.css({marginLeft:rightWidth});
									_this.find("li").removeClass("flon");
									 _this.find("li:first").addClass("flon");
									 $(".panel a").html(_this.find("li:first").html());  
									_this.animate({
										marginLeft:0
									},speed,function(){
										_BtnRight.bind("click",scrollRight);
									});
								}
								               
								var autoPlay = function(){
												if(timer)timerID = window.setInterval(scrollLeft,timer); 
												                                                                          
                                                                                                                                                         
								};                
								var autoStop = function(){                        
												if(timer)window.clearInterval(timerID);                
								};                 
								                
								_this.hover(autoStop,autoPlay); autoPlay();                
								_BtnRight.css("cursor","pointer").click( scrollRight ).hover(autoStop,autoPlay);               
								_BtnLeft.css("cursor","pointer").click( scrollLeft ).hover(autoStop,autoPlay);         
				}      
})
})(jQuery);

