And here's how without jquery (UPDATE: see other answers where you can now do this with CSS only)
var startProductBarPos=-1;_x000D_
window.onscroll=function(){_x000D_
var bar = document.getElementById('nav');_x000D_
if(startProductBarPos<0)startProductBarPos=findPosY(bar);_x000D_
_x000D_
if(pageYOffset>startProductBarPos){_x000D_
bar.style.position='fixed';_x000D_
bar.style.top=0;_x000D_
}else{_x000D_
bar.style.position='relative';_x000D_
}_x000D_
_x000D_
};_x000D_
_x000D_
function findPosY(obj) {_x000D_
var curtop = 0;_x000D_
if (typeof (obj.offsetParent) != 'undefined' && obj.offsetParent) {_x000D_
while (obj.offsetParent) {_x000D_
curtop += obj.offsetTop;_x000D_
obj = obj.offsetParent;_x000D_
}_x000D_
curtop += obj.offsetTop;_x000D_
}_x000D_
else if (obj.y)_x000D_
curtop += obj.y;_x000D_
return curtop;_x000D_
}
_x000D_
* {margin:0;padding:0;}_x000D_
.nav {_x000D_
border: 1px red dashed;_x000D_
background: #00ffff;_x000D_
text-align:center;_x000D_
padding: 21px 0;_x000D_
_x000D_
margin: 0 auto;_x000D_
z-index:10; _x000D_
width:100%;_x000D_
left:0;_x000D_
right:0;_x000D_
}_x000D_
_x000D_
.header {_x000D_
text-align:center;_x000D_
padding: 65px 0;_x000D_
border: 1px red dashed;_x000D_
}_x000D_
_x000D_
.content {_x000D_
padding: 500px 0;_x000D_
text-align:center;_x000D_
border: 1px red dashed;_x000D_
}_x000D_
.footer {_x000D_
padding: 100px 0;_x000D_
text-align:center;_x000D_
background: #777;_x000D_
border: 1px red dashed;_x000D_
}
_x000D_
<header class="header">This is a Header</header>_x000D_
<div id="nav" class="nav">Main Navigation</div>_x000D_
<div class="content">Hello World!</div>_x000D_
<footer class="footer">This is a Footer</footer>
_x000D_