var oneitHeaderIsFixed       = false;
var oneitHeaderFixedDisabled = false;
var oneitHeaderWrapTopMargin = 10;
var oneitHeaderWrapBorders   = 2;

function fixedMenuSetup()
{
    fixedMenuAdjust();
}

// put into script... (possibly rename)
function fixedMenuAdjust()
{
    if(oneitHeaderFixedDisabled)
    {
        return;
    }

    var scrollTop = $(window).scrollTop();
    var fixFromHeight = $('#header_wrap').height(); // offsetTop

    if(fixFromHeight == null || fixFromHeight <= 0)
    {
        oneitHeaderFixedDisabled = true;
    }

    if(scrollTop >= fixFromHeight && !oneitHeaderIsFixed) 
    {
        var newMargin = ($('#pageHeader').height() + oneitHeaderWrapTopMargin + oneitHeaderWrapBorders) + "px";

        oneitHeaderIsFixed = true;
        $('#pageHeader').addClass('pageHeaderFixed');
        $('.body_wrapper').css("margin-top", newMargin);
        $('#pageHeader_topLink').show();
    }
    else if(scrollTop <= fixFromHeight && oneitHeaderIsFixed)
    {
        oneitHeaderIsFixed = false;
        $('#pageHeader').removeClass('pageHeaderFixed');
        $('.body_wrapper').css("margin-top", "0px");
        $('#pageHeader_topLink').hide();
    }
}

$(window).resize(fixedMenuAdjust);
$(window).scroll(fixedMenuAdjust);
$(window).load(fixedMenuSetup);