// Speed of the automatic slideshow
var slideshowSpeed = 6000;
var interval;
var currentImg = 1;
var imgTotal = 8;
var currentContainerImg = 1;

// Variable to store the images we need to set as background
// which also includes some text and url's.
var photos = [ {
		"title" : "bg1",
		"image" : "bg_header.jpg"
	}, {
		"title" : "bg2",
		"image" : "bg_header2.jpg"
	}, {
		"title" : "bg3",
		"image" : "bg_header3.jpg"
	}, {
		"title" : "bg4",
		"image" : "bg_header4.jpg"
	}, {
		"title" : "bg5",
		"image" : "bg_header5.jpg"
	}, {
		"title" : "bg6",
		"image" : "bg_header6.jpg"
	}, {
		"title" : "bg7",
		"image" : "bg_header7.jpg"
	}, {
		"title" : "bg8",
		"image" : "bg_header8.jpg"
	}
];
$(document).ready(function() {

// contactForm bouton NON
	$(".wpcf7-list-item:nth-child(2) input").click(function () {
	$("#effaceSiNon").fadeOut("slow");
	});
	$(".wpcf7-list-item:nth-child(1) input").click(function () {
	$("#effaceSiNon").fadeIn("slow");
	});

//totop
$().UItoTop({ easingType: 'easeOutQuart' });

	// --ANCHORLINK
	var scrollDuring=1000; /* Duree du Scroll 1000 = 1seconde */
	var scrollBegin=5; /* Hauteur entre l'ancre le scroll */
	$('a.goon').click(function(){
		if(location.pathname.replace(/^\//,'')==this.pathname.replace(/^\//,'')&&location.hostname==this.hostname){
			var $targetid=$(this.hash);
			$targetid=$targetid.length&&$targetid||$('[id='+this.hash.slice(1)+']');
			if($targetid.length){
				var targetOffset=$targetid.offset().top-scrollBegin;
					$('html,body').animate({scrollTop:targetOffset},scrollDuring);
					$("a").removeClass("active");
					$(this).addClass("active");
			return false;
			}
		}
	});
// -- element fixe qui suis la page web -- SousMenu


	// -- PARTIE POP UP --
						$("#bulle1_jquery").mouseover(function() {
							$("#bulle1").css("display","block");
						});
						$("#bulle1_jquery").mouseout(function() {
							$("#bulle1").css("display","none");
						});
						$("#bulle2_jquery").mouseover(function() {
							$("#bulle2").css("display","block");
						});
						$("#bulle2_jquery").mouseout(function() {
							$("#bulle2").css("display","none");
						});
						$("#bulle3_jquery").mouseover(function() {
							$("#bulle3").css("display","block");
						});
						$("#bulle3_jquery").mouseout(function() {
							$("#bulle3").css("display","none");
						});
	// -- FIN PARTIE POP UP --
	
	// -- POPUP POISSONS --
//When you click on a link with class of poplight and the href starts with a #
$('a.popupPoisson').click(function() {
	var popID = "popupPoisson";
  
  var catID = $(this).attr('rel');
  initSelectDepPoisson(catID);
	
	//Fade in Background
	$('body').append('<div id="fade"></div>'); //Add the fade 
	$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fad
	$('#' + popID).fadeIn().css();
	$('.btn_close').fadeIn().css();
	return false;
	});
	//Close Popups and Fade Layer
	$('a.btn_close, #fade').live('click', function() {
			$('#fade , .popup_block').fadeOut(function() {
				$('#fade, a.close').remove();
			}); //fade them both out
		return false;
	});
	
// -- POPUP PARCOURS --
//When you click on a link with class of poplight and the href starts with a #
$('a.popupParcours').click(function() {
	var popID2 = "popupParcours";
  
  var catID2 = $(this).attr('rel');
  initSelectDepParcours(catID2);
	
	//Fade in Background
	$('body').append('<div id="fade"></div>'); //Add the fade 
	$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fad
	$('#' + popID2).fadeIn().css();
	$('.btn_close').fadeIn().css();
	return false;
	});
	//Close Popups and Fade Layer
	$('a.btn_close, #fade').live('click', function() {
			$('#fade , .popup_block').fadeOut(function() {
				$('#fade, a.close').remove();
			}); //fade them both out
		return false;
	});
	
	
	/*** MAIN SLIDER ***/		
		//Mise en place des premières images
		$("#headerimg1").css({
			"background-image" : "url(/wp-content/themes/ehgo/img/" + photos[currentImg - 1].image + ")",
			"display" : "block"
		});
		$("#headerimg1").addClass("rdeImgSlider").addClass("current");
		
		$("#headerimg2").css({
			"background-image" : "url(/wp-content/themes/ehgo/img/" + photos[currentImg].image + ")",
			"display" : "none"
		});
		$("#headerimg2").addClass("rdeImgSlider");
		
		//Lancement de l'animation
		currentImg = 2;
		interval = setInterval("changeImage()", slideshowSpeed);
	
});

//Fonction gérant le formulaire des département sur les poissons
function initSelectDepPoisson(nomCat){
  //console.log("PopupPoisson : " + nomCat);
  $("#formSelectPoisson option").css('display', 'none'); //Masque toutes les options de ton select
  $("#formSelectPoisson option").attr('selected', ''); //Retire la sélection précédente
  $("#formSelectPoisson option." + nomCat).css('display', 'block'); //Affiche uniquement les options avec la catégorie passée en paramètre
}
function initSelectDepParcours(nomCat2){
  //console.log("PopupPoisson : " + nomCat);
  $("#formSelectParcours option").css('display', 'none'); //Masque toutes les options de ton select
  $("#formSelectParcours option").attr('selected', ''); //Retire la sélection précédente
  $("#formSelectParcours option." + nomCat2).css('display', 'block'); //Affiche uniquement les options avec la catégorie passée en paramètre
}


//Fonction gérant le changement d'image
function changeImage(){
	//Récupération des images courante
	var actif = $(".rdeImgSlider.current");
	var next = actif.next();
	
	//Récupération du conteneur à faire apparaitre
	if(currentContainerImg == 1){
		var nextContainerImg = 2;
	}else{
		var nextContainerImg = 1;
	}
	
	//Apparition des images
	$("#headerimg"+currentContainerImg).fadeOut(500);
	$("#headerimg"+nextContainerImg).fadeIn(500);
	
	//Mise en place des prochaines images
	actif.removeClass("current");
	next.addClass("current");
	var temp = currentContainerImg;
	currentContainerImg = nextContainerImg;
	nextContainerImg = temp;
	
	setTimeout(function(){
		currentImg++;
		if(currentImg == imgTotal){ currentImg = 1; }
		$("#headerimg"+nextContainerImg).css({
			"background-image" : "url(/wp-content/themes/ehgo/img/" + photos[currentImg-1].image + ")",
			"display" : "none"
		});
	},500);	
}
