Simple show/hide JQuery code not working on page load, no errors and working in firebug

Simple show/hide JQuery code not working on page load, no errors and working in firebug

Hi there,

I'm trying to get some side navigation to pop up when the top navigation bar goes out of view. When I load my page it does not work (locally or on a server). However, when I load the page and execute the code from the console in firebug, I get no errors and it works perfectly. Any idea what could be going wrong? A note: this page is called index.php, not index.html... there is no php on the page as of yet, I just mention that in case it would make a difference.

My code is below:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript">

$(document).ready(function() {
   $(window).scroll(function() {
     doScrollThing();
   });
 });

function doScrollThing() {
    if (isShowing($("#nav"))) {
        $("#lhn").fadeOut();
    } else {
        $("#lhn").fadeIn();
    }
}

function isShowing(elem) {
    // this function from: http://www.weask.us/entry/jquery-check-element-visible-scroling
    var docViewTop = $(window).scrollTop();
    var docViewBottom = docViewTop + $(window).height();

    var elemTop = $(elem).offset().top;
    var elemBottom = elemTop + $(elem).height();

    return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom));
}

</script>