var exceedTabs = {
	tabSetArray: 	new Array(),
	classOn: 		"tabs_on",
	classOff: 		"tabs_off",
	seconds: 6,
	addTabs: function (tabsContainer, panelsContainer) {
		tabs = $(tabsContainer).getElementsByTagName("a");
		this.tabContainer = $(tabsContainer);
		this.panelContainer = $(panelsContainer);
		for (x in tabs) {
			if (typeof(tabs[x].hash) != "undefined") {
				tabs[x].onclick =  function() {return exceedTabs.switchTab(this, true)} ;
				this.tabSetArray.push(tabs[x].hash.substring(1));
				if (tabs[x].className == this.classOn) { this.defaulttab = tabs[x] }
			} else {}
		}
		this.defaulttab = tabs[0]
		for (x in tabs) {
			if (typeof(tabs[x].hash) != "undefined") {
				if (tabs[x].hash.substring(1) == window.location.hash.substring(1)) {
					this.defaulttab = tabs[x]
				} else {}
			}
		}
		this.switchTab(this.defaulttab, false);
		this.interval = window.setInterval(this.nextTab.bind(this), this.seconds * 1000);
	},
	switchTab: function (element, pause) {
		for (x in this.tabSetArray) {
			dataElement = document.getElementById(this.tabSetArray[x]);
			if (dataElement) {
				if ((dataElement.style.display != "none") && (dataElement != $(element.hash.substring(1)))) {
					this.fadeOut = new Effect.Fade(dataElement, {duration: 1});  
				} else {}
			} else {}		
		}
		tabs = this.tabContainer.getElementsByTagName("a")
		for (x in tabs) {
			if (tabs[x].className != this.classOff) {
					tabs[x].className = this.classOff;
				} else {}
		}
		this.fadeIn = new Effect.Appear($(element.hash.substring(1)), {duration: 1});
		element.className = this.classOn;
		if (pause) this.stop();
		return false;
	},
	nextTab: function () {	
		tabs = this.tabContainer.getElementsByTagName("a");
		next = 0;
		for (x in tabs) {
			if (tabs[x].className == this.classOn) {
				if (parseInt(x) >= tabs.length-1) {
					next = 0;
				} else {
					next = parseInt(x)+1;
				}		
			}
		}
		this.switchTab(tabs[next], false);
	},
	start: function () {
		if (this.interval) return;
		this.interval = setInterval(this.nextTab.bind(this), this.seconds * 1000);
		if (this.button) this.button.src = this.pauseimg;
	},
	stop: function () {
		if (!this.interval) return;
		clearInterval(this.interval);
		this.interval = null;
		if (this.button) this.button.src = this.playimg;
	},	  
	pausePlay: function () {
		if (this.interval) {
			this.stop();
		} else {
			this.start();
		}	
	}
};
