(function($) {

	$.fn.easySliderP = function(options){
	  
		// default configuration properties
		var defaults = {			
			prevIdP: 		'prevBtnP',
			prevTextP: 		'',
			nextIdP: 		'nextBtnP',	
			nextTextP: 		'',
			controlsShowP:	false,
			controlsBeforeP:	'',
			controlsAfterP:	'',	
			controlsFadeP:	false,
			firstIdP: 		'firstBtnP',
			firstTextP: 	'',
			firstShowP:		false,
			lastIdP: 		'lastBtnP',	
			lastTextP: 		'',
			lastShowP:		false,				
			verticalP:		false,
			speedP: 			1000,
			autoP:			true,
			pauseP:			5000,
			continuousP:		true
		}; 
		
		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(); 
			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.verticalP) $("li", obj).css('float','left');
			
			if(options.controlsShowP){
				var html = options.controlsBeforeP;
				if(options.firstShowP) html += '<span id="'+ options.firstIdP +'"><a href=\"javascript:void(0);\">'+ options.firstTextP +'</a></span>';
				html += ' <span id="'+ options.prevIdP +'"><a href=\"javascript:void(0);\">'+ options.prevTextP +'</a></span>';
				html += ' <span id="'+ options.nextIdP +'"><a href=\"javascript:void(0);\">'+ options.nextTextP +'</a></span>';
				if(options.lastShowP) html += ' <span id="'+ options.lastIdP +'"><a href=\"javascript:void(0);\">'+ options.lastTextP +'</a></span>';
				html += options.controlsAfterP;						
				$(obj).after(html);										
			};
	
			$("a","#"+options.nextIdP).click(function(){		
				animate("next",true);
			});
			$("a","#"+options.prevIdP).click(function(){		
				animate("prev",true);				
			});	
			$("a","#"+options.firstIdP).click(function(){		
				animate("first",true);
			});				
			$("a","#"+options.lastIdP).click(function(){		
				animate("last",true);				
			});		
			
			function animate(dir,clicked){
				var ot = t;				
				switch(dir){
					case "next":
						t = (ot>=ts) ? (options.continuousP ? 0 : ts) : t+1;						
						break; 
					case "prev":
						t = (t<=0) ? (options.continuousP ? ts : 0) : t-1;
						break; 
					case "first":
						t = 0;
						break; 
					case "last":
						t = ts;
						break; 
					default:
						break; 
				};	
				
				var diff = Math.abs(ot-t);
				var speedP = diff*options.speedP;						
				if(!options.verticalP) {
					p = (t*w*-1);
					$("ul",obj).animate(
						{ marginLeft: p }, 
						speedP
					);				
				} else {
					p = (t*h*-1);
					$("ul",obj).animate(
						{ marginTop: p }, 
						speedP
					);					
				};
				
				if(!options.continuousP && options.controlsFadeP){					
					if(t==ts){
						$("a","#"+options.nextIdP).hide();
						$("a","#"+options.lastIdP).hide();
					} else {
						$("a","#"+options.nextIdP).show();
						$("a","#"+options.lastIdP).show();					
					};
					if(t==0){
						$("a","#"+options.prevIdP).hide();
						$("a","#"+options.firstIdP).hide();
					} else {
						$("a","#"+options.prevIdP).show();
						$("a","#"+options.firstIdP).show();
					};					
				};				
				
				if(clicked) clearTimeout(timeout);
				if(options.autoP && dir=="next" && !clicked){;
					timeout = setTimeout(function(){
						animate("next",false);
					},diff*options.speedP+options.pauseP);
				};
				
			};
			// init
			var timeout;
			if(options.autoP){;
				timeout = setTimeout(function(){
					animate("next",false);
				},options.pauseP);
			};		
		
			if(!options.continuousP && options.controlsFadeP){					
				$("a","#"+options.prevIdP).hide();
				$("a","#"+options.firstIdP).hide();				
			};				
			
		});
	  
	};

})(jQuery);