
(function($) {
	jQuery.fn.geeCarousel = function(options) {
		/*--------------------------------
		/ Defualt Settings
		--------------------------------*/
		settings = jQuery.extend({
					wrapperID: '.geeCarousel',
					prevBtnID: '.geeCarouselPrev',
					nextBtnID: '.geeCarouselNext',
					animateDuration: 200
		}, options);
		
		/*--------------------------------
		/ Private Properties
		--------------------------------*/
		var wrapper;
		var container;
		var elements;
		var elementCount;
		var elementWidth;
		var wrapperWidth;
		var containerWidth;
		var currentPos;
		
		/*--------------------------------
		/ Functions
		--------------------------------*/
		init = function() {
			//alert(this.attr('class'));
			wrapper			= $(options.wrapperID);
			container		= $(options.wrapperID + ' > ul');
			elements		= $(options.wrapperID + ' > ul > li');

			elementCount	= parseInt(elements.size());
			elementWidth	= parseInt(elements.outerWidth(true));
			wrapperWidth	= parseInt(wrapper.width());
			containerWidth	= elementCount * elementWidth;
			currentPos		= 0;
			
			container.css('width',containerWidth);
		}
		
		/*--------------------------------
		/ Control Buttons
		--------------------------------*/
		function MoveNext(position) {
			container.animate({left: position}, options.animateDuration);
			currentPos = position;
		}

		$(options.prevBtnID).click(function() {
			var nextPos = currentPos + elementWidth;
			if (nextPos % elementWidth != 0)
				nextPos = ((nextPos/elementWidth) * elementWidth) - elementWidth;

			if (nextPos <= 0) {
				MoveNext(nextPos);
			}
		});

		$(options.nextBtnID).click(function() {
			var nextPos = currentPos - elementWidth;
			if (nextPos % elementWidth != 0)
				nextPos = ((nextPos/elementWidth) * elementWidth) + elementWidth;
						
			if ((((containerWidth + nextPos) - wrapperWidth) /* SS - 18/03/2010 + elementWidth */) >= 0 ) { 
				MoveNext(nextPos);
			}
		});	
		
		// Initialize
		init();
	}
})(jQuery);

