/* Pour aller chercher une variable dans l'URL (GET) */
function getURLparameter( name ) {
	  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regexS = "[\\?&]"+name;
	  var regex = new RegExp( regexS );
	  var results = regex.exec( window.location.href );
	  if( results == null )
		return "valeurpardefaut";
	  else
		return "oui";
}


//Switch de langue

function switchLang(oldLang,newLang) {
	var newUrl;
	var oldUrl;

	oldLang='/' + oldLang + '/';
	newLang='/' + newLang + '/';
	oldUrl=document.location.href;
	newUrl=oldUrl.replace(oldLang,newLang);
	
	xhr = getXhr()
	xhr.open("HEAD", newUrl,true);
 	xhr.onreadystatechange=function() {
  		if (xhr.readyState==4) {
   			if (xhr.status==200) {
   				if (document.title.indexOf("Accueil") != -1) {
					window.location.href="index_en.php";
					//alert("We're sorry, but the English version of our website will be not be up and running until November 30th. Please, don't forget to visit the site when it becomes available.");
				} else if (document.title.indexOf("Home") != -1) {
					window.location.href="index.php";
					//alert("Bient\xF4t");
				} else {
					window.location.href=newUrl;
					//alert("We're sorry, but the English version of our website will be not be up and running until November 30th. Please, don't forget to visit the site when it becomes available.");
				}
    		} else if (xhr.status==404) {
    			if (oldLang == "/fr/") {
    				//alert("We're sorry, but the English version of our website will be not be up and running until November 30th. Please, don't forget to visit the site when it becomes available.");
    				alert("This page doesn't exist in french");
				} else {
					//alert("We're sorry, but the English version of our website will be not be up and running until November 30th. Please, don't forget to visit the site when it becomes available.");
					alert("Cette page n'existe pas en anglais");
				}
    		}
  		}
 	}
 xhr.send(null)
}
//Creer l'objet XMLHttpRequest
function getXhr(){
 	var xhr = null; 
	if(window.XMLHttpRequest) // Firefox et autres
	xhr = new XMLHttpRequest(); 
	else if(window.ActiveXObject){ // Internet Explorer 
	try {
	xhr = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	}
	else { // XMLHttpRequest non supportˇ par le navigateur 
	alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	xhr = false; } 
 	return xhr
}


var cvVisible = false;
var anecdoteVisible = false;

function showCV() {
	if (typeof cvVisible == "undefined" || cvVisible == false) {
		$("#cv").show();
		$("#cv_container").animate({"left": "+=510px"}, "slow");
		cvVisible = true;
		if (anecdoteVisible == true) {
			$("#anecdote_container").animate({"top": "+=410px"}, "slow", function() {
    			$("#anecdote").hide();
  			});
			anecdoteVisible = false;
		}
	} else {
		$("#cv_container").animate({"left": "-=510px"}, "slow", function() {
    		$("#cv").hide();
  		});
		cvVisible = false;
	}
}

function showAnecdote() {
	if (typeof anecdoteVisible == "undefined" || anecdoteVisible == false) {
		$("#anecdote").show();
		$("#anecdote_container").animate({"top": "-=410px"}, "slow");
		anecdoteVisible = true;
		if (cvVisible == true) {
			$("#cv_container").animate({"left": "-=510px"}, "slow", function() {
    			$("#cv").hide();
  			});
			cvVisible = false;
		}
	} else {
		$("#anecdote_container").animate({"top": "+=410px"}, "slow", function() {
    		$("#anecdote").hide();
  		});
		anecdoteVisible = false;
	}
}

function afficheBonneSaison() {
	var dToday = new Date;
	if (dToday.getMonth() >= 0 && dToday.getMonth() <= 1 || dToday.getMonth() == 11) {
		$("body").removeClass("printemps");
		$("body").addClass("hiver");
	} else if (dToday.getMonth() >= 2 && dToday.getMonth() <= 4) {
		//rien a faire, la class printemps est deja la par defaut
	} else if (dToday.getMonth() >= 5 && dToday.getMonth() <= 7) {
		$("body").removeClass("printemps");
		$("body").addClass("ete");
	} else if (dToday.getMonth() >= 8 && dToday.getMonth() <= 10) {
		$("body").removeClass("printemps");
		$("body").addClass("automne");
	}
}

// Cookies - From http://www.quirksmode.org/js/cookies.html

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function alertIE6() {
	var x = readCookie('ie6alert');
	if (!x) {
		if ($.browser.msie && $.browser.version.substr(0,1)<7) {
  			createCookie("ie6alert","oui",365);
     		alert("Vous utilisez la version 6 de Internet Explorer. Vous devriez mettre \xE0 jour Internet Explorer pour utiliser toutes les nouvelles fonctionnalit\xE9s disponible sur internet.");
		}
	}
}

//Pour animation video sur l'accueil
function checkCookieVideo() {
	var x = readCookie('videoVu');
	if (!x) {
  		createCookie("videoVu","oui",1);
	} else {
		//Fonction Slideshow pour presenter le site web dans un kiosque
		if (getURLparameter( 'slideshow' ) == "oui") {
			anim_video = "anim";
		} else {
			anim_video = "noanim";
		}
	}
}

function swicthPNGtoGIF() {
	if ($.browser.msie && $.browser.version.substr(0,1)<7) {
  		$('img[src$=".png"]').each(function(index,element) {
          element.src = element.src.replace('.png','.gif');
        });
	}
}


// Pour afficher le Haut de page automatiquement - necessite jQuery
function showHautdepage() {
	if ($("body").attr("id") != "equipe") {
	hautdepageExist = $("*").index( $('div.hautdepage')[0] )
	if (hautdepageExist != -1) {
		var offset = $('div.hautdepage').offset();
		if (offset.top < "850") {
			$('div.hautdepage').css("display", "none");
		} else {
			return false;
		}
	}
	}
}



var saisonActuel = "printemps";


//A la fin du chargement du DOM
$(document).ready(function(){ 
	
	afficheBonneSaison();
	showHautdepage();
	
	// Pour enlever le padding-bottom du dernier <p> dans une cellule de tableau
	$("td p:last-child").css('paddingBottom','0px');

	//Pour prevenir un right-click sur une image
	$('img').bind('contextmenu',function(e){
   		alert('Cette photo ne peut \xEAtre t\xE9l\xE9charg\xE9e.')
   		return false;
	});
	
	alertIE6();
	swicthPNGtoGIF();
	
	
	
	
} );

