$(function() {
  w = $(window);
  p = $('#page-controls');

  p.data('top',p.position().top);
   
  w.scroll(function() {
     if( w.scrollTop() > (p.data('top')+p.height()) )
         p.removeClass('fixed_on_bottom').addClass('fixed_on_top');
     else if( (w.scrollTop()+w.height()) < p.data('top') )
         p.removeClass('fixed_on_top').addClass('fixed_on_bottom');
     else
         p.removeClass('fixed_on_bottom').removeClass('fixed_on_top');
  });

  w.scroll();
});

