TabPane = Base.extend({
   tabs: new Array (),
   tabClassName: 'active',
   paneClassName: 'active',
   
   constructor: function (tabClassName, paneClassName) {
      if (tabClassName) {
         this.tabClassName  = tabClassName;
      }
      if (paneClassName) {
         this.paneClassName = paneClassName;
      }
   },
   
   add: function (element, pane) {
      tab = new Tab (element, pane);
      this.tabs.push (tab);
      Event.observe (element, 'click', function () { this.select (element); return false }.bind (this));
   },
   
   select: function (element) {
      element.blur ();
      for (var i = 0; i < this.tabs.length; i++) {
         var active = (this.tabs[i].element == element);
			if ( active && Cookie ) {
				Cookie.set ( 'theme.tabs.selectedIndex', i );
			}
         Ysf.toggleClassIf (active, this.tabs[i].element, this.tabClassName);
         Ysf.toggleClassIf (active, this.tabs[i].pane, this.paneClassName);
      }
   },
   
   init: function () {
      this.tabs[0].element.click ();
   }
});


Tab = Base.extend({
   index:   0,
   element: null,
   pane:    null,
   
   constructor: function (element, pane) {
      this.element = element;
      this.pane    = pane;
   }
});
