function fade_halos() {
	
	$('#halo1, #halo2').css('opacity', 0);
	
	$('#halo2').animate({
		opacity: 1
	}, 2000);
	
	setTimeout(function() {
		
		$('#halo1').animate({
			opacity: 1
		}, 2000);
	}, 1500);
	
	setTimeout(function() {
		
		$('#halo2').animate({
			opacity: 0
		}, 2000);
		
		setTimeout(function() {
			$('#halo1').animate({
				opacity: 0
				}, 2000);
			}, 1500);
			
			setTimeout(fade_halos, 4000);
	}, 6000);
}

$(document).ready(function() {
	
	
	/**** E-mails ****/
	$('span.email').each(function() {
		var e = $(this).html().replace(' [at] ', '@').replace(' [dot] ', '.');
		$(this).html('<a href="mailto:'+e+'">'+e+'</a>');
	});
	
	/**** Home page, halos ****/
	if ($('#home_page').length && !(jQuery.browser.msie && jQuery.browser.version < 9)) {
		fade_halos();
	}
	
	/**** Galerie photo ****/
	if ($('#galerie_page').length) {
		
		var freeze = false;
		
		$('#galerie img').click(function() {
			
			if (freeze) return;
			freeze = true;
			
			var easing = 'easeOutCubic'; // 'easeOutQuad'; alex est un beau gosse
			var duration = 460;
			
			$(this).prev('img').prev('img').animate({
				width: 170,
				height: 97,
				top: 95,
				left: -405
			}, {duration: duration, easing: easing});
			
			$(this).prev('img').animate({
				width: 335,
				height: 191,
				top: 95,
				left: -213
			}, {duration: duration, easing: easing});
			
			$(this).animate({
				width: 671,
				height: 382,
				top: 0,
				left: 144
			}, {duration: duration, easing: easing, complete: function() {
				freeze = false;
			}});
			
			$(this).next('img').animate({
				width: 335,
				height: 191,
				top: 95,
				left: 838
			}, {duration: duration, easing: easing});
			
			$(this).next('img').next('img').animate({
				width: 170,
				height: 97,
				top: 95,
				left: 1195
			}, {duration: duration, easing: easing});
			
		});
		
	}
	
});
