/**
 * SetaTab
 * -------------------------
 * Copyright 2005 - Setasign - Jan Slabon
 * http://www.setasign.de
 */
function SetaTab(e) {
	this.e = e;
	e.SetaTab = this;
	this.classAtt = document.all && !window.opera ? 'className' : 'class';
	this.buttons = [];
	this.contents = [];
	this.tabBar = null;
	
	this.initElements = function() {
		var childs = this.e.childNodes;
		var l = childs.length;
		var cN = '';
		
		for (var i = 0; i < l; i++) {
			if (childs[i].nodeType != 1)
				continue;
							
			cN = childs[i].getAttribute(this.classAtt);
			if (cN == 'SetaTabBar') {
				this.tabBar = childs[i];
			} else if(cN == 'SetaTabContent') {
				this.contents[this.contents.length] = childs[i];
			} 
		}
	}
	
	this.initButtons = function() {
	    var childs = this.tabBar.childNodes, l = childs.length, n;
		
		for (var i = 0; i < l; i++) {
			if (childs[i].nodeType == 1 && (childs[i].getAttribute(this.classAtt) == 'SetaTab' || childs[i].getAttribute(this.classAtt) == 'SetaTabActive')) {
				n = this.buttons.length;
				this.buttons[n] = childs[i];
				this.buttons[n].content = this.contents[n];
				this.buttons[n].SetaTab = this;
				if (typeof this.buttons[n].onclick == 'function')
					this.buttons[n]._onclick = this.buttons[n].onclick;
				this.buttons[n].onclick = function() {
				    if (!this.SetaTab.isActive(this)) {
					    this.SetaTab.setActive(this);
						if (typeof this._onclick == 'function')
							this._onclick();
					}
					if (this.blur)
					    this.blur();
					return false;
				}
			}
		}
	}
	
	this.setActive = function(b) {
		var active;
		for (var i = 0; i < this.buttons.length; i++) {
		    this.buttons[i].className = (active = this.buttons[i] === b) ? 'SetaTabActive' : 'SetaTab';
			this.contents[i].style.display = active ? 'block' : 'none';
		}	
	}
	
	this.isActive = function(b) {
		return b.className == 'SetaTabActive';
	}
	
	this.init = function(setActive) {
		this.buttons = [];
		this.contents = [];
		this.tabBar = null;
	
		this.initElements();
		this.initButtons();
		
		if (typeof setActive == 'undefined')
		    this.setActive(this.buttons[0]);
		else 
		    this.setActive(this.buttons[setActive]);
	}
	
	this.init();
}
	
