$(document).ready(function(){
	// Work image fader
	$('.work ul li a').click(function(event){
		event.preventDefault();
		var imageSource = $(this).attr('href');
		var imageAlt = $(this).attr('title');
		var targetImg = $(this).parent('li').parent('ul').parent('.work').find('img');//main image
		var thumbLi = $(this).parent('li');
		targetImg.attr('src', imageSource).attr('alt', imageAlt);
		thumbLi.siblings('.active').removeClass('active');
		thumbLi.addClass('active');
	});

	// Prevent orphans in aboutme text and work text
	var nonBreaking = function() {
		$(this).html($(this).html().replace(/\s([^\s]+\s*(?:<|$))/g, '&nbsp;$1'));
	}
	//$('#aboutme p:first').each(nonBreaking);
	$('.work p').each(nonBreaking);

	// Smooth scroll to top
	$('a.backToTop').click(function(event) {
		event.preventDefault();
		$.scrollTo( { top:0, left:0}, 800 )
	});

});

