(function($, Lego){

Lego.block['b-tabbed-pane__tabs'] = function(params){
    var thisTabbedPaneTabs = $(this),
        componentIndex = params.bind || 'def',
        tabs = thisTabbedPaneTabs.find('.b-tabbed-pane__tab'),
        storage = [];
        $.each(tabs, function(){
            var tab = $(this);
            var bind = (this.onclick ? this.onclick() : {}).bind || 'def';
            storage.push(tab.data('b-tabbed-pane.tabs', {index : bind }));
            tab.click(function(){
                var bind = $(this).data('b-tabbed-pane.tabs').index;
                bind = typeof bind == 'string' ? [bind] : bind;
                $(document).trigger(componentIndex + '.togglePanel.lego', { index: bind });
                $.each(storage, function(){
                    var i = this.data('b-tabbed-pane.tabs').index;
                    this.toggleClass('b-tabbed-pane__item_current', tab == this);
                });
            });
        });
};
})(jQuery, window.Lego);
