(function($){
		  
	$.fn.jSlide = function(options){
	
		options = $.extend({
						   
			speed: 600,
			easing: "swing",
			direction: "horizontal",
			loop: "false",
			amount: 1,
			single: "false"
		
		}, options || {})
		
		
		//--------------------------- Initialization
		
		var $that = this;
		var $slider = $that.children("ul");
		var blocks = Math.ceil(parseInt($slider.children("li").length) / options.amount);
		var curPos = 0;
		
		var sWidth = (options.width * options.amount) * blocks;
		var sHeight = options.height;
		
		
		
		$that.css({
			position: "relative",
			overflow: "hidden",
			width: options.width,
			height: options.height
		})
		
		$slider.css({
			position: "relative",
			top: 0,
			left: 0,
			listStyle: "none",
			margin: 0,
			padding: 0,
			outline: "none",
			width: sWidth,
			height: sHeight
		})
		
		$slider.children("li").css({float:"left"});
		
		if(options.single===true){
			var ln = $slider.children('li').length;
			var divideH = options.width / $slider.children('li:first').outerWidth(true);
			var divideV = options.height / $slider.children('li:first').outerHeight(true);
			blocks = (options.direction=="horizontal")?Math.floor(ln/options.items)*divideH:Math.floor(ln/options.items)*divideV;
			blocks -= options.items - (ln%options.items);
		}else{
			var divideH = 1;
			var divideV = 1;
		};
		
		
		
		//--------------------------- Interactivity
		
		var anim = function(){
			$slider.stop(true).animate({left: -(curPos*options.width / divideH)}, options.speed, options.easing)
		};
		
		var nextfn = function(){
			
			if(curPos < blocks-1){
				curPos++;
			}
			
			//hide arrows
			$(options.previous).css({visibility: "visible"}).animate({opacity:1}, 300)
			if(curPos == blocks-1) {
				$(options.next).fadeOut();
			 }
			
			anim();
			
			return false
		
		};
		
		var previousfn = function(){
			
			if(curPos > 0){
				curPos--;
			}
			
			hideArrow();
                                
            $(options.next).fadeIn();
			
			anim();
			
			return false
		
		};
		
		
		$(options.next).bind("click", nextfn);
		$(options.previous).bind("click", previousfn);
		
		function hideArrow(){
			if(options.loop === false && curPos <= 0){
				$(options.previous).animate({opacity: 0}, 300, function(){												
					$(this).css({visibility: "hidden"});
				});
			};
		}
		
		hideArrow();
		
	};
		  
})(jQuery);
