function tabsController() {
	this.controller = false;
	this.contentDivs = new Array;
	
	this.setController = TC_setController;
	this.setContentDivs = TC_setContentDivs;
	this.setActiveTabIndex = TC_setActiveTabIndex;
	this.initialize = TC_initialize;
	this.showDiv = TC_showDiv;
	this.setSimpleController = TC_setSimpleController;
	this.disableBlur = TC_disableBlur;
	this.checkAnchors = TC_checkAnchors;
}


function TC_setController(controllElement) {
	this.controller = controllElement;
}

function TC_setContentDivs(divs) {
	this.contentDivs = TC_setContentDivs.arguments;
}

function TC_initialize() {
	/*
	 * Hide all Divs, except the first one
	 */
	 for(var i=0; i < this.contentDivs.length; i++) {
	 	var div = document.getElementById(this.contentDivs[i]);
	 	if(div && i > 0) {
	 		div.style.display = 'none';
	 	}
	 }
	 	 
	 /*
	  * Create the Tab-Controller
	  */
 	 var rootElement = document.getElementById(this.controller);
 	 if(rootElement) {
		var as = rootElement.getElementsByTagName('a');
		for(var j=0; j < as.length; j++) {
			var a = as[j];
			if(a.className != 'notab') {
				a.setAttribute('control', this.contentDivs[j]);
				a.setAttribute('number', j);
				
				var owner = this;
				
				a.onclick = function() {
					owner.showDiv(this.getAttribute('control'));
					owner.setActiveTabIndex(this.getAttribute('number'));
					
					// Anpassen des InnerFrames
					if(typeof(resize_iframe) == 'function') {
						resize_iframe();
					}
					
					return false;
				};
			}	
			this.disableBlur(a);
		}
 	 }
 	 
 	 this.checkAnchors();
}

function TC_showDiv(divId) {
	
	/*
	 * Hide all Divs first
	 */
	 for(var i=0; i < this.contentDivs.length; i++) {
	 	var div = document.getElementById(this.contentDivs[i]);
	 	if(div) {
	 		div.style.display = 'none';
	 	}
	 }
	
	var div = document.getElementById(divId);
	if(div) {
		div.style.display = 'block';
	}
}

function TC_setActiveTabIndex(index) {
	var controller = document.getElementById(this.controller);
	if(controller) {
 		var lis = controller.getElementsByTagName('li');
		for(var i=0; i < lis.length; i++) {
			var li = lis[i];
			if(i == index) {
				li.className = 'active';
			} else {
				li.className = '';
		 	}
		}
	}
}

function TC_setSimpleController(id, contentId, index) {
	var rootElement = document.getElementById(id);
	if(rootElement) {
		var as = rootElement.getElementsByTagName('a');
		for(var j=0; j < as.length; j++) {
			var a = as[j];
			var owner = this;
						
			a.onclick = function() {
				owner.showDiv(contentId);
				owner.setActiveTabIndex(index);
				return false;
			};
			
			this.disableBlur(a);

		}
	}
}

function TC_disableBlur(e) {
	e.onfocus = function() {
		this.blur();
	};
}

function TC_checkAnchors() {
	var anchor = window.location.hash;
	if(anchor) {
		anchor = anchor.substr(1);
		for(var i=0; i < this.contentDivs.length; i++) {
			var actDiv = this.contentDivs[i];
			if(actDiv == anchor) {				
				this.showDiv(actDiv);
				this.setActiveTabIndex(i);
				break;
			}
		}
	}
}
