function Tab(domRoot) {
//*
  var search, i, n, search2;
  
  this.domRoot = domRoot;
  this.header = domRoot.getElementsByTagName("h2")[0];
  this.content = domRoot.getElementsByTagName("p")[0];
  
  this.show = function() {
    this.domRoot.style.display = "block";
    this.linkedLi.setAttribute("class", "active");
  }
  this.hide = function() {
    this.domRoot.style.display = "none";
    this.linkedLi.removeAttribute("class");
  }
  this.header.style.display="none";
  search=this.content.parentNode.getElementsByTagName("table");
  for(n=0; n<search.length;n++) {
    search2 = search[n].getElementsByTagName("tr");
    for(i=0; i<search2.length; i=i+2) {
      search2[i].setAttribute("class", "odd");
    }
  }
//*/
}


function TabRoot(domRoot) {
//*
  var i, search, tmpLi, tmpA, tmpText;
  this.domRoot = domRoot;
  this.tabs = new Array();
  
  /// Suchen der Tabs
  search = domRoot.getElementsByTagName("div");
  for(i=0; i<search.length; i++) {
    if (search[i].getAttribute("class") == "tabMain content") { this.tabs.push(new Tab(search[i])); }
  }
  for(i=0; i<this.tabs.length; i++) {
    this.tabs[i].domRoot.tabRoot = this;
  }
  
  /// Erstellen des "Inahltsverzeichnis" (toc=Table of Contents)
  this.toc=document.createElement("ul");
  this.toc.setAttribute("class", "tabs");
  this.domRoot.appendChild(this.toc);

  for(i=0; i<this.tabs.length; i++) {
    ///Erstellen
    tmpLi = document.createElement("li");
    this.tabs[i].linkedLi = tmpLi;
    
    tmpA = document.createElement("a");
    tmpA.linkedTab = this.tabs[i];
    tmpA.linkedTabRoot = this;
    tmpA.setAttribute("href", "#");
    tmpA.setAttribute("onclick", "this.linkedTabRoot.hideAllTabs(); this.linkedTab.show(); return false;");
    
    tmpText = document.createTextNode(this.tabs[i].header.firstChild.nodeValue);
    
    ///Anhängen
        
    tmpA.appendChild(tmpText);    
    tmpLi.appendChild(tmpA);
    
    this.toc.appendChild(tmpLi);
    
    ///Sortierung vornehmen
    this.domRoot.appendChild(this.tabs[i].domRoot);
  }

//*/  
  /// Funktionen:
   
  this.hideAllTabs = function() {
    var i;
    for(i=0; i<this.tabs.length; i++) { this.tabs[i].hide(); }
  }   
  this.showAllTabs = function() {
    var i;
    for(i=0; i<this.tabs.length; i++) { this.tabs[i].show(); }
  }
//*/  


  ///Initialsisierung
  this.hideAllTabs();
  this.tabs[0].show();
}

function makeTabs(domRoot) {
  var i, search;
  search = domRoot.getElementsByTagName("div");
  
  for(i=0; i<search.length; i++) {
     if (search[i].getAttribute("class") == "tabRoot") { new TabRoot(search[i]); }
  }
}

/// DEBUG! Muss noch ins BodyTag als onload..
window.setTimeout("makeTabs(document.getElementById('main'))", 10);
