/*
 * Chris Peery
 * version 1.0 2009-07-25
 */
var Simpletabs = Class.create();

Simpletabs.prototype = {
  initialize : function(list, options) {
    this.list = $(list);
    if (null == this.list) return false;

    this.options = Object.extend({
        beforeTabSelect: Prototype.emptyFunction,
        afterTabSelect: Prototype.emptyFunction,
        defaultTabIndex: 0,
        tabSelectEvent: 'click'
    },options || {});

    this.tabs = this.list.getElementsBySelector('a');

    // define events for slider
    this.events = {
      tabClick: this.activate.bind(this)
    };

    this.tabs.invoke('observe', this.options.tabSelectEvent, this.events.tabClick);
    this.show(this.tabs[this.options.defaultTabIndex]);
  },
  activate :  function(event) {
    Event.stop(event);

    var element = Event.element(event);
    if ( !element.readAttribute('href') ) element = element.up('a', 0);
    element.blur();

    this.show(element);
    this.tabs.without(element).each(this.hide.bind(this));
  },
  hide : function(element) {
    $(element).removeClassName('active-tab');
    $(this.tabID(element)).removeClassName('active-tab-body');
  },
  show : function(element) {
    $(element).addClassName('active-tab');
    $(this.tabID(element)).addClassName('active-tab-body');
  },
  tabID : function(element) {
    return element.id + '-body';
  }
}
