$(function() {
    
  /**
   * Switchable tabs for the front page news.
   */
  $("#tabbed-news div#mini-panel-tabbed_news div.panel-pane").slice(1).hide();
  $("#tabbed-rmm div#mini-panel-tabbed_rmm div.panel-pane").slice(1).hide();
  $("#tabbed-news").prepend("<div id='tabs'><ul id='menu'></ul></div>");
  $("#tabbed-rmm").prepend("<div id='tabs2'><ul id='menu'></ul></div>");

  $("#tabbed-news div#mini-panel-tabbed_news div.panel-pane").each(function() {
    var target = $(this).attr('id');
    var $h2 = $(this).children('h2');
    $h2.hide();

    var tab = '<li><a href="#' + target + '" target="#' + target + '">' + $h2.html() + '</a></li>';
    $("#tabs ul").append(tab);
  });
  
  $("#tabbed-rmm div#mini-panel-tabbed_rmm div.panel-pane").each(function() {
    var target = $(this).attr('id');
    var $h2 = $(this).children('h2');
    $h2.hide();

    var tab = '<li><a href="#' + target + '" target="#' + target + '">' + $h2.html() + '</a></li>';
    $("#tabs2 ul").append(tab);
  });
  
  $("#tabs a").eq(0).addClass('selected');
  $("#tabs2 a").eq(0).addClass('selected');
  $("#tabs a").click(function() {
    $("#tabs a.selected").removeClass('selected');
    $(this).addClass('selected');
    $("#tabbed-news div#mini-panel-tabbed_news div.panel-pane").hide();
    $($(this).attr('target')).show();
    return false;
  });
  $("#tabs2 a").click(function() {
    $("#tabs2 a.selected").removeClass('selected');
    $(this).addClass('selected');
    $("#tabbed-rmm div#mini-panel-tabbed_rmm div.panel-pane").hide();
    $($(this).attr('target')).show();
    return false;
  });
  
});
