this will do it
$(document).scroll(function(){
var el = $('body');
var top = $(el).offset().top - $(document).scrollTop();
if (top < 5){
var term = $('#q').val();
$('p').highlight(term);
}
});