Try this:
$(function(){
var n = $('header').height();
/*hide the navbar*/
$('#nav').hide();
$(window).scroll(function(){
if($("body").scrollTop() > n) {
//adjust you nav offset here.
$('#nav').show();
}
else $('#nav').hide();
});
});
Info about query scroll can be consulted here: http://api.jquery.com/scroll/
You must eval that condition every time the scroll moves, so that your header appears or disappears accordingly.