(function( $ ){
  $.fn.equalHeight = function(minheight) {
    var max = 0;

    this.each(function() {
      max = Math.max(max, $(this).height());
    });

    minheight = typeof minheight != 'undefined' ? minheight : max;

    if (max < minheight) {
      max = minheight
    }

    this.height(max);
  };
})( jQuery );

jQuery(document).ready(function() {
  // equal height for themablocks on homepage
  jQuery('.themablockrow').each(function() {
    jQuery(this).find('.themablock').equalHeight();
  });
  
  //equal height for subnavigation blocks on artikel page
  var maxArtikelColumns = 3;  
  var currentArtikelSummaryRow = 0;
  var currentArtikelSummaryColumn = 0;
  var totalArtikelSummaryRows = 0;
  
  jQuery('.menu-block-2 > ul > li').each(function() {
    if(totalArtikelSummaryRows == 0) {totalArtikelSummaryRows = 1;}  
    jQuery(this).addClass('artikelRow-' + currentArtikelSummaryRow);
    currentArtikelSummaryColumn++;
    if(currentArtikelSummaryColumn == maxArtikelColumns) {
        currentArtikelSummaryRow++;
        currentArtikelSummaryColumn = 0;
        totalArtikelSummaryRows++;
    }
  });
  
  for(i = 0; i <= totalArtikelSummaryRows; i++) {
    jQuery(this).find('.artikelRow-' + i).equalHeight();    
  }
  
});;

