var Tabs = Class.create();
Tabs.prototype = {
   initialize : function(element) {
          this.element = $(element).getElementsByTagName('ul')[0];
          var options = Object.extend({}, arguments[1] || {});
          this.menu = $A(this.element.getElementsByTagName('a'));
          $(element).select('.tab_content').each(function(e) {
            e.hide();
          });
          this.show(this.getInitialTab());
          this.menu.each(this.setupTab.bind(this));
 },
        setupTab : function(elm) {
            Event.observe(elm,'click',this.activate.bindAsEventListener(this),false)
  },
        test : function() {
          alert(123);
        },
        activate :  function(ev) {
           var elm = Event.findElement(ev, "a");
           Event.stop(ev);
           document.location.href = '#'+this.tabID(elm);
           this.menu.without(elm).each(this.hide.bind(this));
           this.show(elm);
        },
        hide : function(elm) {
            $(elm).removeClassName('active');
            $(this.tabID(elm)).hide();

    },
        show : function(elm) {
            $(elm).addClassName('active');
            $(this.tabID(elm)).show();
  },
        tabID : function(elm) {
           return elm.href.match(/#(\w.+)/)[1];
      },
        getInitialTab : function() {
          if(document.location.href.match(/#(\w.+)/)) {
            var loc = RegExp.$1;
            var elm = this.menu.find(function(value) { return value.href.match(/#(\w.+)/)[1] == loc; });
            return elm || this.menu.first();
          } else {
                  return this.menu.first();
         }
 }
}

