function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore(quelBt) { //v3.0
	//Ajout pour ne pas que le bouton "ON" d'un section dans laquelle on se trouve, ne s'eteigne pas
	if (document.title.indexOf(quelBt) == -1) {
		var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//Utiliser pour faire des popup d'images agrandi (_popimage.html)
function popImage(theURL,largeur,hauteur) {
  if (!largeur) {
  	features = 'status=yes,menubar=yes,resizable=yes,scrollbars=yes,width=750,height=550';
  } else {
  	features = 'status=yes,menubar=yes,resizable=yes,scrollbars=yes,width=' + largeur + ', height=' + hauteur + '';
  }
  window.open(theURL,'pop', features);
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}


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.html";
				} else if (document.title.indexOf("Home") != -1) {
					window.location.href="index_fr.html";
				} else {
					window.location.href=newUrl;
				}
    		} 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
}



function nousJoindreEcommerce(oldLang,newLang) {
	//var newUrl;
	//var oldUrl;

	//oldLang='/' + oldLang + '/';
	//newLang='/' + newLang + '/';
	//oldUrl=document.location.href;
	//newUrl=oldUrl.replace(oldLang,newLang);
	//if (document.title.indexOf("Accueil") != -1) {
	//	window.location.href="index_en.html";
	//} else {
	//	window.location.href=newUrl;
	//}
	
	alert('Coming soon');
}


//Pour caratres spciaux dans alert(), faire un translate en Hex -> \xE9



// Cookies - From quirksmode.org

var Cookies = {
	init: function () {
		var allCookies = document.cookie.split('; ');
		for (var i=0;i<allCookies.length;i++) {
			var cookiePair = allCookies[i].split('=');
			this[cookiePair[0]] = cookiePair[1];
		}
	},
	create: function (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=/";
		this[name] = value;
	},
	erase: function (name) {
		this.create(name,'',-1);
		this[name] = undefined;
	}
};
Cookies.init();

// Header - Pour se souvenir de la photo ou on est rendu dans le header
// Function appele du flash header a chaque frame qu'il doit se souvenir
function cookieHeader(quelPhoto) {
	name = "Gforcedivision";
	Cookies.create(name,quelPhoto,365);
}



// Functions pour loader dynamiquement les fichiers dans la mise en page - AJAX

function clientSideInclude(id, url, etatHome) {
  var req = false;
  // For Safari, Firefox, and other non-MS browsers
  if (window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch (e) {
      req = false;
    }
  } else if (window.ActiveXObject) {
    // For Internet Explorer on Windows
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        req = false;
      }
    }
  }
 var element = document.getElementById(id);
 if (!element) {
  alert("Bad id " + id +
   "passed to clientSideInclude." +
   "You need a div or span element " +
   "with this id in your page.");
  return;
 }
  if (req) {
    // Synchronous request, wait till we have it all
    req.open('GET', url, false);
    req.send(null);
    element.innerHTML = req.responseText;
  } else {
    element.innerHTML =
   "Sorry, your browser does not support " +
      "XMLHTTPRequest objects. This page requires " +
      "Internet Explorer 5 or better for Windows, " +
      "or Firefox for any system, or Safari. Other " +
      "compatible browsers may also exist.";
  }
}

// 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.");
		}
	}
}


function openConvertisseur() {
			if (window.location.href.indexOf("/fr") != -1) {
				MM_openBrWindow("/fr/_convertisseur.html","convertisseur","left=20,top=20,width=300,height=400,toolbar=0,resizable=1,location=0,menubar=0");
			} else {
				MM_openBrWindow("/en/_convertisseur.html","convertisseur","left=20,top=20,width=300,height=400,toolbar=0,resizable=1,location=0,menubar=0");
			}
}



//A la fin du chargement du DOM
$(document).ready(function(){ 

	$("#btn1").hover(
 		function() {
 			$("#menu1").slideDown();
 			$("#btn1").css({ zIndex:"50" });
 		}, function() {
 			$("#menu1").slideUp();
 			$("#btn1").css({ zIndex:"5" });
		}
	);
	
	$("#btn2").hover(
 		function() {
 			$("#menu2").slideDown();
 			$("#btn2").css({ zIndex:"50" });
 		}, function() {
 			$("#menu2").slideUp();
 			$("#btn2").css({ zIndex:"5" });
		}
	);
	
	$("#btn3").hover(
 		function() {
 			$("#menu3").slideDown();
 			$("#btn3").css({ zIndex:"50" });
 		}, function() {
 			$("#menu3").slideUp();
 			$("#btn3").css({ zIndex:"5" });
		}
	);
	
	$("#btn4").hover(
 		function() {
 			$("#menu4").slideDown();
 			$("#btn4").css({ zIndex:"50" });
 		}, function() {
 			$("#menu4").slideUp();
 			$("#btn4").css({ zIndex:"5" });
		}
	);

	//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();
	
	//convertisseur de devises	
	$(function() {
		$('.convertisseur').bind('click', function () {
			openConvertisseur();
		})
	});
	$(".convertisseur").hover(
 		function() {
 			$(".convertisseur img").addClass("buttonOver");
 		}, function() {
 			$(".convertisseur img").removeClass("buttonOver");
		}
	);
	
} );

