$(function(){
	var loc = '' + window.location;
	loc = loc.split('#');
	if ( loc.length <= 1 ) {
		$("html,body").animate({scrollTop: $('#about').offset().top},'slow');
		$("nav ul li a").removeClass("active").filter(":first").addClass('active');
	}
	else {
		$("nav ul li a").each(function(){
			if ( $(this).attr("href") == '#' + loc[1] ) 
				$(this).addClass("active");
		});
	}
		
	$("footer").css("paddingBottom", $(document).height() / 2);
	$("nav ul li a").click(function(){
		$("html,body").animate({scrollTop: $( $(this).attr('href') ).offset().top},'slow');
		$("nav ul li a").removeClass('active');
		$(this).addClass('active');
	});
	$("a[href^=#]").click(function(){
		$("html,body").animate({scrollTop: $( $(this).attr('href') ).offset().top},'slow');
		$("nav ul li a").removeClass('active');
		$("nav ul li a[href=" + $(this).attr("href") + "]").addClass('active');
	});
	
	$("a[rel=external]").each(function(){
		$(this).attr('target', '_blank');
	});

	/* Email Encrypt */
	$(".mask").each(function(){
		var ats, dots, address, i;
		ats = [ ' at ', ' (at) ', ' [at] ' ];
		dots = [ ' dot ', ' (dot) ', ' [dot] ' ];
		address = $(this).html();
		for ( i = 0; i < ats.length; i++ ) {
			address = address.replace(ats[i], '@');
		}
		for ( i = 0; i < dots.length; i++ ) {
			address = address.replace(dots[i], '.');
		}
		$(this).html('<a href="mailto:' + address + '">' + address + '</a>');
	});

});
