$(function() {

  $(window).scroll(function() {
    var $window      = $(this),
        headerHeight = $('header').outerHeight();

    if ($window.scrollTop() >= headerHeight) {
      $('nav ul').css({
        position: 'fixed',
        top: '21px'
      });
    } else if ($window.scrollTop() < headerHeight) {
      $('nav ul').css({
        position: 'relative',
        top: 0
      });
    }
  });

  $('nav a').click(function() {
    var targetY = $($(this).attr('href')).position().top - 10;
    $('body').animate({scrollTop : targetY}, 1000);
    return false;
  });

});


