var exceedTabs = {
	tabSetArray: 	new Array(),
	tabs:			null,
	classOn: 		"tabs_on",
	classOff: 		"tabs_off",
	lastTab:		"#hero-image-8",
	seconds: 6,
	addTabs: function (tabsContainer, panelsContainer) {
		this.tabContainer = document.getElementById(tabsContainer);
		this.panelContainer = document.getElementById(panelsContainer);

		// Retrieve the tabs for jumping to a specific image.
		this.tabs = this.tabContainer.getElementsByTagName("a");
		for (x in this.tabs) {
			var current = this.tabs[x];
			if (typeof(current.hash) != "undefined") {
				current.onclick = function() {
					return exceedTabs.switchTab(this, true);
				};
				
				// Add the tab's hashcode to the tabSetArray.
				this.tabSetArray.push(current.hash);
				if (current.className == this.classOn) {
					this.defaulttab = current;
				}
			}
		}

		// If the URL sets the active tab, change the default tab.
		if (window.location.hash != "") {
			for (x in this.tabs) {
				var current = this.tabs[x];
				if (typeof(current.hash) != "undefined") {
					if (current.hash == window.location.hash) {
						this.defaulttab = current;
					}
				}
			}
		}
		this.switchTab(this.defaulttab, false);
		this.interval = window.setInterval('exceedTabs.nextTab()', this.seconds * 1000);
	},
	switchTab: function (element, pause) {
		var tabId = element.hash.substring(1);
		var activeTab = document.getElementById(tabId);
		for (x in this.tabSetArray) {
			var href = this.tabSetArray[x].substring(1);
			var dataElement = document.getElementById(href);
			if (dataElement) {
				if ((dataElement.style.display != "none") && (dataElement != activeTab)) {
					dataElement.style.display = 'none';
				}
			}
		}

		// Turn all tabs off.
		//var tabs = this.tabContainer.getElementsByTagName("a")
		for (x in this.tabs) {
			var current = this.tabs[x];
			if (current.className != this.classOff) {
				current.className = this.classOff;
			}
		}
		
		// Turn the chosen tab on.
		activeTab.style.display = 'block';
		element.className = this.classOn;
		if (pause) {
			this.stop();
		}
		
		return false;
	},
	nextTab: function () {	
		// Advance to the next tab.
		var next = 0;
		for (x in this.tabs) {
			var current = this.tabs[x];
			if (current.className == this.classOn) {
				var tabId = current.hash;
				if (tabId != this.lastTab) {
					next = tabId.substring(tabId.length - 1);
				}		
			}
		}
		this.switchTab(this.tabs[next], false);
	},
	start: function () {
		if (this.interval) {
			return;
		}
		this.interval = setInterval('exceedTabs.nextTab()', this.seconds * 1000);
		if (this.button) {
			this.button.src = this.pauseimg;
		}
	},
	stop: function () {
		if (0 == this.interval) {
			return;
		}
		
		clearInterval(this.interval);
		this.interval = null;
		if (this.button) {
			this.button.src = this.playimg;
		}
	},	  
	pausePlay: function () {
		if ((null != this.interval) && (0 != this.interval)) {
			this.stop();
		}
		else {
			this.start();
		}	
	}
};