// Twirlie - jQuery animation made simple
// Debashis Chakraborty and Qiming Weng
// Created: November 13, 2009
// Last updated: November 21, 2009

// Version 1.0.1

(function($){  
	$.fn.twirlie = function(options) {
		var defaults = {
			transtime     : 500, //time in milliseconds for items to transition
			nextSel       : "a#next", //CSS selector for next button
			prevSel       : "a#prev", //CSS selector for previous button
		};
		var options = $.extend(defaults, options);
		var obj = this;
		$(this).each(function() {
			var next = options.nextSel;
			var prev = options.prevSel;
			var current = 0;
			var total = $('ul li', obj).size();
			var widthNP = obj.css("width");
			var width = parseInt(widthNP.substring(0, widthNP.length-2));
		
			$(next).click(function() {
				current += 1;
				if (current == total) current = 0;
				$('ul', obj).animate({
					left: current*(0-width) + "px"
			    }, options.transtime);
			});
	
			$(prev).click(function() {
				current -= 1;
				if (current < 0) current = total-1;
				$('ul', obj).animate({
					left: current*(0-width) + "px"
			    }, options.transtime);
			});
	   });
	}
})(jQuery); 