(function($){
	$.fn.extend({
		picker: function(options) {
			var defaults = {
				item:$("li", this), //the item definition
				defaultItem:$("li", this).eq(0), //the first visible item
				maxWidth:100,
				minWidth:10,
				interval:5000,
				wait:10000,
				duration:500,
				autoStart:true
			};

			var options = $.extend(defaults, options);

			return this.each(function() {
				var o = options;
				var obj = $(this);
				var items = $(o.item, obj);
				
				//show the default item
				o.defaultItem.css("width", o.maxWidth);
				
				//keep track of the last item
				var lastItem = o.defaultItem;
				
				//start the interval
				if(o.autoStart == true) {
					startInterval(o.interval);
				}
				
				items.click(function() {
					waitInterval(o.wait);
					showItem(this);
				});
				
				function showItem(target) {
					lastItem.animate({width: o.minWidth+"px"}, {queue:false, duration:o.duration});
					$(target).animate({width: o.maxWidth+"px"}, {queue:false, duration:o.duration});
					lastItem = $(target);

					broadcastClick(items.index(lastItem));
				}

				function broadcastClick(index) {
					var event = new jQuery.Event("picked");
					event.index = index;
					items.eq(index).trigger(event);
				}
				
				function startInterval(time) {
					$(this).everyTime(time, function() {
						var pos = items.index(lastItem)+1;
						if(pos == items.length) {
							pos = 0;
						}
						showItem(items.eq(pos));
					});	
				}
				
				function waitInterval(time) {
					clearInterval();
					
					$(this).oneTime(time, function() {
						startInterval(o.interval);
					});
				}
		
				function clearInterval() {
					$(this).stopTime();
				}
			
			});
		}
	});
})(jQuery);