﻿$(function() {

	$.fn.reverse = [].reverse;

	$('.menu a').click(function() {
		$('.menu a').removeClass('current');
		$(this).addClass('current').blur();
		$.scrollTo('a[name=' + $(this).attr('href').replace(/^.*\#/i, '') + ']', 800);
	});
	
	$('.top').click(function() {
		$.scrollTo(0, 800);
	});

	$(window).scroll(function() {
		var vCenter = $(window).scrollTop() + $(window).height() / 2 - 3 * 32; // ignore 5em H1 top border
		$('a[name]').reverse().each(function() {
			if ($(this).offset().top <= vCenter) {
				$('.menu a').removeClass('current');
				$('.menu a[href$=#' + $(this).attr('name') + ']').addClass('current');
				return false;
			}
		});
	}).scroll();

	$('a').click(function() {
 		$(this).blur();
	});

});
