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);
  var newWin = window.open(theURL,winName,features);
  newWin.focus();
}

//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; }
}


//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.html";
					//alert("Coming soon");
				} else if (document.title.indexOf("Home") != -1) {
					window.location.href="index.html";
					//alert("Bient\xF4t");
				} else {
					window.location.href=newUrl;
					//alert("Coming soon");
				}
    		} else if (xhr.status==404) {
    			if (oldLang == "/fr/") {
    				alert("This page doesn't exist in french");
				} else {
					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
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}



//Pour caratres spŽciaux dans alert(), faire un translate en Hex -> \xE9



// Sous-menu colonne de gauche

function sousmenuON(qui) {
	$(qui).addRemove("off");
	$(qui).addClass("on");
}

function sousmenuOFF(qui, quelTitrePage) {
	titre = document.title
	//Ajout pour ne pas que le bouton "ON" d'une section dans laquelle on se trouve, ne s'eteigne pas
	if (titre.indexOf(quelTitrePage) != -1) {
		$(qui).addRemove("off");
		$(qui).addClass("on");
	} else {
		$(qui).addRemove("on");
		$(qui).addClass("off");
	}
}


// Option sans sous-menu

function firstLoad() {

//Ajuste la hauteur de #contenu selon la hauteur de #sidebar
if ($("#sidebar").height() > $("#contenu").height()) {
	hauteurVoulu = $("#contenu").height() + ($("#sidebar").height()-$("#contenu").height());
	$("#contenu").height(hauteurVoulu);
}

//Change l'état du lien du menuLeft pour la section dans laquelle on se trouve

if (document.title.indexOf("Accueil") != -1 || document.title.indexOf("Home") != -1) {
	$("#accueil").addClass("on");
} else if (document.title.indexOf("offre") != -1 || document.title.indexOf("what we do") != -1) {
	$("#offre").addClass("on");
	if (document.title.indexOf("offre / 21e") != -1 || document.title.indexOf("what we do / 21st") != -1) {
		$("#vingt-et-une").addClass("on");
	} else if (document.title.indexOf("offre / Capital4") != -1 || document.title.indexOf("what we do / Capital4") != -1) {
		$("#capital4").addClass("on");
	} else if (document.title.indexOf("offre / D\xE9veloppement durable") != -1 || document.title.indexOf("what we do / Sustainable development") != -1) {
		$("#dev").addClass("on");
	} else if (document.title.indexOf("offre / consultation marketing") != -1 || document.title.indexOf("what we do / marketing consultation") != -1) {
		$("#consultation-marketing").addClass("on");
	} else if (document.title.indexOf("offre / marketing social") != -1 || document.title.indexOf("what we do / social marketing") != -1) {
		$("#marketing-social").addClass("on");
	} else if (document.title.indexOf("offre / marketing de parteneriat") != -1 || document.title.indexOf("what we do / partnership marketing") != -1) {
		$("#marketing-parteneriat").addClass("on");
	} else if (document.title.indexOf("offre / publicit\xE9") != -1 || document.title.indexOf("what we do / advertising") != -1) {
		$("#publicite").addClass("on");
	} else if (document.title.indexOf("offre / cr\xE9ation de contenu") != -1 || document.title.indexOf("what we do / content development") != -1) {
		$("#creation-contenu").addClass("on");
	} else if (document.title.indexOf("offre / en un clin d'oeil") != -1 || document.title.indexOf("what we do / in a nutshell") != -1) {
		//Page d'accueil de la section
		$("#clin-d-oeil").addClass("on");
	}
} else if (document.title.indexOf("philosophie") != -1 || document.title.indexOf("how we work") != -1) {
	$("#philosophie").addClass("on");
} else if (document.title.indexOf("turboth\xE8que") != -1 || document.title.indexOf("turbo drive") != -1) {
	$("#turbotheque").addClass("on");
	if (document.title.indexOf("turboth\xE8que / 360") != -1 || document.title.indexOf("turbo drive / 360") != -1) {
		$("#trois-cent-soixante").addClass("on");
	} else if (document.title.indexOf("turboth\xE8que / le nouveau marketing social") != -1 || document.title.indexOf("turbo drive / social marketing today") != -1) {
		$("#nouveau-marketing-social").addClass("on");
	} else if (document.title.indexOf("turboth\xE8que / turbo-folio") != -1 || document.title.indexOf("turbo drive / turbo-folio") != -1) {
		$("#turbo-folio").addClass("on");
	} else if (document.title.indexOf("turboth\xE8que / turbo-info") != -1 || document.title.indexOf("turbo drive / turbo-info") != -1) {
		$("#turbo-info").addClass("on");
	}
} else if (document.title.indexOf("carburant") != -1 || document.title.indexOf("track record") != -1) {
	$("#carburant").addClass("on");
	if (document.title.indexOf("carburant / Naya") != -1 || document.title.indexOf("track record / Naya") != -1) {
		$("#naya").addClass("on");
	} else if (document.title.indexOf("carburant / SAQ") != -1 || document.title.indexOf("track record / SAQ") != -1) {
		$("#saq").addClass("on");
	} else if (document.title.indexOf("carburant / Fondation de la faune du Qu\xE9bec") != -1 || document.title.indexOf("track record / The Fondation de la faune du Qu\xE9bec") != -1) {
		$("#fondation-faune-quebec").addClass("on");
	} else if (document.title.indexOf("carburant / Fondation Interbox") != -1 || document.title.indexOf("track record / Fondation Interbox") != -1) {
		$("#fondation-interbox").addClass("on");
	} else if (document.title.indexOf("carburant / Sarah et Simon") != -1 || document.title.indexOf("track record / Sarah and Simon") != -1) {
		$("#sarah-et-simon").addClass("on");
	} else if (document.title.indexOf("carburant / Fonds Naya") != -1 || document.title.indexOf("track record / Fonds Naya") != -1) {
		$("#fonds-naya").addClass("on");
	} else if (document.title.indexOf("carburant / Consortium \xC9cho-Logique") != -1 || document.title.indexOf("track record / Consortium \xC9cho-Logique") != -1) {
		$("#consortium_echo-logique").addClass("on");
	} else if (document.title.indexOf("carburant / Parti lib\xE9ral du Canada") != -1 || document.title.indexOf("track record / Liberal Party of Canada") != -1) {
		$("#parti-liberal-canada").addClass("on");
	} else if (document.title.indexOf("carburant / Astral Media Affichage") != -1 || document.title.indexOf("track record / Astral Media Outdoor") != -1) {
		$("#astral-media-affichage").addClass("on");
	} else if (document.title.indexOf("carburant / Le Jour de la Terre Qu\xE9bec") != -1 || document.title.indexOf("track record / Le Jour de la Terre Qu\xE9bec") != -1) {
		$("#jour-terre-quebec").addClass("on");
	} else if (document.title.indexOf("carburant / BDC") != -1 || document.title.indexOf("track record / BDC") != -1) {
		$("#bdc").addClass("on");
	} else if (document.title.indexOf("carburant / SSQ") != -1 || document.title.indexOf("track record / SSQ") != -1) {
		$("#ssq").addClass("on");
	} else if (document.title.indexOf("carburant / Roulez mieux") != -1 || document.title.indexOf("track record / Roulez mieux") != -1) {
		$("#roulez-mieux").addClass("on");
	} else if (document.title.indexOf("carburant / Bludrop") != -1 || document.title.indexOf("track record / Bludrop") != -1) {
		$("#bludrop").addClass("on");
	} else if (document.title.indexOf("carburant / Mission citoyenne") != -1 || document.title.indexOf("track record / Mission citoyenne") != -1) {
		$("#mission-citoyenne").addClass("on");
	} else if (document.title.indexOf("carburant /") != -1 || document.title.indexOf("track record /") != -1) {
		//Page d'accueil de la section
		$("#carburant_sm").addClass("on");
	}
} else if (document.title.indexOf("\xE9quipe") != -1 || document.title.indexOf("under the hood") != -1) {
	$("#equipe").addClass("on");
	if (document.title.indexOf("\xE9quipe / Pierre Ladouceur") != -1 || document.title.indexOf("under the hood / Pierre Ladouceur") != -1) {
		$("#pierre-ladouceur").addClass("on");
	} else if (document.title.indexOf("Rivard") != -1 || document.title.indexOf("Rivard") != -1) {
		$("#marc-andre-rivard").addClass("on");
	} else if (document.title.indexOf("\xE9quipe / Annie Voyer") != -1 || document.title.indexOf("under the hood / Annie Voyer") != -1) {
		$("#annie-voyer").addClass("on");
	} else if (document.title.indexOf("\xE9quipe / Isabelle Panelli") != -1 || document.title.indexOf("under the hood / Isabelle Panelli") != -1) {
		$("#isabelle-panelli").addClass("on");
	} else if (document.title.indexOf("\xE9quipe / David Belliveau") != -1 || document.title.indexOf("under the hood / David Belliveau") != -1) {
		$("#david-belliveau").addClass("on");
	}
} else if (document.title.indexOf("coordonn\xE9es") != -1 || document.title.indexOf("contact") != -1) {
	$("#coordonnees").addClass("on");
}


	//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 && document.title.indexOf("21e") != -1) {
		jQuery.preLoadImages('/fr/offre/images/carre-aider_down.gif','/fr/offre/images/carre-sortir-rouge_down.gif','/fr/offre/images/carre-socio-promo_down.gif','/fr/offre/images/carre-cause-effet_down.gif');
	} else {
		jQuery.preLoadImages('/en/offre/images/carre-aider_down.gif','/en/offre/images/carre-sortir-rouge_down.gif','/en/offre/images/carre-socio-promo_down.gif','/en/offre/images/carre-cause-effet_down.gif');
	}
	
	//Menu dans 21e
	leUrlActuel=document.location.href;
	if (leUrlActuel.indexOf('/fr') != -1) {
		lg = "/fr";
	} else {
		lg = "/en";
	}
	if (leUrlActuel.indexOf("21e.php") != -1) {
		pathImg = lg + "/offre/images/carre-aider_on.gif";
		$("#aider").attr("src",pathImg);
	} else if (leUrlActuel.indexOf("21e_sortir-rouge.php") != -1) {
		pathImg = lg + "/offre/images/carre-sortir-rouge_on.gif";
		$("#sortir_rouge").attr("src",pathImg);
	} else if (leUrlActuel.indexOf("21e_socio-promo.php") != -1) {
		pathImg = lg + "/offre/images/carre-socio-promo_on.gif";
		$("#socio_promo").attr("src",pathImg);
	} else if (leUrlActuel.indexOf("21e_cause-effet.php") != -1) {
		pathImg = lg + "/offre/images/carre-cause-effet_on.gif";
		$("#cause_effet").attr("src",pathImg);
	}
	
	
	//Positionne l'icone twitter
	var positionInfos = $("#infos_footer").position();
	var largeurInfos = $("#infos_footer").width();
	var largeurTwitter = $(".twitter").width();
	var positionTwitter = positionInfos.left+((largeurInfos-largeurTwitter)/2);
	$(".twitter").css({ position: "absolute", top: "20px", left: positionTwitter });
	$(".twitter").css({ display:"block" });
}






// 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.";
  }
} 


//Function pour inserer du code HTML de faon dynamique dans la page
function showPhotoZoomNouvelles(quelPhotoZoom){
	if (document.all) {
		DIVD.innerHTML="texte";
	} else if (document.getElementById) {
		rng = document.createRange();
		el = document.getElementById("DIVD");
		rng.setStartBefore(el);
		htmlFrag = rng.createContextualFragment("texte");
		while (el.hasChildNodes()) el.removeChild(el.lastChild);
		el.appendChild(htmlFrag);
	}
}

  
// OnLoad Event

function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}
addEvent(window, 'load', firstLoad);

// Pour jouer avec l'apparence du curseur
//document.body.style.cursor='pointer';
//document.body.style.cursor='default';


var layerAffiche = "aucun";

//Function pour un click sur un bouton pour show/hide un layer
function showHideLayer(div_id) {
	if (layerAffiche == "aucun") {
		hideAllLayer();
    	$("#layer1").css({ display:"block" });
    	layerAffiche = div_id;
    } else {
    	hideAllLayer();
    	layerAffiche = "aucun";
    	if (layerAffiche == div_id) {
    		layerAffiche = "aucun";
    	} else {
			quelLayer = "#" + div_id;
    	    $(quelLayer).css({ display:"block" });
    		layerAffiche = div_id;
    	}
    }
}

// Modifier selon les layers de la page
function hideAllLayer() {
	$("#layer1").css({ display:"none" });
    $("#layer2").css({ display:"none" });
    $("#layer3").css({ display:"none" });
}


