/*
 * jQuery Tiny Tabs plug-in 1.0.0
 *
 * Copyright (c) 2009 Nicolás Azuara Hernández
 * http://code.google.com/p/tinytabs/
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 */
jQuery.fn.tinytabs = function(options){
	var id = "#" + this.attr("id");
	options = $.extend({
		selected: id + ">div:first",
		speed: "normal",
		effect: "none"	
	}, options);
	var target, old;
	var re = /([_\-\w]+$)/i;
	var divId = $(options.selected).attr("id");	
	$(options.selected).addClass("current-tab");
	$(id + ">div:not(.current-tab)").hide();	
	$(id + " ul li a").each(function(){
		target = re.exec(this.href)[1];
		if(target==divId){
			$(this).addClass("current");
			return false;
		};
	});	
	$(id + ">ul>li>a").click(function(e){
		e.preventDefault();
		$(id + ">ul>li>a").removeClass("current");
		$(this).addClass("current");
		$(this).blur();
		target = $("#" + re.exec(this.href)[1]);
		old = $(id + ">div");
		old.removeClass("current-tab");
		
		switch(options.effect){
		case "fade":
			old.fadeOut(options.speed);
			target.fadeIn(options.speed);
			break;
		case "slide":
			old.slideUp(options.speed);
			target.slideDown(options.speed);
			break;
		default : 
			old.hide();
			target.show();
		};
		target.addClass("current-tab");
	});
};
