// ###################################
// ################# FAQ #############
// ###################################

// FAQ openklapper
function setupFAQ() {

  // Check whether a hash is present, if so, fold open that answer
  var hasHash = document.location.href.indexOf("#");
  var urlAnswer = (hasHash > -1) ? document.location.href.substring(hasHash+1) : '';
  if ((urlAnswer != '') && $(urlAnswer)) {
    resetFAQ($(urlAnswer));
    Element.addClassName($(urlAnswer).parentNode, "answered");
  } else {
    resetFAQ();
  }

  var nl = $$("p.question a");
  nl.each(function(n) {
    var id = n.href.substr(n.href.lastIndexOf('#') + 1);
    n.href = "javascript:openQuestion('" + id + "');";
  });
}

function resetFAQ(excluding) {
  var nl = $$("p.question");
  nl.each(function(n) {
    Element.removeClassName(n.parentNode, "answered");
  });
  nl = $$("div.answer");
  nl.each(function(n) {
    if (n != excluding) Effect.BlindUp(n, {duration: 0.05});
  });
}

function openQuestion(id) {
  var n = $(id);
  if (!n) return;
  if (n.style.display != "none") {
    resetFAQ();
    return;
  }
  resetFAQ(n);
  Element.addClassName(n.parentNode, "answered");
  Effect.BlindDown(n, {duration: 0.05});
}

loader.schedule("faq", setupFAQ);
