var TabControl = function(containerID) {
	this.containerID = containerID;
	
	this._tabContainer = null;
	this._tabs = [];
}

TabControl.prototype.get_tabContainer = function() {
	var outerContainer = document.getElementById(this.containerID);
	
	if(this._tabContainer == null && outerContainer != null) {
		this._tabContainer = document.createElement('ul');
		this._tabContainer.className = 'tab-container';
		
		outerContainer.appendChild(this._tabContainer);
		
	}
	
	return this._tabContainer;
}

TabControl.prototype.get_tabs = function() {
	return this._tabs;
}

TabControl.prototype.addTab = function(text, isActive, onClick) {
	var tab = null;
	var container = this.get_tabContainer();
	
	if(container) {
		tab = document.createElement('li');
		
		tab.className = 'tab-heading';
		
		if(isActive) {
			tab.className += ' tab-heading-active';
		} else {
			tab.className += ' tab-heading-inactive';
		}
		
		tab.innerHTML = text;
		
		if(typeof(onClick) != 'undefined') {
			if(tab.attachEvent) {
				tab.attachEvent('onclick', onClick);
			} else if (tab.addEventListener) {
				tab.addEventListener('click', onClick, false);
			}
		}
		
		container.appendChild(tab);
		
		this._tabs.push(tab);
	}
}

TabControl.prototype.setActive = function(tabIndex) {
	if(tabIndex >= 0 && tabIndex < this._tabs.length) {
		for(var i = 0; i < this._tabs.length; i++) {
			this._tabs[i].className = 'tab-heading' + 
				(tabIndex == i ? ' tab-heading-active' : ' tab-heading-inactive');
		}
	}
}



