/*
 This script can be included to ensure that the left, middle and right
 columns are all of the same height. The columns will be set to the
 height of the tallest column.
*/

SET_MIDDLE_COLUMN_HEIGHTS = {
    equalHeight : function() {
        var group = $("div#middle").children("div").not("#footer").filter(":visible");
        var tallest = 0;
        group.each(function() {
            var testCSS = $(this).css("cssText");
            if( testCSS ) {
                if( testCSS.indexOf("important") != -1 ) {
                    // Skip this element, since it's height has been set by this script once already
                    return;
                }
            }
            var thisHeight = $(this).innerHeight();
            if(thisHeight > tallest) {
                tallest = thisHeight;
            }
        });
        
        group.each(function() {
            if( !$(this).hasClass("main")) {
                var padding = $(this).innerHeight() - $(this).height();
                var heightMinusPadding = tallest - padding;
                // we cannot just call $(this).height(), since the stylesheets define
                // height with "!important".
                
                $(this).css("cssText",$(this).css("cssText") + ";height: " + heightMinusPadding + "px !important;" );
            }
        });
        
        
    }
    
    
}



// set the column heights when the page has finished loading
$(document).ready(SET_MIDDLE_COLUMN_HEIGHTS.equalHeight);

// set the column heights when an ajaxcall has finished, in case the content of the
// page has been modified.
$(document).ajaxStop( SET_MIDDLE_COLUMN_HEIGHTS.equalHeight );

// set the colums heights when the browser window is resized.
$(window).resize( SET_MIDDLE_COLUMN_HEIGHTS.equalHeight );