$(function () {
  
  var msie6 = $.browser == 'msie' && $.browser.version < 7;
  
  if (!msie6) {
		var top = $('.aside-fixed').offset().top - parseFloat($('.aside-fixed').css('margin-top').replace(/auto/, 0));
		var sfixed = true;
		
	var viewportHeight = $(window).height();
	var sidebarHeight = $('.aside-fixed').height();
		
		if ((viewportHeight-20) < sidebarHeight) {
				$('.aside-fixed').removeClass('fixed');
				var sfixed = false;
		} else {
		$(window).scroll(function () {
		  // what the y position of the scroll is
		  var y = $(this).scrollTop();
		  
		  // whether that's below the form
		  if (y >= top-20) {
			// if so, ad the fixed class
			if (sfixed){
			$('.aside-fixed').addClass('fixed');
			}
		  } else {
			// otherwise remove it
			$('.aside-fixed').removeClass('fixed');
		  }
		});
			
		}
	
  }  
  
});