/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \
|		Copyrigth (c) 2004 Smart Agence
|		Webdesign : Smart Agence
|		http://www.smartagence.com/
\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */


/* ______________________[ 01 | Interactivité du menu principal (menu « dropdown ») ]________________________ */

/* A special thanks goes to Eric Shepherd for his ALA article about “Hybrid CSS Dropdowns”: http://www.alistapart.com/articles/hybrid/ 
and to Patrick Griffiths and Dan Webb for their htmldog.com article “Sons of Suckerfish”: http://www.htmldog.com/articles/suckerfish/ */

/* Inspiré du "Suckerfish Dropdowns" de Patrick Griffiths et Dan Webb, adaptaté par Smart Agence
http://www.google.com/search?hl=en&ie=UTF-8&q=Suckerfish+Dropdowns&btnG=Google+Search */

/* Détection des vieilles versions de Gecko 
var agt=navigator.userAgent.toLowerCase();
var is_Gecko=(agt.indexOf('rv:')!=-1&&agt.indexOf('gecko')!=-1);
var limit=1.0;
if (is_Gecko) {
	stVs=agt.indexOf('rv:')+3;
	var GeckoVersion=agt.substring(stVs,stVs+3);
}

function SmartList(who) {
	var args=SmartList.arguments;
	for (n=0;n<args.length;n++) {
		if ((document.all&&document.getElementById&&document.getElementById(who))||GeckoVersion<limit) {
			var navRoot=document.getElementById(who);
			for (i=0;i<navRoot.childNodes.length;i++) {
				var node=navRoot.childNodes[i];
				if (node.nodeName=="LI") {
					node.onmouseover=function() {
						this.className+=" over";
					}
					node.onmouseout=function() {
						var Allnodes=this.parentNode.childNodes;
						for (a=0;a<Allnodes.length;a++) {
							if (Allnodes[a].nodeName=="LI") {
								this.className=Allnodes[a].className=="selected"?"selected":"hide";
							}
						}
					}
				}
			}
		}
	}
}*/

function SmartList(who) {
	if (document.all&&document.getElementById&&document.getElementById(who)) {
		navRoot=document.getElementById(who);
		for (i=0;i<navRoot.childNodes.length;i++) {
			node=navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {this.className+=" over";}
				node.onmouseout=function() {this.className=this.className.replace(" over", "");}
			}
		}
	}
}

/* ______________________[ 02 | Différentiation d’un élément de fin de liste ]________________________ */

/* Pour différentier le début d'une liste <ul /> en redéfinissant la propriété
CSS "background-image" sur "none" de son premier enfant <li /> */

function SmartNav(who) {
	var navRoot=document.getElementById(who);
	if (navRoot&&navRoot.nodeName=="UL") {
		for (i=0;i<navRoot.childNodes.length;i++) {
			if (navRoot.childNodes[i].nodeName=="LI") {
				navRoot.childNodes[i].style.backgroundImage="none";
				break;
			}
		}
	}
}


/* ______________________[ 03 | Correction de bogue visuel IE/mac ]________________________ */

/* Merci à Stephanie Sullivan et Danilo Celic de http://communitymx.com/
pour ce script qui corrige un bogue IE/mac (cf. http://www.positioniseverything.net/easyclearing.html) */

function fixmacie(classname) {
	var divs=document.getElementsByTagName("DIV");
	for (var d=0; d < divs.length;d++) {
		if (divs[d].className.indexOf(classname)==0) {
			divs[d].innerHTML+= "<div class='mac-clearfix'> </div>";
			/* The above html tags get added to the end of the cleared container if the browser is IE/mac. */
		}
	}
}


/* ______________________[ 04 | Ouverture de fenêtre compatible XHTML 1.0 Strict ]________________________ */

/* L’attribut target étant déprécié en XHTML et non supporté en XHTML Strict, il est utile de mimer l’effet d’un attribut « target="_blank" » 
via le script suivant. Totalement compatible XHTML Strict et si JavaScript n’est pas supporté ou activé, le lien s’ouvrira dans la fenêtre courante. */

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors=document.getElementsByTagName("a");
	for (var i=0;i<anchors.length;i++) {
		var anchor=anchors[i];
		if (anchor.getAttribute("href")&&anchor.getAttribute("rel")=="external") anchor.target="_blank";
	}
}


/* ______________________[ 05 | Gestion de l’ouverture/fermeture d’une liste « <dl/> » ]________________________ */

/* Ce script est utilisé lorsque chaque « <dt/> » à l’intérieur d’un onglet doit ouvrir/fermer le « <dd/> » correspondant.
Il y a une gestion d’état « on ». Deux fonctionnalités cohabitent : par exemple « SmartDL("listeDynamique",0,"FAQ",0,"Guides",1); » 
le premier argument de cette fonction est l’ID de la <dl/> à rendre interactive, le chiffre qui suit (0 ou 1) définit le type de fonctionnalité :
pour « 0 », un clic sur un <dt/> provoque l’ouverture du <dd/> associé ET la fermeture de tous les autres <dd/>. Pour « 1 », un clic sur
un <dt/> provoque l’ouverture/fermeture du <dd/> associé selon son état au moment du clic, les autres <dd/> ne bougent pas. */

function SmartDL() {
	var args=SmartDL.arguments;
	for (n=0;n<args.length;n+=2) {
		var ClickFx=args[n+1];
		if (document.getElementById&&document.getElementById(args[n])) {
			var root=document.getElementById(args[n]).childNodes;
			for (a=0;a<root.length;a++) {
				if (root[a].nodeName=="DT"&&root[a].className!="on") {
					if (root[a].nextSibling.nodeName=="DD") {var Sister=root[a].nextSibling;}
					else if (root[a].nextSibling.nextSibling.nodeName=="DD") {var Sister=root[a].nextSibling.nextSibling;}
					Sister.className="off";
				}
				if (root[a].nodeName=="DT"&&root[a].className=="on") {
					if (root[a].nextSibling.nodeName=="DD") {var Sister=root[a].nextSibling;}
					else if (root[a].nextSibling.nextSibling.nodeName=="DD") {var Sister=root[a].nextSibling.nextSibling;}
					Sister.className="on";
				} 
			}
			for (a=0;a<root.length;a++) {
				if (root[a].nodeName=="DT") {SmartOpenClose(root[a],root,ClickFx);}
			}
		}
	}
}

function SmartOpenClose(who,Brothers,ClickFx) {
	if (who.nextSibling.nodeName=="DD") {var Sister=who.nextSibling;}
	else if (who.nextSibling.nextSibling.nodeName=="DD") {var Sister=who.nextSibling.nextSibling;}
	if (ClickFx==1) {
		who.onclick=function() {
			who.className=who.className=="on"?"off":"on";
			Sister.className=Sister.className=="on"?"off":"on";
		}
	} else {
		who.onclick=function() {
			for (a=0;a<Brothers.length;a++) {
				if (Brothers[a].nodeName=="DT") {Brothers[a].className="";}
				else if (Brothers[a].nodeName=="DD") {Brothers[a].className="off";}
			}
			who.className="on";
			Sister.className=(Sister.className=="on"||Sister.className==" on")?"":"on";
		}
	}
}


/* ______________________[ 06 | Interactivité de la page des références ]________________________ */

/* A special thanks goes to Eric Shepherd for his ALA article about “Hybrid CSS Dropdowns”: http://www.alistapart.com/articles/hybrid/ 
and to Patrick Griffiths and Dan Webb for their htmldog.com article “Sons of Suckerfish”: http://www.htmldog.com/articles/suckerfish/ */

/* Ce script est nécessaire à MSIE pour mimer le comportement de la pseudo-classe « :hover » sur un élément « <li/> ». */

/*var args=SmartDL.arguments;
	for (n=0;n<args.length;n+=2) {*/
	
function SmartHover(who) {
	if (document.all&&document.getElementById&&document.getElementById(who)) {
		navRoot=document.getElementById(who);
		for (i=0;i<navRoot.childNodes.length;i++) {
			node=navRoot.childNodes[i];
			if (node.nodeName=="DT") {
				node.onmouseover=function() {this.className+=" over";}
				node.onmouseout=function() {this.className=this.className.replace(" over", "");}
			}
		}
	}
}

/* ______________________[ 07 | Lancement des scripts : méthode dite « Unobtrusive JavaScript » ]________________________ */

window.onload=function() {
	SmartList("Navigation");
	externalLinks();
	SmartNav('Transversal');
	SmartDL("RefMenu",0);
	SmartHover("RefMenu");
	 if (navigator.appVersion.indexOf('Mac')!=-1 && document.all) {
	 	fixmacie("clearfix");	
	}
	legendHandler();
}