(function($) {
	$.fn.easySlider = function(options){
		// default configuration properties
		var defaults = {			
			prevId: 		'prevBtn',
			prevText: 		'Previous',
			nextId: 		'nextBtn',	
			nextText: 		'Next',
			controlsShow:	true,
			controlsBefore:	'',
			controlsAfter:	'',	
			controlsFade:	true,
			firstId: 		'firstBtn',
			firstText: 		'First',
			firstShow:		false,
			lastId: 		'lastBtn',	
			lastText: 		'Last',
			lastShow:		false,				
			vertical:		false,
			speed: 			800,
			auto:			false,
			pause:			2000,
			continuous:		false, 
			numeric: 		false,
			numericId: 		'controls'
		}; 
		
		var options = $.extend(defaults, options);  
				
		this.each(function() {  
			var obj = $(this); 				
			var s = $("li", obj).length;
			var w = $("li", obj).width(); 
			var h = $("li", obj).height(); 
			var clickable = true;
			obj.width(w); 
			obj.height(h); 
			obj.css("overflow","hidden");
			var ts = s-1;
			var t = 0;
			$("ul", obj).css('width',s*w);
							
			if(options.controlsShow){
				var html = options.controlsBefore;				
				html += '<div class="'+ options.swClass +'">';
				html += '<a href=\"javascript:void(0);\" id="'+ options.prevId +'" class="'+ options.prevClass +'" style="display: none;">'+ options.prevText +'</a>';
				html += '<a href=\"javascript:void(0);\"id="'+ options.nextId +'" class="'+ options.nextClass +'">'+ options.nextText +'</a>';
				html += '<div class="cb"></div></div>';
				
				html += options.controlsAfter;						
				$(obj).after(html);										
			};
			
			$("#"+options.nextId).click(function(){		
				animate("next",true);
			});
			$("#"+options.prevId).click(function(){		
				animate("prev",true);				
			});	
			$("#"+options.firstId).click(function(){		
				animate("first",true);
			});				
			$("#"+options.lastId).click(function(){		
				animate("last",true);				
			});
			
			function adjust(){
				if(t>ts) t=0;		
				if(t<0) t=ts;	
				$("ul",obj).css("margin-left",(t*w*-1));
				clickable = true;
			};
			
			function animate(dir,clicked){
				if (clickable){
					clickable = false;
					var ot = t;				
					switch(dir){
						case "next":
							t = (ot>=ts) ? (options.continuous ? t+1 : ts) : t+1;						
							break; 
						case "prev":
							t = (t<=0) ? (options.continuous ? t-1 : 0) : t-1;
							break; 
						case "first":
							t = 0;
							break; 
						case "last":
							t = ts;
							break; 
						default:
							t = dir;
							break; 
					};	
					var diff = Math.abs(ot-t);
					var speed = diff*options.speed;
					p = (t*w*-1);
					$("ul",obj).animate(
						{ marginLeft: p }, 
						{ queue:false, duration:speed, complete:adjust }
					);
					
					if(t==ts){
						$("#"+options.nextId).hide();
						$("#"+options.lastId).hide();
					} else {
						$("#"+options.nextId).show();
						$("#"+options.lastId).show();					
					};
					if(t==0){
						$("#"+options.prevId).hide();
						$("#"+options.firstId).hide();
					} else {
						$("#"+options.prevId).show();
						$("#"+options.firstId).show();
					};				
					
					if(clicked) clearTimeout(timeout);
				};
				
			};
			
			// init
			var timeout;
			$("#"+options.prevId).hide();
			$("#"+options.firstId).hide();
		});
	  
	};

})(jQuery);




