$( function() {

  var matchedPane = $("#" + $("#accordion-wrapper").find("a.matched").eq(0).attr("rel"));
 $("#accordion-wrapper").children(".accordion-pane").not($(matchedPane)).css("display", "none");

  $("#accordion-wrapper").children(".accordion-key").click( function(e) {
          var targetPane = document.getElementById($(this).attr("rel"));
          var visible = $(targetPane).css("display");
          $("#accordion-wrapper").children("a.active").not(this).removeClass("active");

          if (visible == "none") {
                  $(this).addClass("active");
                  $(targetPane).slideDown();
          } else {
                  $(targetPane).slideUp();
                  $(this).removeClass("active");
          }
          $("#accordion-wrapper").children(".accordion-pane").not(targetPane).slideUp();
          e.preventDefault();
  });

});
