$(function() {
	// Contact form
	$('#contactForm').submit(function(event) {
		event.preventDefault();
		$('input[type=submit]', this).attr('disabled', 'disabled');
		$(this).load('contact.php #result', $(this).serialize());
	}).find('#answer').val('8').parent().hide();
	
	// Overlay
	$('#contact').removeClass('section').addClass('overlay');
	$('a[rel="#contact"]').overlay({
		effect: 'apple',
		mask: '#FFF'
	});
	
	// Fading images on mouseover
	$('img').wrap($('<span />', {'class': 'fader'})).after(function() {
		var src = $(this).attr('src');
		var newsrc = src.substr(0, src.lastIndexOf('.')) + '-faded' + src.substr(src.lastIndexOf('.'));
		return $(this).clone().attr('src', newsrc).addClass('faded');
	});
	
	$('.faded').hover(function() {
		$(this).stop(true).animate({opacity: 0});
	}, function() {
		$(this).stop(true).animate({opacity: 1});
	});
	
	// External links open in a new window
	$('a[rel*=external]').click(function(event) {
		event.preventDefault();
		window.open($(this).attr('href'), '_blank');
	});
});
