// Tabbed Browser object for Package Template:
function TB(eRoot, transitMode)
{
 // event handler: swap displayed info when control link clicked 
  this.selectfn = function(eClick)
  {
    var elt = Event.findElement(eClick, 'a');
    var newsel;
   // find which tab triggered click event 
    for (var i = 0; i < this.aTabs.length; i++)
    {
      if (this.aTabs[i] == elt)
      {
        newsel = i;
        break;
      }
    }
   // change displayed info if current selection not clicked:
    if (newsel != this.cursel) 
    {
     // change selected tab: 
      this.aTabs[this.cursel].className = "PkgTB_unsel";
      this.aTabs[newsel].className = "PkgTB_sel";
     // hide unselected content, show selected
      if (this.tmode == 0)
      {  // mode 0: straight swap
        this.aInfo[this.cursel].style.display = "none";   
        this.aInfo[newsel].style.visibility = "visible";   
        this.aInfo[newsel].style.display = "block";   
      }
      else if (this.tmode == 1)
      {  // mode 1: Scriptaculous dissolve effect
        Effect.Fade(this.aInfo[this.cursel]); 
        this.aInfo[newsel].style.visibility = "visible";   
        Effect.Appear(this.aInfo[newsel]);
      }
      this.cursel = newsel;
    }
    Event.stop(eClick);
    return false;
  };

// constructor code
  this.eRoot = eRoot;            // root div of this Tabbed Browser
  this.tmode = transitMode;      // transition mode: instant or Scriptaculous fade/appear
  this.aTabs = new Array();      // control links
  this.aInfo = new Array();      // content to display
  
  this.aTabs = this.eRoot.getElementsByClassName("PkgTBLinks")[0].getElementsByTagName("a");
  this.aInfo = this.eRoot.getElementsByClassName("PkgTBdisp");
  if (this.aTabs.length != this.aInfo.length) return -1;    // error: must have #tabs == # content areas
  for (var i = 0; i < this.aTabs.length; i++)
  {
    Event.observe(this.aTabs[i], 'click', this.selectfn.bindAsEventListener(this)); 
    if ( (this.aInfo[i].style.visibility == "visible") && (this.aInfo[i].style.display == "block"))
    {
      this.cursel = i;
    }
    else
    {
      this.aInfo[i].style.visibility = "visible";
      this.aInfo[i].style.display = "none";
    }
  }
  if (typeof(this.cursel) != "number" || (0 > this.cursel) || (this.cursel >= this.aTabs.length))
  {
    this.cursel = 0;   
    this.aTabs[this.cursel].className = "PkgTB_sel";
    this.aInfo[this.cursel].style.display = "block";   
  }  
  return;
}

function PkgTB_Prep()
{
 // locate all elements (s/b divs) that are Tabbed Browser containers
 // create Tabbed Browser object for each
  aTBconfig = [ { transitMode: 0 },
                { transitMode: 1 },
                { transitMode: 1 },
                { transitMode: 1 },
                { transitMode: 1 }];
  var aeTBC = document.getElementsByClassName("PkgTabbedBrowse");
  for (var i = 0; i < aeTBC.length; i++)
  {
    var j = parseInt(aeTBC[i].id.substring(2,4));
   // look up configuration; default to 0th if none/invalid
    if ( (isNaN(j)) || (j >= (aTBconfig.length)) ) j = 0; 
    new TB(aeTBC[i], aTBconfig[j].transitMode);
  }
}

