function adFollow(fixed_ad,content_container){ var followAdH = $(fixed_ad).height(); if(followAdH >= 600){ var ad_gutter_h = content_container.outerHeight(); var ad_gutter_top = fixed_ad.parent().offset().top; var ad_gutter_bottom = ad_gutter_top + ad_gutter_h; var ad_unit_top = fixed_ad.offset().top; var ad_unit_h = fixed_ad.outerHeight(); var window_pos = $(window).scrollTop(); var window_h = $(window).height(); if((window_pos >= ad_gutter_bottom - ad_unit_h)){ fixed_ad.css({ "position":"relative", "top": ad_gutter_bottom - ad_gutter_top - ad_unit_h + "px" }); } else if((window_pos >= ad_gutter_top && window_h >= ad_unit_h)){ fixed_ad.css({ "position":"fixed", "top": 0 }); if (jQuery.browser.msie && $.boxModel==false) { fixed_ad.css({ "position":"absolute", "top": window_pos + "px" }); } } else { fixed_ad.css({ "position":"relative" }); if (jQuery.browser.msie && $.boxModel==false) { fixed_ad.css({ "top": "" }); } } }/*end height check*/ } $(window).resize(function(){adFollow($(".ad.sponsored"),$("#content"));}); $(window).scroll(function(){adFollow($(".ad.sponsored"),$("#content"));});