var $block = $('nav'), position;
$(window).on('scroll resize', function(){
position = $block.offset().top
if ($(window).scrollTop() > position) {
$block.addClass('fixed');
} else {
$block.removeClass('fixed');
}
});