var Bekent = Bekent || {};

Bekent.Tabs = new Class({

    Extends: Bekent.Rotater,

    options: {
        autoplay: false,
        tabSelector: '.tabs a',
        contentSelector: '.tab-content'
    },

    initialize: function(container, options){
        this.setOptions(options);
        this.container = $(container);
        this.tabs = this.container.getElements(this.options.tabSelector);
        if(this.tabs.length == 0) return false;
        this.createTabs();
        this.parent(this.container.getElements(this.options.contentSelector),options);
        return this;
    },

    createTabs: function () {
        this.tabs.each(function(tab,index){
            tab.addEvent('click', function(event){
                event.preventDefault();
                this.showSlide(index);
                this.stop();
            }.bind(this));
        }.bind(this));
    }.protect(),

    activateTab: function(tabIndex) {
        this.tabs.removeClass('active');
        this.tabs[tabIndex].addClass('active');
    }.protect(),

    showSlide: function(slideIndex){
        if(slideIndex == this.currentSlide) return this;
        this.activateTab(slideIndex);
        this.parent(slideIndex);
        return this;
    }

});
