$(document).ready(function() {

	var hauteurFenetre = $(window).height();
	var hauteurDivPage = $('#page').height();
	var diffHauteur = hauteurDivPage-hauteurFenetre;
	var heightFooterContainer = $('#footerContainer').height();
	//alert('hauteur Page : '+hauteurDivPage+' - hauteur Fenêtre : '+hauteurFenetre);
	
	// Gestion du fullscreen => background resizable
	function redimensionnement(){ 
		var image_width = $('img#backgroundPage').width(); 
		var image_height = $('img#backgroundPage').height(); 
		var over = image_width / image_height; 
		var under = image_height / image_width;
		var body_width = $(window).width(); 
		var body_height = $(window).height();
		if (body_width / body_height >= over) { 
			$('img#backgroundPage').css({ 
				'width': body_width + 'px', 
				'height': Math.ceil(under * body_width) + 'px', 
				'left': '0px', 
				'top': Math.abs((under * body_width) - body_height) / -2 + 'px' 
			}); 
		} else { 
			$('img#backgroundPage').css({ 
				'width': Math.ceil(over * body_height) + 'px', 
				'height': body_height + 'px', 
				'top': '0px', 
				'left': Math.abs((over * body_height) - body_width) / -2 + 'px' 
			}); 
		} 
	}          
	// Gestion de la hauteur de la  liste de matérieux dans la rubrique "Savoir-Faire"
	function redimListe() {
		var hauteurPage = $(window).height();
		var hauteurListe = hauteurPage-192;
		//alert('hauteurPage : '+hauteurPage+' - hauteurListe : '+hauteurListe);
		$("#contentContainer.savoir-faire .content").css({
			height:hauteurListe+'px'
		});
	}
	
	//Gestion de la hauteur des images dans la partie Prestations
	function redimContentImgPresta() {
		var reelHauteurHeadPresta = $('#contentContainer.prestations .head').outerHeight(true);
		var espaceRestant = hauteurFenetre-reelHauteurHeadPresta-heightFooterContainer;
		var hauteurDivContentPresta = espaceRestant-7;	
		$('#contentContainer.prestations .content').css({
			height:hauteurDivContentPresta+'px'
		});
	}
	
	//Gestion de la hauteur des images dans la partie Portfolio
	function redimContentImgPortfolio(tailleReduc) {
		 $('#contentContainer.portfolio .content img').load(function() {
			var hauteurInitContentPortfolio = $(this).height();
			var newHauteurContentImgPortfolio = hauteurInitContentPortfolio-tailleReduc-10;
			$('#contentContainer.portfolio .content').css({
				height:newHauteurContentImgPortfolio+'px'
			});
		}); 
	}
    redimensionnement(); //onload 
	redimContentImgPresta();
	redimListe();
	redimContentImgPortfolio(diffHauteur);
	
    $(window).resize(function(){
		redimensionnement();
		redimContentImgPresta();
		redimListe();
		redimContentImgPortfolio(diffHauteur);
    });
	
	// Gestion focus sur le champ d'inscription a la newsletter
	var contentFormNewsletter = $('#subscribe #email').attr('value');
	if(contentFormNewsletter=='entrez votre adresse mail'){
		$('#subscribe #email').focus(function(){
			$(this).attr('value','');
		});
	}
	$('#subscribe #email').focusout(function(){
		contentFormNewsletter = $('#subscribe #email').attr('value');
		if(contentFormNewsletter==''){
			$(this).attr('value','entrez votre adresse mail');
		} else {
			$(this).attr('value',contentFormNewsletter);
		}
	});

	// Dans l'admin    
	$('#typeAmbiance').click(function(){
		$('div.posPhoto').slideUp('fast', function(){
			$('div.description').slideUp('fast');
		});
	});
	var inputSelectionne = $('#typeAmbiance').attr('checked');
	if(inputSelectionne=='checked'){
		$('div.posPhoto').hide();
		$('div.description').hide();
	}
    
	$('#typePackshot').click(function(){
		$('div.posPhoto').slideDown('fast');
		$('div.description').slideDown('fast');
	});
	
	$('#contentContainer.admin .contentMain .index .process').hide();
	$('#contentContainer.admin .contentMain .index > ul > li:first-child .process').show();
	
	$('#contentContainer.admin .contentMain .index > ul > li > a').click(function(){
		$('#contentContainer.admin .contentMain .index .process').slideUp('slow');
		var liParent = $(this).parent();
		$(liParent).children('.process').slideDown();
		return false;
	});
})
