/* accordion functionality */
//Extension functie om de oorpsronkelijke hoogte van een item te bewaren.
$.fn.resetHeight = function(initial) {
  this.each(function() {
    if (initial) {
      this.originalHeight = this.offsetHeight + "px";
    }
    $(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
$.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
  };
  
  $("h4", this).filter(function() {
    //Alleen <h3>'s die gevolgd worden door een <div>.
    return $($(this).next().get(0)).is("div");
  }).click(function() {
    if ($(this).hasClass("open")) {
      //Class "open" uit de <h3> en de <div> verwijderen, eventuele lopende animatie stoppen, en verbergen.
      $(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){
        $(this).parents("div.acc").find("div.container").stop().hide().removeClass("open").resetHeight().css(resetSettings).prev().removeClass("open");
      }
      $(this).addClass("open").next().addClass("open").each(function() {
        //$(this).slideDown("slow");
        $(this).animate(animSettings, "slow", "swing");
      });
    }
    window.location.href = "#open" + this.id;
    return false;
  });
  return this;
};
