function adjustLayout()
{
  if(!adjusting) {
    adjusting = true;

    var content = $("#content-inner");
    var left = $("#sidebar-left");
    var right = $("#sidebar-right");

    $("#footer").hide();

    // Reset heights to force a clean resize
    content.height("");
    left.height("");
    right.height("");

    // Get natural heights (including margins)
    var cHeight = content.outerHeight(true);
    var lHeight = left.outerHeight(true);
    var rHeight = right.outerHeight(true);

    // Get overage due to margins
    var cOverage = cHeight - content.height();
    var lOverage = lHeight - left.height();
    var rOverage = rHeight - right.height();

    // Find the maximum height
    var maxHeight = Math.max(cHeight, Math.max(lHeight, rHeight));

    // Assign maximum height to all columns
    if(cHeight < maxHeight)
      content.height(maxHeight - cOverage);
    left.height(maxHeight - lOverage);
    right.height(maxHeight - rOverage);

    // Show the footer
    $("#footer").show();

    adjusting = false;
  }
}

var adjusting = false;
var lastContentHeight;
var lastHeaderHeight;
window.onload = function()
{
  adjustLayout();
  $(window).resize(adjustLayout);

  lastContentHeight = $("#content-area").height();
  lastHeaderHeight = $("#content-header").height();
  setInterval(
    function() {
      contentHeight = $("#content-area").height();
      headerHeight = $("#content-header").height();
      if(contentHeight != lastContentHeight || headerHeight != lastHeaderHeight) {
        adjustLayout();
        lastContentHeight = contentHeight;
        lastHeaderHeight = headerHeight;
      }
    },
    300
  );
}

