/*
V1.01 - 23/02/10 AC
- Added a new function SetCurrentTab to define default tab (removed from AddVehicleTab)
*/

function VehicleTabs() {
	this.currentTab = false;
	this.tabList = new Array();
	this.tabActiveTags = new Array();
	this.tabInActiveTags = new Array();
	
	this.SetCurrentTab = SetCurrentTab;
	this.AddVehicleTab = AddVehicleTab;
	this.SelectTab = SelectTab;
	this.SetAllTabEvents = SetAllTabEvents;
	this.SetTabEvents = SetTabEvents;
}

function SetCurrentTab(tabName) {
	this.currentTab = tabName;
}

function AddVehicleTab(tabName, activeTags, inactiveTags) {
	//if (this.currentTab === false) this.currentTab = tabName; (removed 23/02/10 AC)
	this.tabList.push(tabName);
	if (activeTags != '') this.tabActiveTags[tabName] = activeTags.split(',');
	if (inactiveTags != '') this.tabInActiveTags[tabName] = inactiveTags.split(',');
}

function SelectTab(tabName) {
	var i;
	this.currentTab = tabName;
	this.SetAllTabEvents();
	if (typeof(this.tabActiveTags[tabName]) != 'undefined') {
		for (i = 0; i < this.tabActiveTags[tabName].length; i++) {
			this.currentPage.ShowGadgetByTag(this.tabActiveTags[tabName][i]);
		}
	}
	if (typeof(this.tabInActiveTags[tabName]) != 'undefined') {
		for (i = 0; i < this.tabInActiveTags[tabName].length; i++) {
			this.currentPage.HideGadgetByTag(this.tabInActiveTags[tabName][i]);
		}
	}
}

function SetAllTabEvents() {
	var i;
	for (i = 0; i < this.tabList.length; i++) {
		this.SetTabEvents(this.tabList[i], i);
	}
}

function SetTabEvents(tabName, i) {
	var tabObject = document.getElementById("vehicleTab"+tabName+this.gadgetId);
	var tabClass = (tabName == this.currentTab) ? "vehicleTabDark" : "vehicleTabLight";
	if (i > 0) tabClass += " topGap";
	tabObject.className = tabClass;
	thisPointer = this;
	tabObject.onclick = function() {
			thisPointer.SelectTab(tabName);
			}
	tabObject.onmouseover = function() {
			var newClass = "vehicleTabDark";
			if (i > 0) newClass += " topGap";
			this.className = newClass;
			}
	tabObject.onmouseout = function() {
			var lastClass = (tabName == thisPointer.currentTab) ? "vehicleTabDark" : "vehicleTabLight";
			if (i > 0) lastClass += " topGap";
			this.className = lastClass;
			}
}
