(function($) {

	$.fn.slider = function(options){
		
		var defaults = {
			auto: "on",
			autospeed: 8000,
			speed: 600			
		}; 
		var options = $.extend(defaults, options);
		
		this.each(function() {  
			var obj = $(this); 				
			var numobj = $("li", obj).length;
			var wid = obj.width();
			var s = numobj-1;
			var t = 0;
			var  autointerval; 
			
			$("li", obj).css('float','left');
			$("ul", obj).prepend($("ul li:last-child", obj).clone().css("margin-left","-"+ wid +"px"));
			$("ul", obj).append($("ul li:nth-child(2)", obj).clone());
			$("ul", obj).css('width',(numobj+1)*wid);
			
			if (options.auto == "on")
				autointerval = setInterval(rotate, options.autospeed);
			
			function animate(dir){
					t = t+1;								
					p = (t*wid*-1);
					$("ul",obj).animate(
						{ marginLeft: p }, 
						options.speed
					);
					if (t > s) {
						t = 0;
						$("ul",obj).animate(
						{ marginLeft: (0*wid*-1) }, 
						0
						);
					}
			};
			function rotate(){
				animate("next");
			};
			$("img",obj).click(function(){
				rotate();
			});
			
		});

	};

})(jQuery);