$(function () {  
  var msie6 = $.browser == 'msie' && $.browser.version < 7;
  if (!msie6) {

    var divh = $('#floater').height();
    var conth = $('#main_section').height();
    var bottomStop = $("#main_section").offset().top + conth;

   var top = $('#floater').offset().top - parseFloat($('#floater').css('margin-top').replace(/auto/, 0));
    $(window).scroll(function (event) {
      // what the y position of the scroll is
      var y = $(this).scrollTop();
      
      if(y + divh  >= bottomStop) {        
        $('#floater.fixed').css('top', (bottomStop - divh - y) + "px");
      } else if (y >= top) {
        // if so, add the fixed class
        $('#floater').addClass('fixed');
        $('#floater.fixed').css('top', "0px");
      } else {
        // otherwise remove it
        $('#floater').removeClass('fixed');
      }
    });
  }  
});

