/**
 * Javascript Tab system
 * Written by Lucas van Dijk (http://www.return1.net)
 * 
 * You'll need script.aculo.us for this script to work
 */

function TabControl(element)
{
	if(typeof element != "string")
	{
		throw Error('element must me an ID');
	}
	
	this.element = element;
	this.current_tab = 0;
	this.OnOpenTab = function(index, content) { }
	
	this.tabs = $$('#' + element + ' ul.tabs li');
	this.content = $$('#' + element + ' div.tab-content');
	
	this.init_tabs();
	this.init_content();
}

TabControl.prototype.init_tabs = function()
{
	for(var i = 0; i < this.tabs.length; i++)
	{
		this.tabs[i].onclick = this.open_tab.bindAsEventListener(this, i);
	}
	
	this.tabs[this.current_tab].className = "active-tab";
}

TabControl.prototype.init_content = function()
{
	for(var i = 0; i < this.content.length; i++)
	{
		this.content[i].style.display = "none";
	}
	
	this.open_tab(null, this.current_tab);
}

TabControl.prototype.open_tab = function(event, index)
{
	this.tabs[this.current_tab].className = '';
	this.tabs[index].className = "active-tab";
	
	this.content[this.current_tab].style.display = "none";
	this.content[index].style.display = "block";
	
	this.current_tab = index;
	
	this.OnOpenTab(index, this.content[index]);
}
	
	
	
