﻿function Tabs(){
	this.tabItems = [];
	this.tabIndex = 0;
}

Tabs.prototype = {
	
	AddTabItem: function(labelElement, containerElement){
		if(!labelElement) return;
		
		var tab = new TabItem();
		this.tabIndex++;
		tab.Id = this.tabIndex;
		tab.SetLabel(labelElement);
		tab.SetContainer(containerElement);
		
		var _Tabs = this;
		
		Common.Event.add(labelElement, 'click', function(){
			_Tabs.OnTabLabelClick(this);
		});
		
		this.tabItems.push(tab);
	},
	
	OnTabLabelClick: function(refElement){
		var id = refElement.Tab.Id;
		
		menu(this.tabItems, function(tab){
			if(tab.Id === id){
				tab.SetSelected(true);
			}
			else{
				tab.SetSelected(false);
			}
		});
	}
	
}


function TabItem(){
	this.SELECTED = 'selected';
	this.DISABLED = 'tab-disabled';

	this.Id = null;
	this.labelElement = null;
	this.containerElement = null;
}

TabItem.prototype = {

	SetLabel: function(labelElement){
		labelElement.Tab = this;
		this.labelElement = labelElement;
	},
	
	SetContainer: function(containerElement){
		this.containerElement = containerElement;
	},
	
	/**
	 * Активирует/деактивирует вкладку
	 */
	SetSelected: function(isSelected){
		if(isSelected){
			Common.Class.add(this.labelElement, this.SELECTED);
			Common.Class.remove(this.containerElement, this.DISABLED);
			//this.containerElement.style.visibility = 'visible';
		}
		else{
			Common.Class.remove(this.labelElement, this.SELECTED);
			Common.Class.add(this.containerElement, this.DISABLED);		
			//this.containerElement.style.visibility = 'hidden';
			
			//this.containerElement.style.display = 'none';
		}
	}

}
