(function($) {

	$.fn.easySlider = function(options){
	  
		// default configuration properties
		var defaults = {
			prevId: 		'prev-prd',
			nextId: 		'next-prd',	
			speed: 			800,
			stay:			5000,
			rotate:			true	
		}; 
		
		var options = $.extend(defaults, options);  
		
		return this.each(function() {  
			obj = $(this); 				
			var s = $("li", obj).length;
			var w = obj.width(); 
			var h = obj.height(); 
			var ts = s-1;
			var t = 0;
			$("ul", obj).css('width',s*w);			
			$("."+options.prevId+" a").hide();
			$("."+options.nextId+" a").hide();
			$("."+options.nextId+" a").click(function() {
				animate("next");
				if (t>=ts) $(this).fadeOut();
				$("."+options.prevId+" a").fadeIn();
			});
			$("."+options.prevId+" a").click(function() {
				animate("prev");
				if (t<=0) $(this).fadeOut();
				$("."+options.nextId+" a").fadeIn();
			});	
						
			function animate(dir){
				if(dir == "next"){
					t = (t>=ts) ? ts : t+1;
				} else {
					t = (t<=0) ? 0 : t-1;
				};		
				$('.count').html(t+1);
					p = (t*w*-1);
					$("ul",obj).animate(
						{ marginLeft: p }, 
						options.speed
					);				
			};
			
			function rotate() {
				if (t<ts) {
					animate("next");
					if (t>=ts) $("."+options.nextId+" a").fadeOut();
					$("."+options.prevId+" a").fadeIn();
				} else {
					$("ul",obj).animate(
						{ marginLeft: 0 }, 
						options.speed
					);
					t = 0;
					$('.count').html(t+1);
					if (t<=0) $("."+options.prevId+" a").fadeOut();
					$("."+options.nextId+" a").fadeIn();
				}
				return false;
			}
						
			if(s>1) $("."+options.nextId+" a").fadeIn();
			$('.length').html(s);
			$('.count').html(t+1);	

			if (options.rotate == true) {
				rotateInterval = setInterval ( function() {rotate()}, options.stay );
				$('#home-splash').mouseover(function() {
					clearInterval(rotateInterval);
				});
				$('#home-splash').mouseout(function () {
					rotateInterval = setInterval ( function() {rotate()}, options.stay );
				});
			}
		});
	};

})(jQuery);