$(document).ready(function(){
var stickyTop = $(".sticky_sidebar").offset().top;
$(window).scroll(function() {
var windowTop = $(window).scrollTop();
var minusHeight = ( $(".sticky_col").height() + $(".sticky_col").offset().top ) - ( $(".sticky_sidebar").height() + $('#hcontainer').height() );
if (stickyTop < windowTop && minusHeight > windowTop) {
console.log('yes');
$('.sticky_sidebar').css({
'position': 'fixed',
'top': $('#hcontainer').height() + 25 + 'px',
'width': $('.sticky_sidebar').outerWidth() + 'px'
});
} else {
console.log('no');
$('.sticky_sidebar').css({
'position': 'relative',
'top': 0,
'margin-top': '0 !important'
});
}
});
});