jQuery(document).ready(function($){
  // console.log dummy if not defined
  if (typeof console === "undefined" || typeof console.log === "undefined") {
    console = {log: function(){}};
  }

  function positionKeyfacts() {
    var position = $('.scroll_container').offset();
    var offset = $('.scroll_container .pinned').length ? -40 : 20;

    if ($(window).height() < $('.scroll_container .scroller').height()) {
      $('.scroll_container .scroller').removeClass("pinned");
    }
    else {
      if (position.top - offset < $(document).scrollTop()) {
        $('.scroll_container .scroller').addClass("pinned");
      }
      else {
        $('.scroll_container .scroller').removeClass("pinned");
      }
    }
  }

  // register keyfacts pinning
  if (!(/iPhone|iPod/i.test(navigator.userAgent)) && $('.keyfacts').length) {
    $(window).bind({
      resize: positionKeyfacts,
      scroll: positionKeyfacts
    });
  }
});

