// JavaScript Document

var tab_items, tab_contents;
function initListTabs()
{
	// add the click events to the tab links
	tabs = css.getElementsByClass(document, "tabs", "UL");
	
	tabs = tabs[0];
	if (typeof(tabs) == "undefined") return;
	
	tab_items = tabs.getElementsByTagName("LI");
	for (var i=0; i<tab_items.length; i++)
	{
		var a = tab_items[i].getElementsByTagName("A")[0];
		
		if (typeof(a) != "undefined")
		{
			a.onclick = function() {
				var pieces = this.href.split("#");
				setActive(pieces[1]);
			}
		}
	}

	
	// set the active tab and hide the others. If the ahsh is set, use that, otherwise grab the first item from the list
	var hash = document.location.hash;
	if (hash != "")
	{
		var default_tab = hash.replace("#", "");
	}
	else
	{
		var default_tab = css.getElementsByClass(tabs, "default", "LI");
		default_tab = default_tab[0].id.replace("item_", "");
	}
	setActive(default_tab);
}
addOnLoad(initListTabs);

function setActive(tab)
{
	resetTabs();

	// now we have the default tab, set it
	if (document.getElementById("item_" + tab))
	{
		var tab_item = document.getElementById("item_" + tab);
		css.addClassToElement(tab_item, "item_active");
	}

	if (document.getElementById("content_" + tab))
	{
		var tab_content = document.getElementById("content_" + tab);
		if (typeof(tab_content) != "undefined") css.removeClassFromElement(tab_content, "hidden");
	}
}

function resetTabs()
{
	tab_contents = css.getElementsByClass(document, "tab_content", "DIV");
	for (var i=0; i<tab_contents.length; i++)
	{
		css.addClassToElement(tab_contents[i], "hidden");
	}
	
	for (var i=0; i<tab_items.length; i++)
	{
		css.removeClassFromElement(tab_items[i], "item_active");
	}
}

