var Tabber = new Class({
    container: {},
    handler_size: {},
    current_tab: 0,
    handlers: [],
    tabs: [],
    
    Implements: [Options, Events],
    
    options: {
        find_selected: true,
        selected_class: 'tabber_handle_selected',
        container: false
    },
    
    initialize: function(options){
        this.setOptions(options);

        if(this.options.container){
            this.shell          = $(this.options.container);
            this.container      = this.shell.getElement('.tabber_tab_container');
            this.handlers       = this.shell.getElements('a.tabber_handle');
            this.tabs           = this.shell.getElements('.tabber_tab');
            
            this.container.store('fx', new Fx.Morph(this.container, {
                duration: 275
            }));
            
            this._build()._handlerActions().showTab(this.current_tab);
        }
    },
    
    showTab: function(index){
        this.tabs.each(function(tab, i){
            if(i == index){
                this.handlers[i].addClass('tabber_handle_selected');
                var size = tab.getScrollSize();
                
                this.container.retrieve('fx').start({
                    'height' : size.y
                });
                
                tab.setStyle('height', size.y);
            }else{
                tab.setStyle('height', '0px');
                this.handlers[i].removeClass('tabber_handle_selected');
            }
        }.bind(this));
        
        return this;
    },
    
    _handlerActions: function(){
        this.handlers.each(function(handle, i){
            handle.removeEvents();
            handle.addEvent('click', function(e){
                e.stop();
                this.showTab(i);
            }.bind(this));
        
        }.bind(this));
        
        return this;
    },
    
    _build: function(){
        this.tabs.each(function(tab){
            tab.setStyles({
                'height': '0px'
            });
        });
        
        return this;
    }
});