/*
 * Image size corrigator.
 *
 * This script can be used change the height of a containing div if one
 * absolutely positioned element in it is higher.
 * (c) 2005-2006 Oliver Klee, http://www.oliverklee.de/
 *
 * This script is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * The GNU General Public License can be found at
 * http://www.gnu.org/copyleft/gpl.html.
 */

/**
 * Changes the size of the element with the ID 'content'
 * if the element 'column-left' is higher than 'content' plus an offset.
 */
function corrigateSizes() {
  // If our browser doesn't support the necessary DOM stuff, bail out.
  if (document.getElementById) {
    var columnLeft = document.getElementById('column-left');
    var columnContent = document.getElementById('content');

    var heightLeft = getHeight(columnLeft);
    var heightContent = getHeight(columnContent);
    /** the number of pixel that should be added to content's height
     *  so that the left column fits beautifully */
    var offset = 37;

    if ((heightLeft - offset) > heightContent) {
      var newHeight = heightLeft - offset;

      columnContent.style.height = newHeight + 'px';
    }
  }
}

/**
 * Returns the computed height (in px) for a given DOM element.
 *
 * @param domElement the element for which the height should be looked up
 *
 * @return int the height of the element in px (without the "px" unit at the end)
 */
function getHeight(element) {
  var result = 0;

  if (document.defaultView && window.getComputedStyle) {
    result = document.defaultView.getComputedStyle(element, '').getPropertyValue('height');
  } else if (element.currentStyle) {
    result = element.offsetHeight;
  }

  return parseInt(result);
}

