/**
 * jQuery Fader
 * Copyright (c) 2010-2011 Christian Schmitz <mail@schmizz.com>
 */
(function($){
	$.fn.fader = function(options) {
		// Extend our default options with those provided.
		var options = $.extend({}, $.fn.fader.defaults, options);
		
		var setup = function() {
			var $this   = $(this);
			var $parent = $this.parent();
			
			var o = $.meta ? $.extend({}, options, $this.data()) : options;

			var current = 0;
			var $items = $('li', $this);
			
			var update = function() {
				var $item = $('li:last', $parent);
				$item.animate({opacity: 0}, o.speed, 'linear', function() {
					$item.prependTo($item.parent()).css({opacity: 1});
					window.setTimeout(update, o.delay);
				});
			};

			var move = function() {
				var offset = $parent.width() * current * -1;
				$this.animate({ 'margin-left': offset }, { duration: "slow" });
			}
			
			window.setTimeout(update, o.delay);
		};
		
	 	// Our plugin implementation code goes here.
		return this.each(setup);
	};
	
	$.fn.fader.defaults = {
		'delay' : 1500,
		'speed': 200
	};

	function debug($obj) {
		if (window.console && window.console.log)
			window.console.log($obj);
	};
})(jQuery);
