$(function()
{
  // 'Close' all dd's in the faq_list dl on initial window load
  $(".faq_list dd").addClass("hide");
  
  // Add an <a> to each 'dt' (FAQ question)
  $(".faq_list dt").each(function()
  {
    $(this).wrapInner("<a href=\"#\"></a>");
  });
  
  $(".faq_list dt a").each(function()
  {
    $(this).click(function()
    {
      //
      // Needs the 'dd' containing the answer to be the
      // next sibling of the 'dt' containing the question.
      // We're "in" an <a>, so parent() gets the 'dt' and
      // next() gets the 'dd'.
      //
      $(this).parent().next().toggleClass("hide");
      return false;
    });
  });
  
  // Add the open/close all links (not needed if JS not present, so only added by JS)
  $("#faq_open_close_all").append(
      "<p>Click on a question to show the answer, click on it again to hide the answer, or use the Show/Hide buttons to " +
      "show or hide all answers at once.</p>" +
      "<p><a class=\"faq_all_button\" id=\"faq_open_all\" href=\"#\">Show All Answers</a>&nbsp;&nbsp;<a class=\"faq_all_button\" id=\"faq_close_all\" href=\"#\">Hide All Answers</a></p>");
      
  $("#faq_open_all").click(function()
  {
    $(".faq_list dd").removeClass("hide");
    return false;
  });
     
  $("#faq_close_all").click(function()
  {
    $(".faq_list dd").addClass("hide");
    return false;
  });
   
});
