var tabs = [];
var current = 0;
var timer;
var autoplay = true;
var duration = 4000;
function initTabs()
{
	var sets = document.getElementsByTagName("div");
	for (var i = 0; i < sets.length; i++)
	{
		if (sets[i].className.indexOf("tabset") != -1)
		{
			var links = sets[i].getElementsByTagName("a");
			links.index = 0;
			for (var j = 0; j < links.length; j++)
			{
				if (links[j].className.indexOf("tab") != -1)
				{
					tabs.push(links[j]);
					links[j].tabs = tabs;
					var c = document.getElementById(links[j].href.substr(links[j].href.indexOf("#") + 1));

					//reset all tabs on start
					if (c) 
						if (links[j].className.indexOf("active") != -1) 
							c.style.position = "static";
						else {
							c.style.position = "absolute";
							c.style.left = "-9999px";
						}

					links[j].index = j;
					links[j].onclick = function (el)
					{
						clearTimeout(timer);
						current = this.index;
						var c = document.getElementById(this.href.substr(this.href.indexOf("#") + 1));
						if (c)
						{
							//reset all tabs before change
							for (var i = 0; i < this.tabs.length; i++)
							{
								document.getElementById(this.tabs[i].href.substr(this.tabs[i].href.indexOf("#") + 1)).style.position = "absolute";
								document.getElementById(this.tabs[i].href.substr(this.tabs[i].href.indexOf("#") + 1)).style.left = "-9999px";
								this.tabs[i].className = this.tabs[i].className.replace("active", "");
							}
							this.className += " active";
							c.style.position = "static";
							clearTimeout(timer);
							return false;
						}
					}
				}
			}
			timer = setTimeout('tabChanger()', duration);
		}
	}
}
function tabChanger()
{
	if(autoplay)
	{
		if(++current >= tabs.length)
		{
			current = 0;
		}
		var c = document.getElementById(tabs[current].href.substr(tabs[current].href.indexOf("#") + 1));
		if (c)
		{
			for (var i = 0; i < tabs.length; i++)
			{
				document.getElementById(this.tabs[i].href.substr(this.tabs[i].href.indexOf("#") + 1)).style.position = "absolute";
				document.getElementById(this.tabs[i].href.substr(this.tabs[i].href.indexOf("#") + 1)).style.left = "-9999px";
				tabs[i].className = tabs[i].className.replace("active", "");
			}
			
				
			tabs[current].className += " active";
			c.style.position = "static";
		}
		
		timer = setTimeout('tabChanger()', duration);
	}
}

if (window.addEventListener) 
	window.addEventListener("load", initTabs, false);
else if (window.attachEvent) 
	window.attachEvent("onload", initTabs);
	

//<![CDATA[
if (typeof sIFR == "function") {
	sIFR.replaceElement(named({
		sSelector: ".tab-placeholder .info h1 em",
		sFlashSrc: "wp-content/themes/bachfestivalsociety/media/sifr.swf",
		sBgColor:"#FFFFFF",
		sWmode:"transparent",
		sColor: "#CDC8C7",
		sLinkColor: "#CDC8C7",
		wmode: "transparent",
		sHoverColor: "#CDC8C7",
		nPaddingTop:0, nPaddingBottom:0, 
		sFlashVars:"textalign=left&offsetTop=0"
	}));
}
//]]>