/*====== Alle funktionen für die Tabs in den Boxen ======*/

var tabBoxes = {};


/* initialisiert die Tabboxen */
function initTabBoxes() { 

	var tabrows = $$('DIV.boxtabs');
	var currentBox;
	var tablist;
	var rememberedTab;
    
    
    
	for (var i=0; i<tabrows.length; i++) {
		currentBox = $(tabrows[i].parentNode);
		
		currentBox.myTabList = tabrows[i].firstDescendant().childElements();
		currentBox.myContents = tabrows[i].next('.boxcenter').childElements();
		currentBox.myID = '';
		currentBox.myCurrentTab = 0;
			
		for (var j=0;  j<currentBox.myTabList.length; j++) {
			currentBox.myTabList[j].myBox = currentBox;
			currentBox.myTabList[j].myTabNum = j;
			currentBox.myTabList[j].onmouseover = function () {setTab(this.myBox, this.myTabNum)};
			
			if (currentBox.myTabList[j].className == 'activeBoxTab') {
				currentBox.myCurrentTab = j;
			}
		}
		
		currentBox.myContents.each(function(elem){elem.setStyle({'display':'none'})});
		setTab(currentBox,currentBox.myCurrentTab);
	}
}


/* aktiviert einen Tab */
function setTab (box, tabNum) {
	var displayValue, bottomLinkValue;
	var tabClassName;
    	
	for (var i=0; i<box.myTabList.length; i++) {		
        

		// Der Tab ist aktiv (letzter Tab hat zusätzlichen style "lastTab")
		if (i==tabNum) { 
            tabClassName = 'activeBoxTab' + i;
        }
		// Der Tab ist links vom aktiven Tab (Schatten!)
		else if (i==tabNum-1) {
            tabClassName = 'activeBoxTab';
        }		
		// Der Tab ist rechts vom aktiven Tab (Schatten!)
		else if (i==tabNum+1) {
            tabClassName = 'activeBoxTab';
        }
		// Der Tab ist inaktive und kein direkter Nachbar des aktiven Tabs
		else {
            tabClassName = 'activeBoxTab';
        }
		
		box.myTabList[i].className = tabClassName;
		
		if (box.myContents[i]) {
			displayValue = (i==tabNum) ? 'block' : 'none';	
            if(i==tabNum){ 
              if(typeof(bottomlink) != "undefined"){
                bottomLinkValue = bottomlink[i]; 
              }
         
            }
			box.myContents[i].setStyle({'display': displayValue});
            
		}
	}
    
    if(document.getElementById('bottomlinkhref')){
      document.getElementById('bottomlinkhref').href = bottomLinkValue;
    }
    
}


registerOnLoadFunction (initTabBoxes);
