// JavaScript Document

/**
 * This file, tab.js, contains the tabNavigation object which is used to create
 * instances of a tab navigation system on the page.
 *
 **/
 
 /* Create a new class using Prototype's Class Object */
 var tabNavigation = Class.create();
 
 tabNavigation.prototype = {
    
    _menu: null,
    
    _currentTab: null,
    
    initialize: function(p_id, p_startTab) {
      
      // var options = Object.extend({},arguments[1]|| {});
      this._menu = $$('#' + p_id + ' a')
      this._menu.each(this.setupTab.bind(this));
      this.highlightTab(p_startTab);
    },
    
    setupTab: function(elm) {
      Event.observe(elm,'click',this.expandTab.bindAsEventListener(this),false);
      $(elm.id + 'Content').setStyle({display: 'none'});
    },
    
    expandTab: function(ev) {
      var elmId = Event.findElement(ev,'a').id;
      Event.stop(ev);
      this.highlightTab(elmId);
      return(false);
    },
    
    highlightTab: function(p_linkId) {
      this._menu.without(p_linkId).each( function(elm) {
         $(elm).removeClassName('selected');
         $(elm.id + 'Content').setStyle({display: 'none'});
         // Effect.SlideUp(elm.id + 'Content', {duration: 0.5});
      });
      
      $(p_linkId).addClassName('selected');
      this._currentTab = p_linkId;
      $(p_linkId + 'Content').setStyle( {display: 'block'});
      // Effect.Appear(p_linkId + 'Content', {duration: 0.5});
      // Effect.SlideDown(p_linkId + 'Content', {duration: 0.2});
      // Effect.SlideDown('tabcontents', {duration: 0.2});
      // setTimeout($(p_linkId + 'Content').setStyle( {display: 'block'}),700);
    },
    
    getCurrentTab: function() { return this._currentTab; }
  };
 
 
 /*
 try {
    
    Event.observe(window, 'load', function() {
      tabs = new tabNavigation('tabList','tabclub');
                                 }, true);
 } catch(ex) {}
 
 */
 
