jQuery(document).ready(function() {
   // first, we select the sidebar
   jQuery('#fullsidebar2').each(function() {
      // each child of the sidebar element will be a widget, and will become a tab
      var widgets = jQuery(this).children();
 
      // we'll build the list of titles, starting with the opening tag
      var titleList = '<ul>';
 
      //for each widget in the sidebar:
      widgets.each(function() {
 
         // save the title of the widget
         var widgetTitle = jQuery(this).children('h4').text();
         // then hide it since it will be displayed in the tab
         jQuery(this).children('h4').hide();
 
         // create a new list item for the tab, linking to this widget's id
         var listItem = '<li><a href="#'+jQuery(this).attr('id')+'">'+widgetTitle+'</a></li>';
         // add the list item to the list we're building
         titleList += listItem;
      });
      // close the list now that we're done going through each widget
      titleList += '</ul>';
 
      // add the title list to the beginning of the sidebar
      jQuery(this).before(titleList);
   });
 
   // apply the tabs plugin
   jQuery('#fullsidebar2').tabs();
});
