$(function()
{
	/******** Gestion des réalisations ********/
	var nbReas = $('section.reas article.rea').length;
	/* Positionnement */
	$('section.reas article.rea').each(function() {
        $(this).css({
			top: $(window).height(),
			left: ($(window).width()-$(this).width())/2,
			opacity: 0
		});
    });
	/* Survol/désurvol des vignettes */
	$('section.vignettesReas div.vignetteRea').hover(function(){
		$(this).children('div.contenuVignetteRea').children('div.conteneurVignetteRea').animate({
			top: '-140px'
		}, 300, 'easeOutExpo');
		$(this).animate({
			backgroundColor: '#000'
		}, 300, 'easeOutQuad');
	}, function(){
		$(this).children('div.contenuVignetteRea').children('div.conteneurVignetteRea').animate({
			top: '0px'
		}, 300, 'easeInExpo');
		$(this).animate({
			backgroundColor: '#CFCFCF'
		}, 300, 'easeInQuad');
	});
	
	var reaAOuvrir;
	var reaOuverte;
	var transReas = false;
	/* Ouverture */
	$('section.vignettesReas div.vignetteRea div.conteneurVignetteRea a').click(function(){
		transReas = true;
		var posTopLien = $(this).offset().top;
		$('section.vignettesReas div.ligne').each(function() {
			if($(this).offset().top < posTopLien) {
				$(this).animate({
					bottom: $(window).height()+100
				}, 800, 'easeOutExpo');
			} else {
				$(this).animate({
					bottom: -250
				}, 800, 'easeOutExpo');
			}
        });
		$('section.reas').fadeIn(500, 'easeInQuad');
		afficherNav();
		reaAOuvrir = $('section.reas article#rea'+$(this)[0].id.substring(7, 9));
		reaAOuvrir.delay(400).animate({
			top: ($(window).height()-reaAOuvrir.height())/2,
			opacity: 1
		}, 500, 'easeInExpo', function(){
			reaAOuvrir.addClass('reaOuverte');
			reaOuverte = reaAOuvrir;
			transReas = false;
		});
		return false;
	});
	
	/* Fermeture */
	$('section.nav div.fermer').click(function(){
		transReas = true;
		masquerNav();
		reaOuverte.removeClass('reaOuverte');
		reaOuverte.animate({
			top: 0-reaOuverte.height(),
			opacity: 0
		}, 500, 'easeOutExpo', function(){
			reaOuverte.css('top', $(window).height());
		});
		$('section.reas').delay(400).fadeOut(500, 'easeOutQuad');
		$('section.vignettesReas div#ligne1').delay(400).animate({
			bottom: 360
		}, 500, 'easeInExpo');
		$('section.vignettesReas div#ligne2').delay(400).animate({
			bottom: 190
		}, 500, 'easeInExpo');
		$('section.vignettesReas div#ligne3').delay(400).animate({
			bottom: 20
		}, 500, 'easeInExpo', function(){ transReas = false; });
	});
	
	
	
	/******** Gestion de la navigation ********/
	$('section.nav div').hover(function(){
		$(this).animate({
			backgroundColor: '#F09'
		}, 300, 'easeOutQuad');
	}, function(){
		$(this).animate({
			backgroundColor: '#FFF'
		}, 300, 'easeInQuad');
	});
	
	/* Afficher navigation */
	function afficherNav() {
		var tempsAnim = 500;
		$('section.nav div').each(function() {
			$(this).delay(1000).animate({
				left: 0
			}, tempsAnim, 'easeOutExpo');
			tempsAnim+=150;
        });
	}
	
	/* Masquer navigation */
	function masquerNav() {
		var tempsAnim = 700;
		$('section.nav div').each(function() {
			$(this).animate({
				left: 20
			}, tempsAnim, 'easeInExpo');
			tempsAnim-=100;
        });
	}
	
	/* Réa précédente */
	$('section.nav div.flecheGauche').click(function() {
		if(transReas == false) {
			transReas = true;
			reaOuverte.removeClass('reaOuverte');
			if(reaOuverte[0].id.substring(3, 5) == 1) reaAOuvrir = $('section.reas article.rea:last-child');
			else reaAOuvrir = reaOuverte.prev('article.rea');
			reaOuverte.animate({
				top: 0-reaOuverte.height(),
				opacity: 0
			}, 500, 'easeOutExpo', function(){
				reaOuverte.css('top', $(window).height());
			});
			reaAOuvrir.delay(400).animate({
				top: ($(window).height()-reaAOuvrir.height())/2,
				opacity: 1
			}, 500, 'easeInExpo', function(){
				reaAOuvrir.addClass('reaOuverte');
				reaOuverte = reaAOuvrir;
				transReas = false;
			});
		}
	});
	
	/* Réa suivante */
	$('section.nav div.flecheDroite').click(function(){
		if(transReas == false) {
			transReas = true;
			reaOuverte.removeClass('reaOuverte');
			if(reaOuverte[0].id.substring(3, 5) == nbReas) reaAOuvrir = $('section.reas article.rea:first-child');
			else reaAOuvrir = reaOuverte.next('article.rea');;
			reaOuverte.animate({
				top: 0-reaOuverte.height(),
				opacity: 0
			}, 500, 'easeOutExpo', function(){
				reaOuverte.css('top', $(window).height());
			});
			reaAOuvrir.delay(400).animate({
				top: ($(window).height()-reaAOuvrir.height())/2,
				opacity: 1
			}, 500, 'easeInExpo', function(){
				reaAOuvrir.addClass('reaOuverte');
				reaOuverte = reaAOuvrir;
				transReas = false;
			});
		}
	});
	
	
	
	/* Paramètre de la lightbox des photos */
	$("a[rel=galeriePhoto1], a[rel=galeriePhoto2], a[rel=galeriePhoto3], a[rel=galeriePhoto4], a[rel=galeriePhoto5], a[rel=galeriePhoto6], a[rel=galeriePhoto7], a[rel=galeriePhoto8], a[rel=galeriePhoto9], a[rel=galeriePhoto10], a[rel=galeriePhoto11], a[rel=galeriePhoto12]").fancybox({
		'padding' : 10,
		'margin' : 100,
		'cyclic' : true,
		
		'overlayShow' : true,
		'overlayOpacity' : 0.8,
		'overlayColor' : '#000',
		
		'transitionIn' : 'elastic', // 'elastic', 'fade' or 'none'
		'transitionOut' : 'elastic', // 'elastic', 'fade' or 'none'
		
		'changeFade' : 100,
		
		'easingIn' : 'easeInQuart',
		'easingOut' : 'easeInQuart'
	});
	
	
	
	/******** Gestion du me contacter ********/
	$('a#meContacter').click(function(){
		var fct = 'mail';
		var a = 'to';
		var name = 'contact';
		var at = '@';
		var domaine = 'gastonbouchayer';
		var ext = '.com';
		location.href=fct+a+':'+name+at+domaine+ext;
		return false;
	});
	
	
	
	/******** Gestion du resize ********/
	$(window).resize(function(){
		$('body').css('height', $(window).height());
		$('section.reas article.rea').each(function() {
			$(this).css({
				top: $(window).height(),
				left: ($(window).width()-$(this).width())/2
			});
		});
		$('section.reas article.reaOuverte').css('top', ($(window).height()-$('section.reas article.reaOuverte').height())/2);
    });
	$(window).trigger('resize');
});

