var tabs = [];
var links = [];
var _fadetimeouts = [];
function initTabs()
{
	var _loc = "";
	_loc = window.location.href.split("#")[1];
	var in_tab = false;
	var sets = document.getElementsByTagName("ul");
	var _j = 0;
	for (var i = 0; i < sets.length; i++)
	{
		if (sets[i].className.indexOf("tabset") != -1)
		{
			links = sets[i].getElementsByTagName("a");
			for (var j = 0; j < links.length; j++)
			{
				if (links[j].className.indexOf("tab") != -1)
				{
					links[j]._j = _j;
					_j++;
					tabs.push(links[j]);
					links[j].tabs = tabs;
					var c = document.getElementById(links[j].href.substr(links[j].href.indexOf("#") + 1));
					if (c)
					{
						if (!_loc)
						{
							if (links[j].className.indexOf("active") != -1)
							{
								c.style.display = "block";
								c.style.height = "100%";
								in_tab = true;
							}
							else
							{
								c.style.height = "0px";
								c.style.display = "none";
							}
						}
						else
						{
							if (_loc == links[j].href.substr(links[j].href.indexOf("#") + 1))
							{
								if (links[j].className.indexOf("active") == -1)
								{
									links[j].className += " active";
								}
								c.style.display = "block";
								c.style.height = "100%";
								in_tab = true;
							}
							else
							{
								links[j].className = links[j].className.replace("active", "");
								c.style.height = "0px";
								c.style.display = "none";
								
							}
						}
					}
					links[j].onclick = function ()
					{
						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++)
							{
								//try
								//{
									if(_fadetimeouts[i])
									{
										clearTimeout(_fadetimeouts[i]);
									}
								//}
								//catch(e){}
								var tab = document.getElementById(this.tabs[i].href.substr(this.tabs[i].href.indexOf("#") + 1));
								if (tab)
								{
									tab.style.height = "0px";
									tab.style.display = "none";
								}
								this.tabs[i].className = this.tabs[i].className.replace("active", "");
							}
							//try
							//{
								if(typeof delay != "undefined")
									_fadetimeouts[this._j] = setTimeout('_switch(' + this._j + ')',delay);
							//}
							//catch(e){}
							
							this.className += " active";
							c.style.display = "block";
							c.style.height = "100%";
							return false;
						}
					}
				}
				
			}
		}
		
	}
	if (!in_tab)
	{
		if (tabs.length)
		{
			var g = document.getElementById(tabs[0].href.substr(tabs[0].href.indexOf("#") + 1));
			tabs[0].className += " active";
			g.style.display = "block";
			g.style.height = "100%";
		}
	}
}

if (window.addEventListener)
	window.addEventListener("load", initTabs, false);
else if (window.attachEvent)
	window.attachEvent("onload", initTabs);