(function($) {
		  
	// plugin definition
	$.fn.carousel = function(o) {	
	
		// set default values
		o = $.extend({	
			displayItems	: 1, 					// number of items to show at any given time
			autoRotation	: 0,					// automatic rotation of the carousel on a set timer [0 - no rotation]
			scrollCount		: 1,					// number of items to scroll
			animation		: 'slide', 				// slide 
			animationSpeed	: 600, 					// animation speed
			orientation		: 'horizontal',			// horizontal | vertical			
			btnNext			: '#next',				// default next button
			btnPrev			: '#previous',			// default previous button
			listMargin		: 17
		}, o || {});
	

		return this.each(function() {					  
			var div = $(this);						// the div tag that holds the ul
			var ul	= $("ul", div);					// the ul tag the holds the product list
			var li	= $("li", ul);					// the product list
			
			var li_first = 1;						// first item counter
			var li_last = o.displayOptions;	// last item counter
			var li_margin = o.listMargin;		// margin of list item 
			var ulDefaultLeft = ul.css('margin-left');
			
			// move next
			$(o.btnNext).click(function() {
				move('left');
				return false;
			});
			

			// move previous
			$(o.btnPrev).click(function() {
				move('right');
				return false;
			});
			
			
			
			// expand the list items width base on content
			li_width = li.width();
			ul.width((li.size() * li_width) + (li.size() * li_margin))
			
			
			
			// list mover
			function move(dir)
			{	
				
				if (dir=='left') {
					li_first += parseInt(o.scrollCount);					
					direction = '-=';
				} else {
					li_first -= parseInt(o.scrollCount);
					direction = '+=';
				}
				li_last = li_first + o.displayItems - 0;
				if (li_last > (li.size()+1)) {
					ul.animate({
						marginLeft: ulDefaultLeft
						}, o.animationSpeed );
						
					li_first = 1;						// reset first item counter
					li_last = o.displayItems;		// reset last item counter
				}else if (li_first < 1) {
					ul.animate({
						marginLeft: "-" + ((li.size() - o.displayItems) * (li_width + li_margin) - parseInt(ulDefaultLeft)) + "px"
						}, o.animationSpeed );					
						
					li_first = (li.size()+1) - o.displayItems;	// reset first item counter to last
					li_last = li.size();				// reset last item counter
				} else {				
					ul.animate({
						marginLeft: direction + (li_width + li_margin) + "px"
						}, o.animationSpeed );
				}
				
			}
			
			
        });
    };
    

})(jQuery);