/*
 * Tabs	v1.0
 * 
 * COPYRIGHT: (c) 2004 Cezary Tomczak
 * LINK:	  http://gosu.pl
 */

function Tabs(id_tabs, id_tabs_data) {
	this.id_tabs = id_tabs;
	this.id_tabs_data =	id_tabs_data;
	this.active	= null;
	this.tabs =	0;
}
Tabs.prototype.init	= function() {
	if (!document.getElementById(this.id_tabs))	{
		alert("Element '"+this.id_tabs+"' does not exist. Cannot initialize	Tabs.");
		return;
	}
	if (!document.getElementById(this.id_tabs_data)) {
		alert("Element '"+this.id_tabs_data+"' does	not	exist. Cannot initialize Tabs.");
		return;
	}
	if (document.getElementById(this.id_tabs).childNodes
			&& document.getElementById(this.id_tabs_data).childNodes) {
		this.parseTabs(document.getElementById(this.id_tabs).childNodes);
		this.parseTabsData(document.getElementById(this.id_tabs_data).childNodes);
	}
	if (this.tabs >	0) {
		this.click(0);
	}
}
Tabs.prototype.parseTabs = function(nodes) {
	var	self = this;
	for	(var i = 0;	i <	nodes.length; i++) {
		if (nodes[i].nodeType != 1)	{
			continue;
		}
		nodes[i].id	= this.id_tabs + "-" + this.tabs;
		eval('nodes[i].onclick = function()	{ self.click("'+this.tabs+'"); }');
		this.tabs++;
	}
}
Tabs.prototype.parseTabsData = function(nodes) {
	var	cnt	= 0;
	for	(var i = 0;	i <	nodes.length; i++) {
		if (nodes[i].nodeType != 1)	{
			continue;
		}
		nodes[i].id	= this.id_tabs_data	+ "-" +	cnt;
		cnt++;
	}
}
Tabs.prototype.click = function(n) {
	if (!document.getElementById(this.id_tabs +	"-"	+ n)
			|| !document.getElementById(this.id_tabs_data +	"-"	+ n)) {
		return;
	}
	if (this.active	!= null) {
		document.getElementById(this.id_tabs + "-" + this.active).className	= "";
		document.getElementById(this.id_tabs_data +	"-"	+ this.active).style.display = "none";
	}
	document.getElementById(this.id_tabs + "-" + n).className =	"active";
	document.getElementById(this.id_tabs_data +	"-"	+ n).style.display = "block";
	this.active	= n;
}