(function($){
	
	"use strict";

	function pageScroll() {
		var scrollPos = $(window).scrollTop();

		$('.nav li').each(function (index, el) {
	        var currLink = $(this),
	        	currentPos = $('.'+ currLink.data('anchor') ).offset().top - 200;

	        if( scrollPos >= currentPos ) {
	        	$('.nav li').removeClass('current');
	        	currLink.addClass('current');
	        }
	        else {
	        	currLink.removeClass('current');
	        }
	    });
	}

	$(document).ready(function($) {

		pageScroll();

		$('.nav').on('click', 'li', function(e) {
			e.preventDefault();

			var $self = $(this),
				anchor = $self.data('anchor'),
				scrollPos = $('.'+anchor).offset().top - 50;
				
			$('html, body').animate( {scrollTop: scrollPos}, 800 );
		});
	});

	$(window).scroll(function(e) {
		e.preventDefault();

		pageScroll();
		
	});

})(jQuery);