/*
 * 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) {
			/*tabs[t].scrollTop = 0;
			tabs[t].scrollLeft = 0;*/
			var tab = document.getElementById(tabs[t]);	
			tab.className = hiddenClassName;
			tab.scrollTop = 0;
			tab = null;
		}
	}

	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]);
	}

	this.alertTabs = function () {
		var message = '';
		for(t in tabs) {
			message=message+t+' '+tabs[t]+'\n';
		}
		alert(message);
	}
	
}
