/*
 * FeatureList - simple and easy creation of an interactive "Featured Items" widget
 * Examples and documentation at: http://jqueryglobe.com/article/feature_list/
 * Change: Vitor de Moraes
 * Version: 1.1.0 (26/11/2010)
 * Copyright (c) 2009 jQueryGlobe
 * Licensed under the MIT License: http://en.wikipedia.org/wiki/MIT_License
 * Requires: jQuery v1.3+
*/
;
(function($) {
	$.fn.featureList = function(options) {
		var opts = $.extend({}, $.fn.featureList.defaults, options);
		var tabs = $(opts.tabs);
		var output = $(opts.output);
		var total_items = tabs.length;

		function slide(nr) {
			if (typeof nr == "undefined") {
				nr = opts.start_item + 1;
				nr = nr >= total_items ? 0 : nr;
			}

			tabs.removeClass('current').filter(":eq(" + nr + ")").addClass('current');

			output.stop(true, true).filter(":visible").fadeOut();
			output.filter(":eq(" + nr + ")").fadeIn(function() {
				opts.start_item = nr;
			});
		}

		if(total_items > 1){
			tabs.removeClass('current').filter(":eq(0)").addClass('current');
			tabs.parent().parent().css('display', 'block');

			output.hide();
			output.eq(opts.start_item).show();
			$(this).eq(opts.start_item).addClass('current');

			tabs.click(function(){
				if ($(this).hasClass('current'))
					return false;

				slide(tabs.index(this));
			});

			if (opts.transition_interval > 0) {
				var timer = setInterval(function () {
					slide();
				}, opts.transition_interval);

				if (opts.pause_on_hover) {
					tabs.mouseenter(function() {
						clearInterval(timer);
					}).mouseleave(function() {
						clearInterval(timer);
						timer = setInterval(function () {
							slide();
						}, opts.transition_interval);
					});
				}
			}
		}

		return this;
	};

	$.fn.featureList.defaults = {
		output: '#output li',
		tabs: '#slideshow-nav a',
		start_item: 0,
		pause_on_hover: true,
		transition_interval: 5000
	};
})(jQuery);
