(function( $ ){
  $( function( ){
    //debugger;
    var tabButtons = $('<div class="tab-buttons"></div>').prependTo( '.most-popular' );
    var tabBodies = $( '.most-popular > ul > li' );
    
    tabBodies.find( 'h4' )
      .each( function( ){
        var $this = $( this );
        var button = $( '<span class="tab-button">'+$this.text( )+'</span>' ).appendTo( tabButtons );
        button.data( 'tab-body', $this.parent( ) );
      })
      .hide( );
    
    tabButtons.click( function( event ){
      //debugger;
      var el = $( event.target );
      var body = el.data( 'tab-body' );
      if( body ){
        tabBodies.hide( );
        body.show( );
        tabButtons.children( ).removeClass( 'current-tab' );
        el.addClass( 'current-tab' );
      }
    })
    .find('.tab-button:first').click( );
    
    
      
    
  });
})( jQuery );