var Tabs = Class.create({
  initialize : function(activeClass) {
    this.activeClass = activeClass;
    this.hashLink = window.location.hash;
    this.tabs = $H({});
  },
  addTab: function(tabName, tabElement, linkElement, contentElement) {
    this.tabs.set(tabName, [tabElement, contentElement]);
    linkElement.observe('click', function(ev) {
      this.activate(tabName);
      ev.stop();
    }.bindAsEventListener(this));
    if (Object.isUndefined(this.activeTab) || this.hashLink == "#" + tabName) { this.activate(tabName); }
  },
  activate: function(tabName) {
    if (!this.tabs.keys().include(tabName)) { return; }
    this.activeTab = tabName;
    window.location.hash = tabName;
    this.tabs.each(function(t) {
      if (t[0] == tabName) {
        t[1][0].addClassName(this.activeClass);
        t[1][1].show();
      } else {
        t[1][0].removeClassName(this.activeClass);
        t[1][1].hide();
      }
    }.bind(this));
  }
});
