/**
 * Steuert den onMouseOver/onMouseOut Effekt eines Buttons
 */
function hoverButton(bid, over) {
	bid.className = (over)?"buttonHover":"button";
}

/**
 * Steuert den onClick Effekt eines Buttons
 */
function pressButton(bid, over) {
	bid.className = (over)?"buttonPress":"buttonHover";
}

/**
 * Das TabSet Objekt
 */
function JSTabSet(tabSetName) {
	this.name			= tabSetName;
	this.tabs			= new Array();
	this.addTab			= _addTab;
	this.select			= _select;
	this.disable		= _disable;
	this.getSelected	= _getSelected;
	this.getPosition	=_getPosition;
	
	function _select(tabName) {
		for(i=0; i<this.tabs.length; i++) {
			this.tabs[i].select((this.tabs[i].name==tabName));
		}
	}
	
	function _disable(tabName, on) {
		for(i=0; i<this.tabs.length; i++) {
			if (this.tabs[i].name==tabName) this.tabs[i].disable(on);
		}
	}

	function _getPosition(tab) {
		for(i=0; i<this.tabs.length; i++)
			if (this.tabs[i] == tab) return i;
		
		return false;
	}

	function _getSelected() {
		for(i=0; i<this.tabs.length; i++) {
			if (this.tabs[i].selected==true)
				return this.tabs[i];
		}
		
		return false;
	}

	function _addTab(tab) {
		tab.set = this;
		this.tabs.push(tab);
	}
}

/**
 * Das Tab-Objekt
 */
function JSTab(tabName, tabLabel, tabAction) {
	this.set		= null;
	this.name		= tabName;
	this.label		= tabLabel;
	this.action		= tabAction;
	this.select		= _select;
	this.selected	= false;
	this.disable	= _disable;
	this.disabled	= false;

	this.tempAction	= null;
	
	function _select(on) {
		this.selected	= on;
		pos				= this.set.getPosition(this);

		if (pos == 0) {
			/* Erstes Element */
			elementId	= "left-"+ this.set.name +"-"+ this.name;
			elementSrc	= "left-" +(on?"on":"off")+ ".gif";
		}
		else {
			elementId	= "mid-"+ this.set.name +"-"+ this.name;
			elementSrc	= "mid-"+ (this.set.tabs[pos-1].selected?"on":"off") +"-"+ (on?"on":"off") +".gif";
		}
		document.getElementById(elementId).src = "skins/blueit/tabs/"+ elementSrc;

		if (pos == this.set.tabs.length-1) {
			/* Letztes Element */
			elementId	= "right-"+ this.set.name +"-"+ this.name;
			elementSrc	= "right-" +(on?"on":"off")+ ".gif";
			document.getElementById(elementId).src = "skins/blueit/tabs/"+ elementSrc;
		}
		
		elementId	= "fill-"+ this.set.name +"-"+ this.name;
		elementCls	= "tab"+(on?"On":"Off");
		document.getElementById(elementId).className = elementCls;
		
		this.disable(this.disabled);
	}
	
	function _disable(on) {
		this.disabled	= on;
		
		elementId	= "fill-"+ this.set.name +"-"+ this.name;
		linkId		= "link-"+ this.set.name +"-"+ this.name;
		if (on) {
			document.getElementById(elementId).className = "tabDisabled";
			if (!this.tempAction) {
				this.tempAction	= document.getElementById(linkId).onclick;
				document.getElementById(linkId).onclick = "";
			}
		}
		else {
			document.getElementById(elementId).className = "tab"+(this.selected?"On":"Off");
			if (this.tempAction) {
				document.getElementById(linkId).onclick = this.tempAction;
				this.tempAction = null;
			}
		}
	}
}