// JavaScript Document
GLB.namespace("GLB.common");
GLB.common.swapTab = function(){
	/*
		.version: 1.0
		
		.date:
		20/09/2007
		
		.usage:
		var tabs = new GLB.common.swapTab("tab1", "tab2", "tab3" ... "tabn");			
	*/
	
	var $swap = function(){
		this._container = "";
		this._lastContainer = "";
		this._lastTab = "";
		this._tabs = "";
		this._multiple = false;
		this._containerTabs = arguments;
		//--
	};
	$swap.prototype = {
		init:function(){
			this.hideAllCTabs();
		},
		setMultiple:function(value) {
			this._multiple = value;
		},
		addTab:function(name){
			this._containerTabs.push(name);
		},
		removeTab:function(itemRemove){
			
			if(!isNaN(itemRemove)){
				this._containerTabs.splice(itemRemove, 1);
			}else if(typeof itemRemove === "string"){
				for(var i=0; this._containerTabs.length; i++){
					if(this._containerTabs[i]==itemRemove)this._containerTabs.splice(i, 1);
				}
			}
			
		},
		swap:function(tab, containerTab){
			//alert("tab: "+tab.innerHTML+" containerTab:"+containerTab);
			this._container = document.getElementById(containerTab) || null;
			if(this._container==this._lastContainer && (!this._multiple))return;
			//--
			this.selectTab(tab);
			if  (this._container != null) { 
			this._container.style.display = (this._container.style.display=="none" || this._container.style.display=="")? "block": "none";
			if(this._lastContainer!="" && (!this._multiple))this._lastContainer.style.display = "none";
			//--
			this.onSelectItem(this._container, this._lastContainer);
			this._lastContainer = this._container;
			}
		},
		selectTab:function(tab){
			if(tab==undefined || tab=="")return;
			
			if(!this._multiple){
				try{
					if(this._lastTab.className.indexOf("on")!=-1)
						this._lastTab.className = this._lastTab.className.split("on").join("off");
					else
						this._lastTab.className += " off";
				}catch(e){};
			}
			//--
			if(tab.className.indexOf("off")!=-1)
				tab.className = tab.className.split("off").join("on");
			else if(tab.className.indexOf("on")!=-1)
				tab.className = tab.className.split("on").join("off");
			else
				tab.className += " on";
			//--	
			tab.blur();
			//--
			this.onSelectTab(tab, this._lastTab);	
			this._lastTab = tab;
		},
		hideAllCTabs:function(){
			for(i=0; i<this._containerTabs.length; i++){
				var ct = document.getElementById(this._containerTabs[i]);
				if(!ct)continue;
				ct.style.display = "none";
			}
		},
		showAllCTabs:function(){
			for(i=0; i<this._containerTabs.length; i++){
				var ct = document.getElementById(this._containerTabs[i]);
				if(!ct)continue;
				ct.style.display = "block";
			}
		},
		onSelectItem:function()	{
			//Evento não deletar e nem escrever aqui!!!
		},
		onSelectTab:function()	{
			//Evento não deletar e nem escrever aqui!!!
		}
	}
	
	return $swap;
}();
