/*Designed and developed by Kristine Towne
JS file for tabbox*/

tabLeft = new Array();
tabRight = new Array();
tabLinks = new Array();
tabContent = new Array();
tabFeatures = new Array();

selected = '#6b0000';
unselected = '#666666';
unselectedborder = '1px solid #666666';
selectedborder = '1px solid #fff';

window.onload = function(){
  var main = document.getElementById("main");
  if(main.hasChildNodes()){
    var divs = main.getElementsByTagName("div");
    for (i = 0; i < divs.length; i++){
      if(divs[i].className == "feature"){
        tabFeatures.push(divs[i]);
      }
    }
  }

  for (t = 0; t < tabFeatures.length; t++){
    feature = tabFeatures[t];
    feature.pos = t;
    tabContent[feature.pos] = new Array();
    tabLeft[feature.pos] = new Array();
    tabRight[feature.pos] = new Array();
    tabLinks[feature.pos] = new Array();

    if(feature.hasChildNodes()){
      var tabbox = feature.getElementsByTagName("div")[0];
      if(tabbox && tabbox.hasChildNodes()){
        var content = tabbox.getElementsByTagName("ul")[1];
        if(content && content.className == "content"){
          if(content.hasChildNodes()){
            var li = content.firstChild;
            do{
              if(li.hasChildNodes()){
                tabContent[feature.pos].push(li);
              }
              li = li.nextSibling;
            }while(li);
           }
         }
         var menu = tabbox.getElementsByTagName("ul")[0];
         if(menu && menu.className == "menu"){
           if(menu.hasChildNodes()){
             var li = menu.firstChild; 
             i = 0;
             do{
               if(li.hasChildNodes()){
                 tabLeft[feature.pos].push(li);
                 var p = li.firstChild;
                 do{
                   if(p.hasChildNodes()){
                     tabRight[feature.pos].push(p);
                     var a = p.firstChild;
                     tabLinks[feature.pos].push(a);
                     a.onmousedown = function(){
                       for(w = 0; w < tabContent[this.location].length; w++){
                         tabContent[this.location][w].style.display='none';
                       }
                       for(x = 0; x < tabLeft[this.location].length; x++){
                         tabLeft[this.location][x].style.background=unselected;
                         tabLeft[this.location][x].style.backgroundImage='url(Images/topleft.gif)';
                         tabLeft[this.location][x].style.backgroundPosition='top left'
                         tabLeft[this.location][x].style.backgroundRepeat='no-repeat';
                         tabLeft[this.location][x].style.borderBottom=unselectedborder;
                       }
                       for(y = 0; y < tabRight[this.location].length; y++){
                         tabRight[this.location][y].style.background=unselected;
                         tabRight[this.location][y].style.backgroundImage='url(Images/topright.gif)';
	                 tabRight[this.location][y].style.backgroundPosition='top right'
                         tabRight[this.location][y].style.backgroundRepeat='no-repeat';
                       }  
                       for(z = 0; z < tabLinks[this.location].length; z++){
                         tabLinks[this.location][z].style.background=unselected;
                         tabLinks[this.location][z].style.color='#fff';
                         tabLinks[this.location][z].selected = false;
                       } 

  	               tabContent[this.location][this.pos].style.display='block';
                       tabLeft[this.location][this.pos].style.background='#fff';
                       tabLeft[this.location][this.pos].style.backgroundImage='url(Images/topleft.gif)';
                       tabLeft[this.location][this.pos].style.backgroundPosition='top left'
                       tabLeft[this.location][this.pos].style.backgroundRepeat='no-repeat';
                       tabLeft[this.location][this.pos].style.borderBottom=selectedborder;
                       tabRight[this.location][this.pos].style.background='#fff';
                       tabRight[this.location][this.pos].style.backgroundImage='url(Images/topright.gif)';
	               tabRight[this.location][this.pos].style.backgroundPosition='top right'
                       tabRight[this.location][this.pos].style.backgroundRepeat='no-repeat';
                       tabLinks[this.location][this.pos].style.background='#fff';
                       tabLinks[this.location][this.pos].style.color=selected;
                       this.selected = true
                     }
                     a.onmouseover = function(){
                       if(!this.selected){
                         tabLinks[this.location][this.pos].style.color=selected;
                       }
                     }
                     a.onmouseout = function(){
                       if(!this.selected){
                         tabLinks[this.location][this.pos].style.color='#fff';
                       } 
                     }
                     a.location = feature.pos;
                     a.pos = i;
                     i = i + 1;
                     a.selected = false;
                   }
                   p = p.nextSibling;
                 }while(p);
               }
               li = li.nextSibling; 
             }while(li);
           }
         }
       }
     }
  }
          
  for (b = 0; b < tabFeatures.length; b++){
    tabContent[b][0].style.display='block';
    tabLeft[b][0].style.background='#fff';
    tabLeft[b][0].style.backgroundImage='url(Images/topleft.gif)';
    tabLeft[b][0].style.backgroundPosition='top left'
    tabLeft[b][0].style.backgroundRepeat='no-repeat';   
    tabLeft[b][0].style.borderBottom=selectedborder;    
    tabRight[b][0].style.background='#fff';
    tabRight[b][0].style.backgroundImage='url(Images/topright.gif)';
    tabRight[b][0].style.backgroundPosition='top right'
    tabRight[b][0].style.backgroundRepeat='no-repeat';  
    tabLinks[b][0].style.background='#fff';
    tabLinks[b][0].style.color=selected;
    tabLinks[b][0].selected = true;
  }
}