/*
/*  panel.js
*/

var Panel = Class.create({
  initialize: function (el) {
    this.el        = el;
    this.tabsEl    = el.down(".tabs").select("li");
    this.contentEl = el.down(".content").select("li");
    this.observeTabs();
  },
  
  observeTabs: function () {
    var panel = this;
    this.tabsEl.each(function (el, index) {
      el.onclick = Prototype.K.bind(this, false);
      el.observe("click", 
        panel.selectTabAtIndex.bind(panel, index));
    });
  },
  
  selectTabAtIndex: function (newIndex) {
    this.tabsEl.each(function (el, index) {
      if (index == newIndex)
        el.addClassName("current");
      else
        el.removeClassName("current");
    });
    this.contentEl.each(function (el, index) {
      if (index == newIndex)
        el.addClassName("current");
      else
        el.removeClassName("current");
    });
  }
});

document.observe("dom:loaded", function () {
  $$(".panel").each(function (el) {
    new Panel(el);
  })
});
