
$.fn.easySlider = function(options){
	  
		// default configuration properties
		var defaults = {
			prevId: 		'prevBtn',
			prevText: 		'Precedente',
			nextId: 		'nextBtn',	
			nextText: 		'Successiva',
			speed: 			800
		}; 
		
		var options = $.extend(defaults, options);  
		var wTot = $(this).width();
		return this.each(function() {
			obj = $(this);
			var s = $("li", obj).length;    // num elementi
			var w = $("li", obj).width(); 	// larghezza elemento
			var elxPage=parseInt(wTot/w);	// el per pagina
			$(obj).width(elxPage*w);		// Larghezza giusta
			var h = obj.height(); 		    // altezza elemento
			var ts = s-1;				    // num elementi -1
			var t = 0;
			$('ul', obj).css('left', 0); 	// reset
			$("ul", obj).css('width',s*w);
			$("li", obj).css('float','left');
			$(obj).css('overflow','hidden');
			$("#navigator").remove();
			$(obj).after('<div id="navigator"><span id="'+ options.prevId +'"><a href=\"javascript:void(0);\">'+ options.prevText +'</a></span> <span id="'+ options.nextId +'"><a href=\"javascript:void(0);\">'+ options.nextText +'</a></span></div>');	
			$("a","#"+options.prevId).hide();
			$("a","#"+options.nextId).hide();
			$("a","#"+options.nextId).click(function(){		
				animate("next");
				if (t>=ts || t>=(s-elxPage)) $(this).fadeOut();
				$("a","#"+options.prevId).fadeIn();
			});
			$("a","#"+options.prevId).click(function(){		
				animate("prev");
				if (t<=0) $(this).fadeOut();
				$("a","#"+options.nextId).fadeIn();
			});	
			function animate(dir){
				if(dir == "next"){
					t = (t>=ts) ? ts : t+1;	
				} else {
					t = (t<=0) ? 0 : t-1;
				};								
				p = (t*w*-1);
				$("ul",obj).animate(
					{ left: p }, 
					options.speed
				);				

			};
			if(s>1) $("a","#"+options.nextId).fadeIn();	
		});
};
