/*
 * Manages Tab Display Functionality
 */
 
function TabManager(titleBarObj, hiddenClassName, visibleClassName, EventManager) {
	var tabs = new Array();
	var MySelf = this;
	var lastTab;
	var currentTab;

	this.getFirstTab = function() {
		for(var t in tabs) {
			return t;
		}
	}
	

	this.addTab = function(tabName, tabObject) {
		tabs[tabName] = tabObject;
	}

	this.removeTab = function(tabName) {
		MySelf.hideAllTabs();
		if(tabs[tabName]) {
			delete tabs[tabName];
		}
		MySelf.showLastTab();
	}
	
	this.hideAllTabs = function() {
		for(var t in tabs) {
			document.getElementById(tabs[t]).className = hiddenClassName;
			tabs[t].scrollTop = 0;
		}
	}

	this.getLastTab = function() {
		return lastTab;
	}

	this.showTab = function(tabName) {
//		if(tabName == currentTab) { return true; }
		MySelf.hideAllTabs();
		if(tabs[tabName]) {
			document.getElementById(tabs[tabName]).className = visibleClassName;
			document.getElementById(titleBarObj).innerHTML =new String(tabName).toUpperCase();
			lastTab= currentTab;
			currentTab = tabName;
		}
	}

	this.showLastTab = function() {
		if(!tabs[lastTab]) {
			lastTab = MySelf.getFirstTab();
		}
		EventManager.triggerEvent('changetab', lastTab);
	}	

	this.checkTab = function(tName) {
		return (tabs[tName]);
	}
	
}
