(function ($) {

/**
 * 'Sticky Footer' by Peter Anderson
 * Inspired by: http://www.drupalcoder.com/blog/cross-browser-sticky-footer-with-fluid-height-using-jquery
 */
Drupal.behaviors.stickyFooter = {
  attach: function(context, settings) {

    // Set 'footer' element
    var footer = $('#bottom');

    // Make footer sticky on page load and when resizing the window
    makeSticky(footer);
    $(window).resize(function() {
      makeSticky(footer);
    });

  }
};

function makeSticky(footer) {
  // Reset the footer's top margin to correctly calculate the heights
  footer.css('margin-top', '0');

  // Get body and window heights
  var bodyHeight = $(document.body).height();
  var windowHeight = $(window).height();

  if (bodyHeight < windowHeight) {
    // Calculate the difference in heights
    var diff = windowHeight - bodyHeight;

    // Set the footer's top margin
    footer.css('margin-top', diff);
  }
}

})(jQuery);
;

