/************************************************************ 
On pages where the viewport is taller than the page content, this function
ensures that the footer is positioned at the bottom of the viewport.

The original code comes from Bobby van der Sluis's article, Exploring
Footers, at A List Apart (http://www.alistapart.com/articles/footers). It
has been modified to fit with our template.

You will find in the article a couple of other CSS-based methods for gluing the
footer to the bottom of the page. We have had inconsistent success with
CSS-based techniques, however. The JavaScript/DOM method presented here
tends to be more cross-browser compatible.
***********************************************************/

/* Find the height of the viewport */
function getWindowHeight() {
  var windowHeight = 0;
  if (typeof(window.innerHeight) == 'number') {
    windowHeight = window.innerHeight;
  }
  else {
    if (document.documentElement && document.documentElement.clientHeight) {
      windowHeight = document.documentElement.clientHeight;
    }
    else {
      if (document.body && document.body.clientHeight) {
        windowHeight = document.body.clientHeight;
      }
    }
  }
  return windowHeight;
}

/* Set the footer to position at the bottom of viewport when the viewport is taller than the content */
function setFooter() {
  if (document.getElementById) {
    var windowHeight = getWindowHeight();
    if (windowHeight > 0) {
      var contentHeight = document.getElementById('wrapper').offsetHeight;
      var footerElement = document.getElementById('footer');
      if (windowHeight - contentHeight >= 0) {
        footerElement.style.position = 'relative';
        footerElement.style.top = (windowHeight - contentHeight) + 'px';
      }
      else {
        footerElement.style.position = 'static';
      }
    }
  }
}

/* Call funtion after the page loads or is resized */
window.onload = function() {
  setFooter();
}
window.onresize = function() {
  setFooter();
}
