//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("Coming soon");
				} else if (document.title.indexOf("Home") != -1) {
					window.location.href="index.php";
					//alert("Bient\xF4t");
				} else {
					window.location.href=newUrl;
					//alert("Coming soon");
				}
    		} else if (xhr.status==404) {
    			if (oldLang == "/fr/") {
    				alert("Cette page n'existe pas en anglais");
				} else {
					alert("This page doesn't exist in french");
					
				}
    		}
  		}
 	}
 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
}

/* 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 campaignIDDefaut;
	  else
		return results[1];
}


// 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.number()<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.");
		}
	}
}

function swicthPNGtoGIF() {
	if ($.browser.msie() && $.browser.version.number()<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() {
	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;
		}
	}
}



//Ajuste la hauteur du contenu-body selon la hauteur des bloc bleu et vert
function ajusteHauteurContenuBody() {
	if ($("body").attr("id") != "accueil" && $("body").attr("id") != "equipe") {
	var hauteurBoxes = $("#boxes").height() + 155;
	var hauteurContenuBody = $("#contenu-body").height();
		if (hauteurBoxes > hauteurContenuBody) {
			hauteurVoulu = hauteurContenuBody + (hauteurBoxes-hauteurContenuBody);
			$("#contenu-body").height(hauteurVoulu);
			hauteurContenuVoulu = hauteurVoulu-46-115;
			$("#contenu").height(hauteurContenuVoulu);
		}
	}
}


//Change la photo du contenu en background (coin haut droit) selon la page
function changePhotoContenu() {
	if(typeof photoContenu == "undefined") {
		photoContenu = $("body").attr("id");
	} 
	$('#contenu').css("background-image", "url(/images/photos_background_contenu/" + photoContenu + ".jpg)");
}

//Ajuste la hauteur du footer siremap pour remplir l'ˇcran jusqu'en bas
function ajusteHauteurFooterSitemap() {
	if ($(window).height() > $('#conteneur').height()) {
		nouvelleHauteur = $("#footer .spacer").height() + ($(window).height() - $('#conteneur').height());
		$("#footer .spacer").css("height", nouvelleHauteur);
	}
}



//A la fin du chargement du DOM
$(document).ready(function(){ 
	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();
	
	ajusteHauteurContenuBody();
	
	// Pour enlever le border du dernier item du drop-down
	$(".jqueryslidemenu ul li ul li:last-child a").css('border','none');
	
	changePhotoContenu();
	
	ajusteHauteurFooterSitemap()
	
	
	//Rollover menu
	$("#menu img").hover(
 		function() {
  			this.src = this.src.replace("_off","_on");
 		}, function() {
  			this.src = this.src.replace("_on","_off");
		}
	);
	
	//Preload specifique - Le preload est different selon si on se trouve sur la page d'acueil ou sur les pages du site
	(function($) {
  		var cache = [];
 		 // Arguments are image paths relative to the current page.
  		$.preLoadImages = function() {
    		var args_len = arguments.length;
    		for (var i = args_len; i--;) {
      		var cacheImage = document.createElement('img');
      		cacheImage.src = arguments[i];
      		cache.push(cacheImage);
    		}
  		}
		})(jQuery)

	leUrlActuel=document.location.href;
	if (leUrlActuel.indexOf('/fr') != -1 || window.location.pathname == "/index.php") {
		if ($.browser.msie() && $.browser.version.number()<7) {
			jQuery.preLoadImages("/fr/images/menu/etudes-cliniques_on.png", "/fr/images/menu/processus-etudes_on.png", "/fr/images/menu/faq_on.png", "/fr/images/menu/nouvelles_on.png", "/fr/images/menu/entreprise_on.png", "/fr/images/menu/services_on.png", "/fr/images/menu/carrieres_on.png");
		} else {
			jQuery.preLoadImages("/fr/images/menu/etudes-cliniques_on.gif", "/fr/images/menu/processus-etudes_on.gif", "/fr/images/menu/faq_on.gif", "/fr/images/menu/nouvelles_on.gif", "/fr/images/menu/entreprise_on.gif", "/fr/images/menu/services_on.gif", "/fr/images/menu/carrieres_on.gif");
		}
	} else {
		jQuery.preLoadImages("/en/images/boxinfo_bt_auto_on.jpg", "/en/images/boxinfo_bt_home_on.jpg");
	}

$(function(){
	$('#vertical-ticker1').vTicker({ 
		speed: 500,
		pause: 3000,
		animation: 'fade',
		mousePause: false,
		showItems: 2
	});
});

$(function(){
	$('#vertical-ticker2').vTicker({ 
		speed: 500,
		pause: 3000,
		animation: 'fade',
		mousePause: false,
		showItems: 2
	});
});


	$(".champs_interets").toggle(function() {
		$(this).next().show();
    	$(this).css("background-image", "url(/images/triangle_accordeon_down.gif)"); 
	},function() {
    	$(this).next().hide();
    	$(this).css("background-image", "url(/images/triangle_accordeon_up.gif)"); 
	});
	
} );

//A la fin du chargement de toutes les images
$(window).bind("load",function(){ 
	//Met l'image du menu a "on", si l'element existe
	if ($(".on img").length) {
		var newSrc = $(".on img").attr("src").replace("_off", "_on");
  		$(".on img").attr("src", newSrc);
  	}
} );
