// JavaScript Document
var flagBioClose = 0;
$(document).ready(function() {
	//flagIn=false;
	
	$(".btn_menu_left").mouseenter(function() {
		 var containerParent = $(this).parent().parent();
		 var btnNomChildren = $(containerParent).children(".btn_nom_left");
	     animateIn(btnNomChildren, this);
	});
	$(".btn_menu_left").mouseleave(function() {
		 var containerParent = $(this).parent().parent();
		 var btnNomChildren = $(containerParent).children(".btn_nom_left");
	      animateOut(btnNomChildren, this);
	});
	

	 var containerParentSelected = $(".container_btn_menu_left_selected");
	 var btnNomChildrenSelected = $(containerParentSelected).children(".btn_nom_left");
	 var btnMenuChildrenSelected = $(containerParentSelected).children(".btn_menu_left");
	 animateIn(btnNomChildrenSelected, btnMenuChildrenSelected);


    $(".cube_liens").mouseenter(function() {
		 var linkName = $(this).attr("id");
		 var classInfosLink = "#container_infos_"+linkName;
	      $(classInfosLink).stop().fadeTo("fast", 1);
	});
	$(".cube_liens").mouseleave(function() {
		 var linkName = $(this).attr("id");
		 var classInfosLink = "#container_infos_"+linkName;
	      $(classInfosLink).stop().fadeTo("fast", 0);
	});


    $(".pthumb").mouseenter(function() {
		 $("#container_info_photo").stop().fadeTo("fast", 1);
	});
	$(".pthumb").mouseleave(function() {
		 $("#container_info_photo").stop().fadeTo("fast", 0, endFade2($("#container_info_photo")));
	});
	
	
	
	$(".menu_unselected img").fadeTo("slow", 0.85);
	$(".menu_unselected img").mouseleave(function() {
       $(this).stop().fadeTo("slow", 0.85); 
	});
	$(".menu_unselected img").mouseenter(function() {
       $(this).stop().fadeTo("slow", 1);
	});
	
	//btn liens///////////////////////////////////////////////////////
	$(".cube_liens").mouseleave(function() {
       $(this).stop().fadeTo("slow", 1); 
	});
	$(".cube_liens").mouseenter(function() {
       $(this).stop().fadeTo("slow", 0.70);
	});
	
	//btn biographie//////////////////////////////////////////////////
	
	$(".container_photo_right_bio").click(function() {
	   if(flagBioClose == 1) {
		  $(".container_bio").fadeTo("slow", 0, endFadeOutBio);
		  $(".container_photo_right_bio").css("background-position", "0px 0px");
          flagBioClose = 0;
	   }
	   else {
		  $(".container_bio").fadeTo("slow", 1, endFadeInBio);
		  $(".container_photo_right_bio").css("background-position", "-20px 0px");
		  flagBioClose = 1;
	   }
	});
	$(".btn_close_bio").click(function() {
       $(".container_bio").fadeTo("slow", 0, endFadeOutBio);
	   $(".container_photo_right_bio").css("background-position", "0px 0px");
	   flagBioClose = 0;
	});
	
	$(".container_photo_right_bio").mouseleave(function() {
       $(this).stop().fadeTo("slow", 1); 
	});
	$(".container_photo_right_bio").mouseenter(function() {
       $(this).stop().fadeTo("slow", 0.60);
	});
	
	//btn navigation//////////////////////////////////////////////////
	$(".btn_nav").mouseleave(function() {
       $(this).stop().fadeTo("slow", 1);
	});
	$(".btn_nav").mouseenter(function() {
       $(this).stop().fadeTo("slow", 0.70);
	});
	
	//btn close pop up intro/////////////////////////////////////////
	$("#btn_close_intro_popup").click(function() {
       $("#container_intro_popup").fadeTo(3000, 0, endFade3);
	});
	
	
	
	$(".container_photo_right").mouseleave(function() {
       $(this).stop().fadeTo("slow", 1);
	});
	$(".container_photo_right").mouseenter(function() {
       $(this).stop().fadeTo("slow", 0.70);
	});
	
	
	
	var imgInit = $("#container_photo_lieu img").attr("src");
	$(".cadre_imgLieu img").mouseenter(function() {
       var img = $(this).attr("src");
	   $("#container_photo_lieu").html("<img src='"+img+"' width='250' height='185' />")
	});
	$(".cadre_imgLieu img").mouseleave(function() {
       var img = $(this).attr("src");
	   $("#container_photo_lieu").html("<img src='"+imgInit+"' width='250' height='185' />")
	});
	
	onResize();
	onResizePopup();
	
	
	
	$(".modal-link").fancybox({
		'titlePosition'		: 'inside',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none'
    });
	
	

	$("#contactForm").validate();
	
	$.metadata.setType("attr", "validate");

	
});


$(window).resize(function() {
	 onResize();
	 onResizePopup();
});



function animateIn(element, element2) {
	  $(element).stop().animate({
		width: "150px"
	  }, 300 );
	  $(element).children(".case_nom_left").stop().animate({
		width: "150px"
	  }, 300 );
	  $(element2).stop().fadeTo("slow", 0.65);
	  //flagIn=true;
}
function animateOut(element, element2) {
	  $(element).stop().animate({
		width: "12px"
	  }, 300 );
	  $(element).children(".case_nom_left").stop().animate({
		width: "0px"
	  }, 300 );
	  $(element2).stop().fadeTo("slow", 1);
	  //flagIn=false;
}


function onResize() {
	 var windowHeight = $(window).height();
	 var topMarg = 0;
	 
	 if(windowHeight > 370)
	 {
	   topMarg = (windowHeight - 370) / 2;
	 }
	 var top = topMarg;
	 $("#main").css("top", top);
}

function onResizePopup() {
	 var windowHeight = $(window).height();
	 var topMarg = 0;
	 
	 if(windowHeight > 370)
	 {
	   topMarg = (windowHeight - 370) / 2;
	 }
	 var top = topMarg;
	 $("#container_slider_popup").css("top", top);
}


function endFadeOutBio() {
      $(".container_bio").css("display", "none");
};
function endFadeInBio() {
  $(".container_bio").css("display", "inline");
};
function endFade2(element) {
  $(element).css("display", "none");
};
function endFade3() {
  $("#container_intro_popup").css("display", "none");
};





$(function () {
	$('#container_contenu_center img').hide();//hide all the images on the page
});

var i = 0;//initialize
var int=0;//Internet Explorer Fix
$(window).bind("load", function() {//The load event will only fire if the entire page or document is fully loaded
	var int = setInterval("doThis(i)",120);//500 is the fade in speed in milliseconds
});

function doThis() {
	var images = $('#container_contenu_center img').length;//count the number of images on the page
	if (i >= images) {// Loop the images
		clearInterval(int);//When it reaches the last image the loop ends
		$("#container_contenu_center").css("background-image", "none");
	}
	$('#container_contenu_center img:hidden').eq(0).fadeTo("slow", 1);//fades in the hidden images one by one
	i++;//add 1 to the count
}



