Because you are inside the .scroll()
function which gets fired everytime the page is scrolled, it will be going to your else condition and displaying the navbar each time because of this line:
$('#nav-container').css({display: 'block'});
Remove this line and it should work as expected.