/* -------------------------------------------------------------------------------------------------------------*/
/* -------------------------------------------------------------------------------------------------------------*/

TabsController = function() {
    TabsController.superClass.apply( this, arguments );
    this.panels = new Array();
}
TabsController.inheritsFrom( Glyph );

/* -------------------------------------------------------------------------------------------------------------*/

TabsController.prototype.setTabWidth = function() {
    for( var i = 0; i < this.panels.length; i++ ) {
        this.panels[ i ].setTabWidth();
    }
}

/* -------------------------------------------------------------------------------------------------------------*/

TabsController.prototype.findPanels = function () {
    var panels = new Array();
    if( document.getElementsByClassName ) {
        panels = document.getElementsByClassName( this.type );
    } else {
        var allNodes = document.getElementsByTagName( '*' );
        var pattern = new RegExp( this.type );
        for( var i = 0; i < allNodes.length; i++ ) {
            var cNode = allNodes[ i ];
            if(
                cNode &&
                cNode.className != '' &&
                pattern.test( cNode.className )
            ) {
                panels[ panels.length ] = cNode;
            }
        }
    }
    for( var c = 0; c < panels.length; c++ ) {
        this.addPanel( panels[ c ] );
    }
}

/* -------------------------------------------------------------------------------------------------------------*/

TabsController.prototype.addPanel = function( panel ) {
    var key = this.getDefaults();

    var newPanel = new this.panel( panel );
    this.panels[ this.panels.length ] = newPanel;
    newPanel.attachObserver( 'Choosed', function() {
        this.notify( 'Choosed' );
    }, this );

    if(
        newPanel &&
        newPanel.getTab
    ) {
        var tab = newPanel.getTab( key || 0 );
        if( tab ) {
          newPanel.choose( tab );
        }
    } 
    return newPanel;
}

/* -------------------------------------------------------------------------------------------------------------*/
/* -------------------------------------------------------------------------------------------------------------*/

TabPanel = function( element, key ) {
    TabPanel.superClass.apply( this, arguments );
    this.element = element;
    this.tabs = new Array();
    this.levels = new Array();
    this.selected = false;

    this.fixed = new RegExp( /(\s*fixed\s*)+/i ).test( this.element.className );
    if( !this.fixed ) {
        this.addHandler( window, 'resize', this.setTabWidth );
    }
}
TabPanel.inheritsFrom( Glyph );

/* -------------------------------------------------------------------------------------------------------------*/

TabPanel.prototype.findTabs = function() {
    var tabs = new Array();
    var pattern = new RegExp( /(\s*tab\s*)+/i );
    var reg_next_line = /\s*next_line\s*/i,
        flag_next_line = $( 'div.next_line', this.element ).length;

    for( var c in this.element.childNodes ) {
        var child = this.element.childNodes[ c ];
        if(
            child &&
            child.className != '' &&
            pattern.test( child.className )
        ) {
            tabs[ tabs.length ] = child;
        }
    }

    var length = tabs[ 'length' ],
        level = this.addLevel();

    for( var c in tabs ) {
        var tab = tabs[ c ];
        if(
            ( !flag_next_line && length > 5 && c == Math.ceil( length / 2 ) ) || ( flag_next_line && reg_next_line.test( tab.className ) ) ) {
            level = this.addLevel();
        }
        this.addTab( tab, level );
    }
}

/* -------------------------------------------------------------------------------------------------------------*/

TabPanel.prototype.getTab = function( idx ) {
    if(
        idx != undefined &&
        this.tabs &&
        this.tabs[ idx ]
    ) {
        return this.tabs[ idx ]
    }
    return false;
}

/* -------------------------------------------------------------------------------------------------------------*/

TabPanel.prototype.choose = function( tab ) {
    if(
        this.selected &&
        this.selected == tab
    ) return false;

    if( this.selected ) {
        this.selected.select( false );
        this.selected = false;
    }

    if( tab ) {
        this.selected = tab;
        this.selected.select( true );
        this.notify( 'Choosed' );
        this.setTabWidth();
    }
}

/* -------------------------------------------------------------------------------------------------------------*/

TabPanel.prototype.setTabWidth = function() {
    for( var i = 0; i < this.levels.length; i++ ) {
        this.levels[ i ].setTabWidth();
    }
}

/* -------------------------------------------------------------------------------------------------------------*/
/* -------------------------------------------------------------------------------------------------------------*/

TabLevel = function( target ) {
    TabLevel.superClass.apply( this, arguments );
    this.current = false;
    this.tabs = new Array();
    this.inRwH = 1;
}
TabLevel.inheritsFrom( Glyph );

/* -------------------------------------------------------------------------------------------------------------*/

TabLevel.prototype.getTab = function( idx ) {
    if(
        idx != undefined &&
        this.tabs &&
        this.tabs[ idx ]
    ) {
        return this.tabs[ idx ]
    }
    return false;
}

/* -------------------------------------------------------------------------------------------------------------*/

TabLevel.prototype.getTotalWidth = function() {
    return this.offset()[ 'width' ];
}

/* -------------------------------------------------------------------------------------------------------------*/

TabLevel.prototype.setTabWidth = function() {
    var length = this.tabs.length;
    var totalWidth = this.getTotalWidth();

    var width = Math.ceil( ( totalWidth ) / length );
    var lastWidth = totalWidth - ( width * ( length - 1 ));

    for( var i = 0; i < length - 1; i++ ) {
        this.setHeaderWidth( i, width );
    }
    this.setHeaderWidth( length - 1, lastWidth );
}

/* -------------------------------------------------------------------------------------------------------------*/

TabLevel.prototype.addTab = function( tab ) {
    var newTab = new Tab( tab, this.element );

    if( !newTab.hidden ) {
        this.tabs[ this.tabs.length ] = newTab;

        this.element.appendChild( newTab[ 'header' ] );

        newTab.attachObserver( 'Selected', function() {
            this.notify( 'Selected' );
        }, this );

        return newTab;
    }
    return false;
}

/* -------------------------------------------------------------------------------------------------------------*/

TabLevel.prototype.setHeaderWidth = function( idx, width ) {
    var tab = this.getTab( idx );
    if(
        tab &&
        tab.setHeaderWidth &&
        width >= 0
    ) {
        this.getTab( idx ).setHeaderWidth( width );
    }
}

/* -------------------------------------------------------------------------------------------------------------*/
/* -------------------------------------------------------------------------------------------------------------*/

Tab = function( tab, target ) {
    Tab.superClass.apply( this, [] );
    this.element = tab;

    var pattern = new RegExp( /(\s*header\s*)+/i );

    for( var c in this.element.childNodes ) {
        var child = this.element.childNodes[ c ];
        if(
            !this.header &&
            child &&
            child.className != '' &&
            pattern.test( child.className )
        ) {
            this.header = false;
            if( !( /\bdontshow\b/.test( child.className ) ) ) {
                this.header = child;
                target.appendChild( this.header );
                
                this.addHandler( this.header, 'click', this.notify, 'Choosed' );
            
                this.addHandler( this.header, 'mouseover', function( params, ev ) {
                    this.stopPropagation( ev );
                    this.notify( 'Overed' );
                });

                this.addHandler( this.header.getElementsByTagName( 'A' )[0], 'click', function( params, ev ) {
                    this.preventDefault( ev );
                });
            } else {
                this.hidden = true;
            }
        }
    }
    this.setClassName( 'hidden', true );
}
Tab.inheritsFrom( Glyph );

/* -------------------------------------------------------------------------------------------------------------*/

Tab.prototype.setHeaderWidth = function( width ) {
    if( width < 0 ) return false;
    
    this.setStyle({
        'width': width + 'px'
    }, this.header );
}

/* -------------------------------------------------------------------------------------------------------------*/

Tab.prototype.select = function( flag ) {
    this.setClassName( 'selected', flag, this.header );
    this.setClassName( 'hidden', !flag );
    this.notify( 'Selected' );
}

/* -------------------------------------------------------------------------------------------------------------*/
/* -------------------------------------------------------------------------------------------------------------*/

SimpleTabsController = function() {
    this.type = 'tabs';
    this.panel = SimpleTabPanel;
    SimpleTabsController.superClass.apply( this, arguments );
    this.findPanels();
}
SimpleTabsController.inheritsFrom( TabsController );

/* -------------------------------------------------------------------------------------------------------------*/

SimpleTabsController.prototype.getDefaults = function() {
    var query = window.location[ 'search' ];
    if( query ) {
        var pattern = new RegExp( /tab=(\d+)/gi );
        var exec = pattern.exec( query );
        if(
            exec &&
            exec[ 1 ]
        ) {
            return exec[ 1 ];
        }
    }
    return 0;
}

/* -------------------------------------------------------------------------------------------------------------*/
/* -------------------------------------------------------------------------------------------------------------*/

SimpleTabPanel = function( element ) {
    this.level = false;
    SimpleTabPanel.superClass.apply( this, arguments );

    this.findTabs();
    for( var i = 0; i < this.levels.length; i++ ) {
        this.levels[ i ].setCorners();
    }

    this.createNode( 'i', this.element, { 'class': 'corner lb' });
    this.createNode( 'i', this.element, { 'class': 'corner rb' });

    this.setClassName( 'tabbed', true );

    this.setTabWidth();
    this.setTabHeight();
}
SimpleTabPanel.inheritsFrom( TabPanel );

/* -------------------------------------------------------------------------------------------------------------*/

SimpleTabPanel.prototype.getLevel = function( key ) {
    return this.levels[ key ] || false;
}

/* -------------------------------------------------------------------------------------------------------------*/

SimpleTabPanel.prototype.addLevel = function() {
    var level = new SimpleTabLevel( this.element.childNodes[ this.levels.length ] );
    this.levels[ this.levels.length ] = level;
    this.setClassName( 'overload', this.levels.length > 1 );
    level.attachObserver( 'Selected', this.selectLevel, this );
    level.attachObserver( 'Selected', this.switchLevels, this );
    return level;
}

/* -------------------------------------------------------------------------------------------------------------*/

SimpleTabPanel.prototype.addTab = function( tab, level ) {
    var newTab = level.addTab( tab );
    if( !newTab ) return false;
    newTab.attachObserver( 'Choosed', function( params, tab ) {
        if( tab == this.selected ) return false;
        this.choose( tab );
        return true;
    }, this );

    this.tabs[ this.tabs.length ] = newTab;
    return newTab;
}

/* -------------------------------------------------------------------------------------------------------------*/

SimpleTabPanel.prototype.selectLevel = function( params, level ) {
    if( this.level == level ) return false;
    
    if( this.level ) {
        this.level.select( false );
    }
    if( level ) {
        this.level = level;
        this.level.select( true );
    }
    this.setTabWidth();
}

/* -------------------------------------------------------------------------------------------------------------*/

SimpleTabPanel.prototype.switchLevels = function() {
    if( !this.getTab ) return false;
    var tab = this.getTab( 0 );
    if(
    tab &&
    tab.element
  ) {
    this.element.insertBefore( this.level.element, tab.element );
  }
}

/* -------------------------------------------------------------------------------------------------------------*/

SimpleTabPanel.prototype.setTabHeight = function() {

    for( var c = this.levels.length; c; c-- ) {
        this.levels[ c - 1 ].setTabHeight();
    }
}

/* -------------------------------------------------------------------------------------------------------------*/
/* -------------------------------------------------------------------------------------------------------------*/

SimpleTabLevel = function( beacon ) {
    SimpleTabLevel.superClass.apply( this, arguments );

    this.element = this.createNode( 'div', false, { 'class': 'headers' });
    beacon.parentNode.insertBefore( this.element, beacon );
}
SimpleTabLevel.inheritsFrom( TabLevel );

/* -------------------------------------------------------------------------------------------------------------*/

SimpleTabLevel.prototype.getTotalWidth = function() {
    return this.offset()[ 'width' ] - ( this.current ? 3 : 15 );
}

/* -------------------------------------------------------------------------------------------------------------*/
window.info = new Array();
SimpleTabLevel.prototype.setTabHeight = function() {
    var heights = new Array();
    for( var c in this.tabs ) {
        var header = this.tabs[ c ][ 'header' ];
        var a = header.getElementsByTagName( 'A' )[ 0 ];
        var aHeight = a.offsetHeight - 11; //this.offset( a )[ 'height' ] - 11;
        heights[ c ] = aHeight;
        if( aHeight > this.inRwH * 16 ) {
            this.inRwH = Math.ceil( aHeight / 16 );
        }
    }

    for( var c in this.tabs ) {
        var rows = Math.ceil( heights[ c ] / 16 );
        var delta = this.inRwH * 16 - heights[ c ];
        var header = this.tabs[ c ][ 'header' ];
        var a = header.getElementsByTagName( 'A' )[ 0 ]

        if( delta > 0 ) {
            /*this.setStyle({
                'lineHeight': ( heights[ c ] + delta ) / rows + 'px',
                'height': ( heights[ c ] + delta ) / rows + 'px'
            }, a );*/
            this.setClassName( 'rh' + ( rows + 1 ), true, a );
        }
/*
        info[ info.length ] = {
            'idx': c,
            'delta': delta,
            'height': heights[ c ],
            'rows': rows
        };
*/
    }
    
    this.setClassName( 'r' + this.inRwH, true );
}

/* -------------------------------------------------------------------------------------------------------------*/

SimpleTabLevel.prototype.select = function( flag ) {
    this.current = flag;
    this.setClassName( 'current', flag );
}

/* -------------------------------------------------------------------------------------------------------------*/

SimpleTabLevel.prototype.setCorners = function() {
    this.createNode( 'i', this.getTab( 0 ).header, { 'class': 'corner lt' });
    this.createNode( 'i', this.getTab( this.tabs.length - 1 ).header, { 'class': 'corner rt' });
}

/* -------------------------------------------------------------------------------------------------------------*/
/* -------------------------------------------------------------------------------------------------------------*/

ToggleTabsController = function() {
    this.type = 'toggle';
    this.panel = TogglePanel;
    ToggleTabsController.superClass.apply( this, arguments );
    this.findPanels();
}
ToggleTabsController.inheritsFrom( TabsController );

/* -------------------------------------------------------------------------------------------------------------*/

ToggleTabsController.prototype.getDefaults = function() {
    var query = window.location[ 'search' ];
    if( query ) {
        var params = query.substring( 1 ).split( '&' );
        for( var i = 0; i < params.length; i++ ) {
            var pair = params[ i ].split( '=' );
            if( pair[ 0 ] == 'slider' ) {
                return pair[ 1 ];
            }
        }
    }
    return 0;
}

/* -------------------------------------------------------------------------------------------------------------*/

ToggleTabsController.prototype.addPanel = function( panel ) {
    var key = this.getDefaults();

    var newPanel = new TogglePanel( panel );
    this.panels[ this.panels.length ] = newPanel;

    newPanel.attachObserver( 'Choosed', function() {
        this.notify( 'Choosed' );
    }, this );

    if(
        newPanel &&
        newPanel.getTab &&
        newPanel.getTabById
    ) {
        var tab = ( newPanel.getTabById( key ) || newPanel.getTab( 0 ) );
        if( tab ) {
          newPanel.choose( tab );
        }
    }

    return newPanel;
}

/* -------------------------------------------------------------------------------------------------------------*/
/* -------------------------------------------------------------------------------------------------------------*/

TogglePanel = function( element ) {
    TogglePanel.superClass.apply( this, arguments );

    var headersWrap = this.createNode( 'div', false, { 'class': 'headers-wrap' });
    if( this.element.firstChild ) {
        this.element.insertBefore( headersWrap, this.element.firstChild );
    }

    this.headers = this.createNode( 'div', headersWrap, { 'class': 'headers' });
    this.marker = this.createNode( 'span', this.headers, { 'class': 'marker' }, '<span></span>' );

    this.createNode( 'span', headersWrap, { 'class': 'left-side' }, '<span></span>' );
    this.createNode( 'span', headersWrap, { 'class': 'right-side' }, '<span></span>' );

    this.findTabs();

    this.addHandler( this.headers, 'mouseout', function() {
        this.moveMarker( this.selected[ 'header' ] );
    });

    this.setClassName( 'toggled', true );
    this.setTabWidth();

}
TogglePanel.inheritsFrom( TabPanel );

/* -------------------------------------------------------------------------------------------------------------*/

TogglePanel.prototype.getTabById = function( key ) {
    if( key == undefined ) return false;
    for( var i = 0; i < this.tabs.length; i++ ) {
        var tab = this.tabs[ i ];
        if(
            tab &&
            tab.header &&
            tab.header.getElementsByTagName
        ) {
            var link = tab.header.getElementsByTagName( 'A' );
            if(
                link &&
                link[ 0 ] &&
                link[ 0 ][ 'hash' ] == ( '#' + key )
            ) {
                return tab;
            }
        }
    }
    return false;
}

/* -------------------------------------------------------------------------------------------------------------*/

TogglePanel.prototype.addLevel = function() {
    var level = new ToggleLevel( this.headers );
    this.levels[ this.levels.length ] = level;
    return level;
}

/* -------------------------------------------------------------------------------------------------------------*/

TogglePanel.prototype.addTab = function( tab, level ) {
    var newTab = level.addTab( tab );
    this.tabs[ this.tabs.length ] = newTab;

    newTab.attachObserver( 'Choosed', function( params, tab ) {
        this.choose( tab );
    }, this );

    newTab.attachObserver( 'Overed', function( params, tab ) {
        this.moveMarker( tab[ 'header' ] );
    }, this );

    return newTab;
}

/* -------------------------------------------------------------------------------------------------------------*/

TogglePanel.prototype.moveMarker = function( target, speed ) {
    speed = speed || 700;
    var offset = this.offset();
    var targetOffset = this.offset( target );

    $( this.marker ).animate({
        'top': targetOffset[ 'top' ] - offset[ 'top' ] + 'px',
        'left': targetOffset[ 'left' ] - offset[ 'left' ] + 7 + 'px',
        'width': targetOffset[ 'width' ] - 14 + 'px'
    }, {
        'queue': false,
        'duration': speed,
        'easing': 'easeOutElastic'
    });
}

/* -------------------------------------------------------------------------------------------------------------*/

TogglePanel.prototype.setTabWidth = function() {
    var isVisible = true;
    for( var i = 0; i < this.levels.length; i++ ) {
        var level = this.levels[ i ];
        level.setTabWidth();
        if( !level.getTotalWidth() ) {
            isVisible = false;
        }
    }

    if( isVisible ) {
        this.moveMarker( this.selected[ 'header' ] );
    }
}

/* -------------------------------------------------------------------------------------------------------------*/
/* -------------------------------------------------------------------------------------------------------------*/

ToggleLevel = function( target ) {
    ToggleLevel.superClass.apply( this, arguments );
    this.element = this.createNode( 'div', target, { 'class': 'level' });
}
ToggleLevel.inheritsFrom( TabLevel );

/* -------------------------------------------------------------------------------------------------------------*/

ToggleLevel.prototype.setHeaderWidth = function( idx, width ) {
    var tab = this.getTab( idx );
  if(
    tab &&
    tab.setHeaderWidth &&
    width >= 0
  ) {
    this.getTab( idx ).setHeaderWidth( width - 14 );
  }
}

/* -------------------------------------------------------------------------------------------------------------*/
/* -------------------------------------------------------------------------------------------------------------*/
var tabControl
$( function() {
    //if(document.cookie.search('show_tpl=1') != -1){
        tabControl = new TabsTransfer($('.tabs')[0]);
    /*
    }else{
    
        window.simpleTabsController = new SimpleTabsController();
        window.toggleTabsController = new ToggleTabsController();

        window.simpleTabsController.attachObserver( 'Choosed', window.toggleTabsController.setTabWidth, window.toggleTabsController );
        window.toggleTabsController.attachObserver( 'Choosed', window.simpleTabsController.setTabWidth, window.simpleTabsController );
    
    }
    */
});

function TabsTransfer(tab){
    this.tab = $(tab).addClass('tabbed');
    this.createTab();
}

TabsTransfer.prototype.createTab = function(){
    var tabs = this.tabs = this.tab.find('>.tab > h2.header, >.tab > h4.header');
        //var tabs = this.tabs = this.tab.find('h2.header, h4.header');
    if(tabs.length == 0) return;
    
    
    this.header = $('<div class="headers r2 current"></div>');
    this.tab.find('*:first').before(this.header);
    
    var n = tabs.length;
    for(var i = 0; i < n; i++){
        tabs[i].par = tabs[i].parentNode;
        new subTabsTransfer(tabs[i].par, 6);
        $(tabs[i].par).addClass('hidden');
        
        this.header.append(tabs[i]);
        
        $(tabs[i]).click(function(me, i){
            return function(e){
                me.setActive(i);
                e.stopPropagation();
                e.preventDefault();
                return false;
            }
        }(this, i));
    }
    
    var widthTab = this.tab.width();
    var width = parseInt(widthTab/n)
    
    tabs.css('width', width);
    tabs.last().css('width', widthTab - (n-1)*width - 1);
    tabs.last().append('<i class=" corner rt"></i>');
    tabs.first().append('<i class=" corner lt"></i>');
    
    this.tab.append('<i class=" corner lb"></i>');
    this.tab.append('<i class=" corner rb"></i>');
    
    var mas = location.href.match(/tab=([0-9]*)/);
    var tabActive = 0;
    if(mas&&mas.length == 2){
        tabActive = mas[1]||0;
    }
    this.setActive(tabActive);
    
    for(var i = 0; i < n; i++){
        var height = $(tabs[i]).height();
        if(height < 43) $(tabs[i]).find('a').addClass('rh2');
    }
}

TabsTransfer.prototype.setActive = function(n){
    if(!this.tabs[n]) return;
    
    if(this.activeTabNum||this.activeTabNum==0){
        $(this.tabs[this.activeTabNum]).removeClass('selected')
        $(this.tabs[this.activeTabNum].par).addClass('hidden');
    }
    this.activeTabNum = n;
    $(this.tabs[n]).addClass('selected');
    $(this.tabs[n].par).removeClass('hidden');
    
    
    var newTabs = $(this.tabs[this.activeTabNum].par).find('.tabs');
    for(var i = 0; i < newTabs.length; i++){
        if(!newTabs[i].flagTabs){
            new TabsTransfer(newTabs[i]);
            newTabs[i].flagTabs = true;
        }
    }
}

function subTabsTransfer(tab, count){
    this.tab = $(tab).find('div.toggle:first').addClass('toggled');
    this.count = count||6;
    this.createTab();
}

subTabsTransfer.prototype.createTab = function(){
    var me = this;
    var tabs = this.tabs = this.tab.find('>.tab > h3.header').css('white-space', 'nowrap');
    //var tabs = this.tabs = this.tab.find('h3.header').css('white-space', 'nowrap');
    
    tabs.find('a').show();
    
    if(tabs.length == 0) return;
    
    this.headerWrap = $('<div class="headers-wrap"></div>');
    this.header = $('<div class="headers"></div>');
    
    this.headerWrap.append(this.header);
    this.tab.find('*:first').before(this.headerWrap);
    
    var marker = this.marker = $('<span class="marker" style="overflow-x: hidden; overflow-y: hidden;"><span></span></span>');
    this.header.append(marker);
    
    var mas = location.href.match(/slider=([a-z0-9]*)/);
    var tabName = '', tabActive = 0;
    if(mas&&mas.length == 2){
        tabName = mas[1]||'';
    }
    
    var level, tabs_index = 0;
    var n = tabs.length;
    var customLevels = false;
    for(var i = 0; i < n; i++){
        if($(tabs[i]).hasClass('next_line')) {
            level = $('<div class="level"></div>');
            this.header.append(level);
            customLevels = true;
        }
        if(i%this.count == 0 && ! customLevels ){
            level = $('<div class="level"></div>');
            this.header.append(level);
        }
        
        tabs[i].par = tabs[i].parentNode;
        $(tabs[i].par).addClass('hidden');
        level.append(tabs[i]);
        
        $(tabs[i]).click(function(me, i){
            return function(e){
                me.setActive(i);
                e.stopPropagation();
                e.preventDefault();
                return false;
            }
        }(this, i));
        
        $(tabs[i]).bind('mouseover', function(me, i){
            return function(e){
                me.setSlideOver(this);
                return false;
            }
        }(this, i));
        
        if($(tabs[i]).find('a[href*=' + tabName + ']').length > 0 && tabName != ''){
            tabActive = i;
        }
    }
    
    this.headerWrap.bind('mouseout', function(){
        me.setSlideOut();
    });
    
    this.header.append('<span class="left-side"><span></span></span>');
    this.header.append('<span class="right-side"><span></span></span>');
    
    this.setActive(tabActive);
    
    this.setPadding();
    this.setSlideOut();
}

subTabsTransfer.prototype.setActive = function(n){
    if(this.activeTabNum||this.activeTabNum==0){
        $(this.tabs[this.activeTabNum]).removeClass('selected')
        $(this.tabs[this.activeTabNum].par).addClass('hidden');
    }
    this.activeTabNum = n;
    $(this.tabs[n]).addClass('selected');
    $(this.tabs[n].par).removeClass('hidden');
}

subTabsTransfer.prototype.setPadding = function(){
    var me = this;
    this.header.find('.level').each(function(){
        me.setPaddingLevel(this);
    })
}

subTabsTransfer.prototype.setPaddingLevel = function(level){
    var elem = $(level).find('.header').css({paddingLeft: 0, paddingRight: 0});
    var width = 0;
    var n = elem.length;
    for(var i = 0; i < n; i++){
        width += $(elem[i]).width();
    }
    
    var w = $(level).width() - width - 2;
    var padding = parseInt(w/(n*2));
    var paddingLast = w - padding*(n-1)*2;
    var paddinfLastLeft = parseInt(paddingLast/2);
    
    elem.css({'paddingLeft': padding, 'paddingRight': padding});
    elem.last().css({'paddingLeft': paddinfLastLeft, 'paddingRight': paddingLast - paddinfLastLeft});
}

subTabsTransfer.prototype.setSlide = function(elem){
    var marker = this.marker;
    
    this.setAnimate(elem);
}

subTabsTransfer.prototype.setAnimate = function(elem){
    var marker = this.marker;
    
    var left = elem.offsetLeft + 12;
    var top = elem.offsetTop + elem.parentNode.offsetTop - 2;
    var width = elem.offsetWidth - 14;
    
    marker.animate({
        'left': left + 'px',
        'top': top + 'px',
        'width': width + 'px'
    }, {
        'queue': false,
        'duration': 700,
        'easing': 'easeOutElastic'
    });
}

subTabsTransfer.prototype.setSlideOver = function(elem){
    var marker = this.marker; 
    this.setSlide(elem, marker);
}

subTabsTransfer.prototype.setSlideOut = function(){
    if(this.activeTabNum||this.activeTabNum==0){
        this.setAnimate(this.tabs[this.activeTabNum]);
    }
}
