﻿$(document).ready(function(){//on attend que la page soit chargée
        //Pour tous les liens commençant par "mailto" ou les span ayant une class "wmail"
        $('a[href^="mailto"], span.wmail').each(function (i) {
                //Remplacment du texte dans l'élément
                var temp = $(this).html();
                temp = temp.replace("[arobase]","@");
                temp = temp.replace("[point]",".");
                $(this).html(temp);
                //Si il y a un attribut "href", on remplace le texte dans l'attribut
                if($(this).attr("href")){
                        var temphref = $(this).attr("href");
                        temphref = temphref.replace("[arobase]","@");
                        temphref = temphref.replace("[point]",".");
                        $(this).attr("href",temphref);
                }
        })
});

this.bannerId = 1;
this.bannerTimer = null;

function menu(idMenu) {
	clearTimeout();
	for (i=1; i<7;i++) {
		myMenu = document.getElementById("rollMenu"+i);
		myBarre = document.getElementById("barreMenu"+i);
		if (myMenu) myMenu.style.display="none";
		if (myBarre) myBarre.style.borderColor="white";
	}
	myMenu = document.getElementById("rollMenu"+idMenu);
	myBarre = document.getElementById("barreMenu"+idMenu);
	if (myBarre) {
		myBarre.style.borderColor="#d04e2a";
	}
	if (myMenu) {
		myMenu.style.display="block";
	}
}


function getElement(id) {
  var element = document.getElementById(id);
  return element;
}

function affiche(element) {
	if (element)  element.style.display = "block";
}

function cache(element) {
	if (element) element.style.display = "none";
}

function Initialisation (){
	AfficheCroissance();
	menu(0);
}

function AfficheCroissance() {
  var croissance = getElement("croissance");
  var fleche_croissance = getElement("fleche_croissance");
  var inter = getElement("international");
  var fleche_inter = getElement("fleche_inter");
  var developpement = getElement("developpement");
  var fleche_developpement = getElement("fleche_developpement");
  cache(developpement);
  cache(fleche_developpement);
  cache(inter);
  cache(fleche_inter);
  affiche(croissance);
  affiche(fleche_croissance);
}

function AfficheInter() {
  var croissance = getElement("croissance");
  var fleche_croissance = getElement("fleche_croissance");
  var inter = getElement("international");
  var fleche_inter = getElement("fleche_inter");
  var developpement = getElement("developpement");
  var fleche_developpement = getElement("fleche_developpement");
  cache(croissance);
  cache(fleche_croissance);
  cache(developpement);
  cache(fleche_developpement);
  affiche(inter);
  affiche(fleche_inter);
}

function AfficheDev() {
  var croissance = getElement("croissance");
  var fleche_croissance = getElement("fleche_croissance");
  var inter = getElement("international");
  var fleche_inter = getElement("fleche_inter");
  var developpement = getElement("developpement");
  var fleche_developpement = getElement("fleche_developpement");
  cache(croissance);
  cache(fleche_croissance);
  cache(inter);
  cache(fleche_inter);
  affiche(developpement);
  affiche(fleche_developpement);
}

function show_hide(el_id) {
  var el=document.getElementById(el_id);
  if (el.style.display=='none') {
    el.style.display='block';
  }
  else if (el.style.display=='block') {
    el.style.display='none';
  }  
}

function showLexique(mot,id){
	$.ajax({ // fonction ajax permettant d'afficher le div
	   type: "POST", 
	   url: "infobullelexique.ajax.php", // url de la page contenant le module php
	   data: "mot="+mot,
	   success: function(msg){ 
			 var pos = $('#lexique_mot_'+mot+'_'+id).offset();
			 if ($('div.infobulle').is(':hidden')) {
					$('div.infobullelexique').html(msg);
					vHeight = $('div.infobulle').height();
					$('div.infobulle').css( {"left":pos.left-130 + "px", "top":pos.top-vHeight+4 + "px"} );
					$('div.infobulle').show();
			 }
		 }
	});
	// pour cacher le div lors d'un clic n'importe où sur la page
	/*$(document.body).click( function() {
		if ($('div.infobulle').is(':visible')) {
			$('div.infobulle').hide();
		}
	} );*/
}

function hideLexique (){
	$('div.infobulle').hide();
}

function DeroulMenu(id,nom) {		
	$('div.menu_deroulant').each(function(){
		if ($('#menu_'+nom).is(':hidden')){
			if (this.id == 'menu_'+nom) {
				$('#'+this.id).css( {"left": "0px", "top": "0px"} );
			  var pos = $('#'+id).offset();
			  var largeur = $('#'+id).innerWidth();		  
			  $('#'+this.id).css( {"left": (pos.left-680+largeur) + "px", "top":pos.top+39 + "px"} );
				$("#div_menu_6").css( {display: 'none'});
				$("nav a#menu_6").css( {display: 'none'});		  																						
				$("#div_menu_6_2").css( {display: 'block'});
				$("#menu_6_2").css( {display: 'block'});		  
				$("#div_menu_7").css( {display: 'none'});
				$("nav a#menu_7").css( {display: 'none'});		  																						
				$("#div_menu_7_2").css( {display: 'block'});
				$("#menu_7_2").css( {display: 'block'});		  			
			  $('#'+this.id).slideToggle(300, function(){ 
			  																						$("#div_menu_6").css( {display: 'block'});
			  																						$("nav a#menu_6").css( {display: 'block'});		  																						
			  																						$("#div_menu_6_2").css( {display: 'none'});
			  																						$("#menu_6_2").css( {display: 'none'});
			  																						$("#div_menu_7").css( {display: 'block'});
			  																						$("nav a#menu_7").css( {display: 'block'});		  																						
			  																						$("#div_menu_7_2").css( {display: 'none'});
			  																						$("#menu_7_2").css( {display: 'none'});
			  																				  });
			  //pour que le menu passe par dessus la vidéo dans la rubrique "en image"
				if ($('div.video').is(':visible')) {
					$('div.video').css( {visibility: "hidden"} );
				}
			}
			else {
				$('#'+this.id).slideUp(300, function() { 
																								$('div.video').css( {visibility: "visible"} );
																							 });
			}
		}
	});	
	
	// pour remonter le menu lors d'un clic n'importe où sur la page
	/*$(document.body).click( function() {
		if ($('#menu_'+nom).is(':visible')){
			$('#menu_'+nom).slideUp(300, function(){ 				
																							if ($('#menu_manifestation').is(':hidden')) {
																								$('div.video').css( {visibility: "visible"} );
																							}
																							if ($('#menu_action').is(':visible')) {
																								$('div.video').css( {visibility: "hidden"} );
																							}																																										
																						 } );			
		}
	});*/
	
// pour remonter le menu lors d'un clic n'importe où sur la page (sauf sur le menu)
$('#menu_'+nom).bind( "clickoutside", function(event){
		if ($('#menu_'+nom).is(':visible')){
			$('#menu_'+nom).slideUp(300, function(){ 				
																							if ($('#menu_manifestation').is(':hidden')) {
																								$('div.video').css( {visibility: "visible"} );
																							}
																							if ($('#menu_action').is(':visible')) {
																								$('div.video').css( {visibility: "hidden"} );
																							}																																										
																						 } );			
		}	
});
	
}

function showComplNewsletter() {
	if (document.forms["inscription"]._packnwl_Email.value == ""){
		$('div._packnwl_bouton_fr').show();
    $('div.erreur').hide();
		$('div.email_vide').show();
	}
	else {
		$('div.email_vide').hide();
		$('div._packnwl_bouton_fr').hide();
    $('div.complement_newsletter').show();
	}
}

function validFormNewsletter() {
	if (document.forms["inscription"]._packnwl_Email.value == ""){
		$('div.erreur').hide();
		$('div.email_vide').show();
		document.forms["inscription"]._packnwl_checkbox.checked = false;
	}
	else
		document.forms["inscription"].submit();
}

function validFormUnsubscribe() {
	if (document.forms["desinscription"]._packnwl_Email.value == ""){
		$('div.erreur_unsubscribe').hide();
		$('div.email_vide').show();
	}
	else
	document.forms["desinscription"].submit();	
}

function videoScroll (sens,nb_image) {	
	if (nb_image == 1 || nb_image == 2) nb_image = 3;
		var margintemp = ($('ul.defil').css('marginLeft'));
		var margintemp = parseInt(margintemp.replace('px',''));
		var margintempleft = margintemp-184
		var margintempright = margintempleft+368
		var nbclick = Math.abs(margintempleft)/184;
		if (sens == 'right' && nbclick != nb_image-2){
			$("div.next").css( {display: "none"} );
			$("div.next2").css( {display: "block"} );
			$("ul.defil").animate( {marginLeft: +margintempleft}, 400,
									 function(){
									 					  $("div.next").css( {display: "block"} );
									 					  $("div.next2").css( {display: "none"} ); 
									 					 } );
	}else if (sens == 'left'){
		if (margintempright <= 0){
			$("div.previous").css( {display: "none"} );
			$("div.previous2").css( {display: "block"} );
			$("ul.defil").animate( {marginLeft: +margintempright}, 400,
									 function(){ 
									 						$("div.previous").css( {display: "block"} );
									 						$("div.previous2").css( {display: "none"} ); 
									 					 } );
		}
	}
}

function changeAction (action){
	$(".image_back").css( {'background-image': 'url('+image[action]+')'} );	
	$(".titre").html(titre[action]);
	$(".sous_titre").html(soustitre[action]);
	$("#plus_lien").attr("href",lien[action]);
	$('a.btn_prog').css( {backgroundPosition: ""} );
	$('#prog'+action).css( {backgroundPosition: "bottom"} );
}

function PageLoad(pageId){
	loadDiapo();
  if(pageId == 1) {
		animateBanner();
	}
}

function animateBanner() {
  this.bannerTime = setInterval('toggleBanner()', 5000);
}

function toggleBanner() {
	if(this.bannerId == 1) {
    this.bannerId = 2;
    $("#obandeau").fadeIn(1500);
    $("#oprebandeau").fadeIn(1500);
  } else {
    this.bannerId = 1;
    $("#obandeau").fadeOut(1500);
    $("#oprebandeau").fadeOut(1500);
  }
}

function loadDiapo(){
	if (typeof(imageRand)!='undefined'){
    $(".image_back").css( {'background-image': 'url('+imageRand+')'} );
		$(".titre").html(titreRand);
		$(".sous_titre").html(soustitreRand);
		$("#plus_lien").attr("href",lienRand);
		$('#prog'+rand_no).css( {backgroundPosition: "bottom"} );
	}
}

var search_click_once = false;

$("#search_words").focus(function() {
  if(search_click_once == false) {
		$(this).val("");
		search_click_once = true;
	}
});

$("#search_words").blur(function() {
  if($(this).val() == "") {
		$(this).val("Rechercher");
	}
});

