



var tab = Class.create({  initialize: function(config) {
    this.cfg = config;  //config contains btn, contentBox, eventType, tabOpen, 
    this.create();    
  },
  
  create: function(){
    this.setTab();
    if(this.cfg.tabOpen){
      this.openTab();
    }else{
      this.closeTab();
    }
  },
  
  setTab: function(){
    this.cfg.btn.observe(this.cfg.eventType, this.tabEvent.bind(this)); 
  },
  
  tabEvent: function(){
    if(this.cfg.tabOpen){
      this.closeTab();
    }else{
      this.openTab();
    }
    
  },
  
  openTab: function(){
    var prNode = Element.extend(this.cfg.contentBox.parentNode);
    prNode.fire("tab:clicked");
    prNode.addClassName('open-tab');
    prNode.removeClassName('close-tab');
    this.cfg.tabOpen = true;
   
  },
  
  closeTab: function(){
    var prNode = Element.extend(this.cfg.contentBox.parentNode);
    prNode.removeClassName('open-tab');
    prNode.addClassName('close-tab');
    this.cfg.tabOpen = false;
  },
  
  getTabState: function(){
    return this.cfg.tabOpen;
  }
  });