document.observe('dom:loaded', function () {
  if ($('footer')) {
    helper_bindFooter();
    Event.observe(window, 'resize', helper_bindFooter);
  }
});

function helper_bindFooter ()
{
  if ($('footer')) {
    $('footer').setStyle({
      margin: '0',
      padding: '0',
      width: '100%',
      textAlign: 'center'
    });

    var h = document.viewport.getHeight();      // height of viewport
    var f = $('footer').getHeight();            // height of footer
    var c = $('top').getHeight() + $('bottom').getHeight();            // height of nav, headers, and content

    var d = h - c;                        // difference

    if (d > 2*f) {                                    // if space
      $('footer').setStyle({                          //   doStick footer
        position: 'absolute',
        bottom: '0'
      });
    }
    else {                                            // else
      $('footer').setStyle({                          //   unStick footer
        position: 'static',
      });
    }
  }
}

