/**
 *	jQTabs jQuery Plugin v. 1.0
 * 
 * Copyright (c) 2009 Francis David - (http://www.arcticwebsolutions.com)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */
 
/**
 *	$.jQTabs(string, string, [event type, selected tab])
 *	Params:
 *	- string (string) Specifies a string ID of container which holds the individual tabs
 *	- string (string) Specifies a string ID of container which holds the content for each tab
 *	- object (object) Holds optional parameters
 *		- event type  (string) any event type such as click, mousover etc.
 *		- selected tab (int) index of selected tab
 */
 
(function($){
	$.jQTabs = function (tabs, tabsContent, options){
		
		var defaults = {
			selected : 0,
			evt : "click",
			ani : "show()"
		}
		var options = $.extend(defaults, options||{});
		var tabs = $("#" + tabs).children();
		var tabsContents = $("#" + tabsContent).children();
		
		tabs.each(function() {
			$(this).css("cursor", "pointer");
			$(this).addClass("inactive");
			$(tabs.get(options.selected)).removeClass("inactive").addClass("active");
		});
		
		$(tabsContents).each(function() {
			$(this).hide();
			$(tabsContents.get(options.selected)).show();
		});
		
		$(tabs).bind("mouseover", function(event) {
			$(this).hasClass("active") ? $(this).removeClass("onover") : $(this).addClass("onover");
			event.stopPropagation();
		}).bind("mouseout", function(event) {
			$(this).removeClass("onover");
			event.stopPropagation();
		});
		
		$(tabs).bind(options.evt, function(event) {
			tabsContents.each(function() {
				$(this).hide();
			});
		
			tabs.each(function() {
				$(this).removeClass("active").css("cursor", "pointer").addClass("inactive");
			});

			$(this).addClass("active").removeClass("inactive onover");
			$(tabsContents.get(tabs.index(this))).css("display") == "none" ? $(tabsContents.get(tabs.index(this))).show() : "";
			event.stopPropagation();
			event.preventDefault();
		});

		$(window).unload(function() {
			$(tabs).unbind();
		});	
	}
})(jQuery);