TabControl = {
    tabs: [],
    currentTab: null,
    
    register: function(tab) {
        tab.deactivate();
        if (!this.tabs.length)
            tab.activate();
            
        this.tabs.push(tab);    
    },
    
    notify: function(tab) {
        cTab = this.currentTab;
        if (cTab)
            cTab.deactivate();
        
        this.currentTab = tab;
    }
};

Tab = Class.create({
    tab: null,
    tabContent: null,
    controller: null,

    initialize: function(tab, tabContent) {
        this.tab = $(tab);
        this.tabContent = $(tabContent);
        TabControl.register(this);
        
        Event.observe(this.tab, 'click', this.activate.bindAsEventListener(this));
    
    },
    
    activate: function() {
        TabControl.notify(this);
        this.tab.addClassName('tab-on');
        this.tab.removeClassName('tab-off');
        this.tabContent.show();
    },
    
    deactivate: function() {
        this.tab.addClassName('tab-off');
        this.tab.removeClassName('tab-on')
        
        this.tabContent.hide();
    }
});

document.observe("dom:loaded", 
    function() {
        if ($('features-tab')) {
            new Tab('features-tab','features');
            new Tab('specifications-tab','specifications');
            new Tab('warranty-tab','warranty');
            new Tab('customer-service-tab','customer-service'); 
            new Tab('availability-purchase-tab','availability-purchase');
        }
    }
);


