jQuery(function($) { var pos; var w; var h; var ad; var offset; var load_comp; $(window).load(function () { load_comp = 1; }); $(window).scroll(function () { if(!load_comp){ return; } if($('#left').height() >= $('#center').height()){ return; } ad = $('#slide_ad'); offset = ad.offset(); if($(window).scrollTop() > offset.top) { if(!pos){ pos = offset.top; w = ad.width(); h = ad.height(); } ad.addClass('fixed'); ad.css({ width:w, height:h }); } else { if(!pos){ return; } if(pos > offset.top){ ad.removeClass('fixed'); pos = undefined; } } }); });