//Clase jsMenuTabBar

function jsMenuTabBar(id, tabs)
{
	this.mb_id = id;
	
	if(tabs){
		this.tabs = tabs;
	}
	else{
		this.tabs = new Array();
	}
	
	//this.rows = new Array();
	
	this.items = new Array();
	
	
	this._current_tab_index = 0;
	
	
	try{
	
		var mb_bar = document.getElementById(this.mb_id);
		
		mb_rows = mb_bar.childNodes;
		//var index_row = 0;
		var index_item = 0;
		
		for (i=0; i < mb_rows.length; i++)
		{
			var mb_row = mb_rows[i];
			if(mb_row.tagName == 'UL')
			{
				//this.rows[index_row] = mb_row;
				//index_row = index_row + 1;
				
				mb_items = mb_row.childNodes;
				for(j=0; j < mb_items.length; j++)
				{
					var mb_item = mb_items[j];
					if(mb_item.tagName == 'LI')
					{
						this.items[index_item] = mb_item;
						index_item = index_item + 1;
					}
				}
			}
		}
	
	}
	catch(e)
	{
		alert(e);
	}
}

jsMenuTabBar.prototype.setStartSelectedItem = function(index) {
	this._current_tab_index = index;
}

jsMenuTabBar.prototype.selectItem = function(index) {
	try{
		//alert(index);
		
		if(this._current_tab_index != index)
		{
			bar = document.getElementById(this.mb_id);
			
			tab =  this.tabs[index];
			this.items[index].innerHTML = tab.content.selected;
			
			row = this.items[index].parentNode;
			
			var selected_row_id = 0;
			var last_row_id = 0;
			var index_last_row = 0;
			for(j=0; j < bar.childNodes.length; j++)
			{
				var bar_row = bar.childNodes[j];
				if(bar_row.tagName == 'UL')
				{
					index_last_row = j;
					if(row.className == bar_row.className)
					{
						selected_row_id = row.className;
					}
				}
			}
			
			last_row_id =bar.childNodes[index_last_row].className;
			//row.className = last_row_id;
			bar.childNodes[index_last_row].className = selected_row_id;
			
			
			
			bar.appendChild(row);
			row.className = last_row_id;
			//alert("Deseleccionar el item anterior");
			tab =  this.tabs[this._current_tab_index];
			this.items[this._current_tab_index].innerHTML = tab.content.unselected;
			
			this._current_tab_index = index;
		}
		
		
	}
	catch(e)
	{
		alert(e + ", Tab index: " + index);
	}
}

jsMenuTabBar.prototype.selectNexItem = function() {
	
	if(this.currentTabIndex < (this.idTabsOff.length -1))
	{
		this.selectItem(this.currentTabIndex + 1);
	}
	else
	{
		this.selectTab(0);
	}
}

