function prepTabBer(){
  $('.tabbertab h2').hide();
  $('.tabbertab').hide();

  $('.tabber').before('<ul class="tabbernav"></ul>');
  $('.tabbertab h2').each(function(i){
    $(this).parent('.tabbertab').attr('id', 'berid' + i);
    var vis = 'deactive';
    if(i==0){
      vis = 'active';
    }
    $('.tabbernav').append('<li class="' + vis + '"><a href="javascript:void(null);" berid="'+ i + '" title="' + $(this).html() + '">' + $(this).html() + '</a></li>');
    
  });
  $('.tabbertab:first').wrap('<div class="tabberlive"></div>');

  $('.tabbertab:first').show(1, enableTabBer);
}

function enableTabBer(){
  $('.deactive a').bind('click', function(){
    $('.deactive a').unbind('click');
    $(this).blur();
    $('.active').addClass('deactive');
    $('.active').removeClass('active');
    $(this).parent('li').addClass('active');
    var berid = $(this).attr('berid');

    $('.tabberlive .tabbertab').hide(1,function(){
      var oldtab = $('.tabberlive .tabbertab').clone();
      $('.tabberlive').after(oldtab);
      $('.tabberlive').remove();
      $('#berid' + berid).wrap('<div class="tabberlive"></div>');
      $('#berid' + berid).show(1, enableTabBer);
      
    });
  });
};

$(function(){
  prepTabBer();
});
