﻿matchColumns=function(my_class, maxHeight){ 
     var divs,contDivs,maxHeight,divHeight,d; 
     // get all <div> elements in the document 
     divs=document.getElementsByTagName('div'); 
     contDivs=[];  
     if (!my_class) {
        my_class = 'column';
     }
     my_regex = new RegExp('(.* |^)' + my_class + '( .*|$)');
     // iterate over all <div> elements in the document
     for(var i=0;i<divs.length;i++){ 
          // make collection with <div> elements with class attribute 'container' 
          if(my_regex.test(divs[i].className)){ 
                d=divs[i]; 
                contDivs[contDivs.length]=d;
                // reset height
                d.style.height = "auto";
          } 
     } 
     for(var i=0;i<contDivs.length;i++){ 
        // determine height for <div> element 
        if(contDivs[i].offsetHeight){ 
             divHeight=contDivs[i].offsetHeight; 
            } 
        else if(contDivs[i].style.pixelHeight){ 
             divHeight=contDivs[i].style.pixelHeight;
         } 
        
        // calculate maximum height 
        maxHeight=Math.max(maxHeight,divHeight); 
     } 
     
     for(var i=0;i<contDivs.length;i++){
          contDivs[i].style.height=maxHeight + "px"; 
     }
 }

 matchColumnsByRow = function(my_class, maxHeight, maxColumn) {
     if (maxColumn == undefined)
         matchColumns(my_class, maxHeight);
     var divs, contDivs, maxHeight, divHeight, d;
     // get all <div> elements in the document 
     divs = document.getElementsByTagName('div');
     contDivs = [];
     if (!my_class) {
         my_class = 'column';
     }
     my_regex = new RegExp('(.* |^)' + my_class + '( .*|$)');
     // iterate over all <div> elements in the document
     for (var i = 0; i < divs.length; i++) {
         // make collection with <div> elements with class attribute 'container' 
         if (my_regex.test(divs[i].className)) {
             d = divs[i];
             contDivs[contDivs.length] = d;
             // reset height
             d.style.height = "auto";
         }
     }
     for (var i = 0; i < contDivs.length; i++) {
         // determine height for <div> element 
         if (contDivs[i].offsetHeight) {
             divHeight = contDivs[i].offsetHeight;
         }
         else if (contDivs[i].style.pixelHeight) {
             divHeight = contDivs[i].style.pixelHeight;
         }

         // calculate maximum height 
         maxHeight = Math.max(maxHeight, divHeight);

         if ((i + 1) % maxColumn == 0) {
             for (var x = 0; x < maxColumn; x++) {
                 contDivs[i - x].style.height = maxHeight + "px";
             }
             maxHeight = 0;
         }
     }
 }