/* Use JQuery to make all currently rendered sidebarblock's content hide/show when you click the
 * header. Using .toggle() here would have been nice, but we can't set which function in the toggle
 * cycle to use first, so we have to have an if/else instead.
 */
jQuery('.sidebarheader, .ml_sidebarheader').click(function() {
  // Find the content associated with this header.
  contentdiv = jQuery(this).siblings('.sidebarcontent');

  jQuery(this).toggleClass('sidebarheaderclosed');

  // If we're not hidden, slide up & hide, and save that we've hidden this box in our JSON cookie.
  if (contentdiv.css('display') != 'none')
  {
    contentdiv.slideUp();
    delete sidebar_prefs.data[jQuery(this).parent().attr('id')];
    sidebar_prefs.save();
  }
  // If we are hidden, unhide & slide down, and save that we've unhidden this box in our JSON cookie.
  else
  {
    contentdiv.slideDown();
    sidebar_prefs.data[jQuery(this).parent().attr('id')] = true;
    sidebar_prefs.save();
  }
});