/* Javascript tab manager class.
 * Written By: Ken Colton <kcolton@360hubs.com>
 */

/* Namespacing object for our tab class */
var TabManager360 = new Object();

TabManager360.TabbedPannel = function(setPannelID)
{
  this.pannelID = setPannelID;
  this.pannelNode = document.getElementById(this.pannelID);

  this.tabHolderNode = getElementByClassName(this.pannelNode, "TabHolder");
  this.tabListNode = getElementByClassName(this.tabHolderNode, "TabList");

  this.tabNodes = this.tabListNode.childNodes;

  this.activeIndex = getChildIndexByClassName(this.tabListNode, "active");

  this.contentHolderNode = getElementByClassName(this.pannelNode, "TabContent");
  this.contentNodes = this.contentHolderNode.childNodes;

  for(var i = 0; i < this.tabNodes.length; i++)
  {
    this.tabNodes[i].managerObject = this;
    this.tabNodes[i].childIndex = i;
    this.tabNodes[i].onclick = this.changeTab;
  }
}

TabManager360.TabbedPannel.prototype =
{
  changeTab:function()
  {
    if(this.childIndex != this.managerObject.activeIndex)
    {
      this.managerObject.tabNodes[this.childIndex].className = "active";
      this.managerObject.tabNodes[this.managerObject.activeIndex].className = "";

      this.managerObject.contentNodes[this.childIndex].className = "active";

      if(this.managerObject.contentNodes[this.childIndex].call)
        eval(this.managerObject.contentNodes[this.childIndex].call);

      this.managerObject.contentNodes[this.managerObject.activeIndex].className = "nonactive";

      this.managerObject.activeIndex = this.childIndex;
    }
  }
}
