/*
 * 
 * jquery.isiat.tabs.js - generator dynamic tabs elements
 * Version 0.0.1
 * @requires jQuery v1.2.X
 * 
 * Copyright (c) 2009 Isiat
 * Examples and docs at: http://.isiat.com
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 * 
 */
/**
 * @description  generator dynamic collapsable elements
 * @param {Object} "#vocab_nav"
 * 
 * @type jQuery
 *
 * @name itabs.
 * 
 * @cat plugins/dictionary
 * 
 * @author Queli Coto / quelicm@gmail.com
 */

(function($){
    jQuery.fn.itabs = function(indice){
		var e = this;
		//add select first element
		$(e).find(indice+":first")
			.attr("id","itabsSelect");
		//save previus element
		var elementPosition = $(e).find(indice+":first").prev();
		//create elemente list
		var listItem = '';
		var list = $('<ol class="itabs clearfix"></ol>');
		$(e).find(indice).each(function (i) {
		   var o = this;
		   var oID='';
		   if(i==0){
		   	   oID='id="iTabSelect"';
		   }
		   listItem=  listItem + '<li ' + oID + ' class="itemTab' + i + '">'+$(o).text()+'</li>';
		   $(o).next().addClass('itemTab'+ i +' eItab');
		   //hide all elements
		   $(o).hide();
		   $(o).next().hide();
		   $(o).next('.itemTab0').show();
      	});
		//transform list in dom elemente jquery
		$(list).append(listItem);
		// add list markup html
		$(elementPosition).append().after(list); 
		//add click event
		$(list).children().each(function (i) {
			 var o = this;
			  $(o).click(function () { 
			     //alert ( $(this).text() ); 
				 var eClass =  $(this).attr("class");
				 $(list).children().each(function (j) {
				 	var oi = this;
			  		$(oi).removeAttr("id");
				 });
				 $(this).attr("id",'iTabSelect');
				 //hide all elementes
				 $('.eItab').hide();
				 $('.'+eClass).show();
			  });
			   $(o).hover(
		      function () {
			  	if( $(this).attr("id") != 'iTabSelect')
		        	$(this).attr("id",'iTabhover')
		      }, 
		      function () {
			  	if( $(this).attr("id") != 'iTabSelect')
		       		$(this).removeAttr("id")
		      }
		    );
      	});
	};
})(jQuery);

//sample uso
/*
 $(function(){
        $('dl dt').csdtCollapsable(); // next element dt, dd, will be collapse
});

*/