var setBodyHeight = function(){
  var header    = $('#pageHeader'),
      body      = $('#pageBody'),
      footer    = $('#pageFooter'),
      viewport  = $(window);
    
  var headerHeight    = $(header).outerHeight(),
      bodyHeight      = $(body).outerHeight(),
      footerHeight    = $(footer).outerHeight(),
      viewportHeight  = $(viewport).height();
    
  var newBodyHeight  = (viewportHeight - (headerHeight + footerHeight)) - 40;

  if((bodyHeight - 40) < newBodyHeight){
    if($.browser.msie && $.browser.version=="6.0"){
      $(body).css({ height: newBodyHeight });
    } else {
      $(body).css({ minHeight: newBodyHeight });
    }
  }
}

var equalizeSectionHeights = function(extraSection){
  var sections  = $('.section.equalize');
  
  var sectionHeights = $.map(sections, function(section, i){
    return $(section).height();
  });
  
  var maxSectionHeight = Math.max.apply(null, sectionHeights);
  
  $(sections).height(maxSectionHeight);
}

$(document).ready(function(){  
  setBodyHeight();
  equalizeSectionHeights();
});

$(window).resize(function(){ 
  setBodyHeight(); 
});