/* accordion functionality */
//Extension functie om de oorpsronkelijke hoogte van een item te bewaren.
$jq.fn.resetHeight = function(initial) {
  this.each(function() {
    if (initial) {
      this.originalHeight = this.offsetHeight + "px";
    }
    $jq(this).height(this.originalHeight);
  });
  return this;
};

//Extension functie voor in- en uitklappen van FAQs
// @param autoclose : true (default)/false. On false any already open acc item will not be closed on opening the next
$jq.fn.accSlider = function(autoclose) {
  if(autoclose == undefined || autoclose != false){
    autoclose = true;
  }
  var animSettings = { 
    marginTop: "4px",
    marginBottom: "8px",
    height: "show"
  };
  var resetSettings = {
    marginTop: 0,
    marginBottom: 0
  };
  
  $jq("h4", this).filter(function() {
    //Alleen <h3>'s die gevolgd worden door een <div>.
    return $jq($jq(this).next().get(0)).is("div");
  }).click(function() {
    if ($jq(this).hasClass("open")) {
      //Class "open" uit de <h3> en de <div> verwijderen, eventuele lopende animatie stoppen, en verbergen.
      $jq(this).removeClass("open").next().stop().hide().removeClass("open").resetHeight().css(resetSettings);
    }
    else {
      //Class "open" aan de <h3> en de <div> toevoegen en weergeven.
      if(autoclose){
        $jq(this).parents("div.acc").find("div.container").stop().hide().removeClass("open").resetHeight().css(resetSettings).prev().removeClass("open");
      }
      $jq(this).addClass("open").next().addClass("open").each(function() {
        //$(this).slideDown("slow");
        $jq(this).animate(animSettings, "slow", "swing");
      });
    }
    window.location.href = "#open" + this.id;
    return false;
  });
  return this;
};

