(function($){
$.fn.carousel = function(params) {
	var defaults = {
		duration: 500,
		delay: 4000
	}
	
	var opts = $.extend(defaults, params);
	
	this.each(function() {
		var $this = $(this);
		var $a = $this.find('a');
		$a.not(':first').hide();
		
		var $current = $a.eq(0);
		
		var timeout = 0;
		
		loop();
		
		var $next;
		
		function next() {
			if ($current.next('a').length) {
				$next = $current.next('a');
			} else {
				$next = $a.eq(0);
			}
			$current.fadeOut(opts.duration, function() {
				$next.fadeIn(opts.duration);
				$current = $next;
				loop();
			});
		}
		
		function loop() {
			if (timeout != 0) {
				clearTimeout(timeout);
				timeout = setTimeout(next, opts.delay);
			} else {
				timeout = setTimeout(next, opts.delay - (opts.duration * 2));
			}
			
		}
	});
}
})(jQuery)