/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \
|		
|		Copyright (c) 2008
|		Design + HTML/CSS/DOM JavaScript : Smart Agence
|		http://www.smartagence.com/
|		
\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

function $id(sID) {
	return document.getElementById(sID);
};

/* ______________________[ 01 | Interactivité du menu principal (menu horizontal) ]________________________ */

/* 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/ */

function SmartHover(who) {
	if (document.all&&document.getElementById&&document.getElementsByTagName&&$id(who)) {
		navRoot=$id(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", "");}
			}
		}
	}
	
	if($id(who)) {
		SmartFocus(who);
	}
};

function SmartFocus(who) {
	var navLnk=document.getElementById(who).getElementsByTagName("A");
	var navItm=document.getElementById(who).getElementsByTagName("LI");
	for (var n=0;n<navItm.length;n++) {
		if (navItm[n].className!="on") navItm[n].className="y";
	}
	for (var i=0;i<navLnk.length;i++) {
		navLnk[i].onfocus=function() {
			if (this.parentNode.parentNode.id==who) {
				this.parentNode.className+=" over";
			} else {
				this.parentNode.parentNode.parentNode.className+=" over";
			}
		}
		navLnk[i].onblur=function() {
			if (this.parentNode.parentNode.id==who) {
				this.parentNode.className=this.parentNode.className.replace(" over", "");
			} else {
				this.parentNode.parentNode.parentNode.className=this.parentNode.parentNode.parentNode.className.replace(" over", "");
			}
		}
	}
}


/* ______________________[ 02 | Gestion de la taille du texte d’un article ]________________________ */

function SmartSize() {
	var args=SmartSize.arguments;
	if (document.getElementById&&document.getElementById("Tplus")&&document.getElementById("Tmoins")) {
		var cibleplus=document.getElementById("Tplus");
		var ciblemoins=document.getElementById("Tmoins");
		cibleplus.onclick=function() {
			for (n=0;n<args.length;n++) {
				if (document.getElementById(args[n])) {
					var cibletxt=document.getElementById(args[n]);
					var sizestr=cibletxt.style.fontSize.substring(0,cibletxt.style.fontSize.length-2);
					var sizeinter=cibletxt.style.lineHeight.substring(0,cibletxt.style.lineHeight.length-2);
					sizestr=sizestr!=""?parseInt(sizestr):12;
					cibletxt.style.fontSize=sizestr+1+"px";
				}
			}
		}
		ciblemoins.onclick=function() {
			for (n=0;n<args.length;n++) {
				if (document.getElementById(args[n])) {
					var cibletxt=document.getElementById(args[n]);
					var sizestr=cibletxt.style.fontSize.substring(0,cibletxt.style.fontSize.length-2);
					var sizeinter=cibletxt.style.lineHeight.substring(0,cibletxt.style.lineHeight.length-2);
					sizestr=sizestr!=""?parseInt(sizestr):12;
					cibletxt.style.fontSize=sizestr-1+"px";
				}
			}
		}
	}
}


/* ______________________[ 03 | Lancement d’une impression pour les navigateurs compatibles ]________________________ */

function DirectPrint() {
	if (window.print) self.print();
}


/* ______________________[ 04 | Miscellaneous ]________________________ */

function OpenPopup(url,nom,option) {
	window.open(url,nom,option);
}


/* ______________________[ 05 | Gestion de l’ouverture/fermeture d’un <h2> » ]________________________ */

function SmartPlan(cible) {
	if (document.getElementById&&document.getElementById(cible)) {
		var root=document.getElementById(cible).getElementsByTagName("H2");
		for (a=0;a<root.length;a++) {
			if (root[a].nodeName=="H2") {
				SmartOpenClose(root[a]);
			}
		}
	}
}

function SmartOpenClose(who) {
	var args=SmartOpenClose.arguments;
	if (who.nextSibling&&who.nextSibling.className=="treeview") {
		var Sister=who.nextSibling;
		Sister.style.display="block";
		who.className="on";
	} 
	if (!document.all&&who.nextSibling.nextSibling&&who.nextSibling.nextSibling.className=="treeview") {
		var Sister=who.nextSibling.nextSibling;
		Sister.style.display="block";
		who.className="on";
	}
	who.onclick=function() {
		if (Sister) {
			Sister.style.display=Sister.style.display=="none"?"block":"none";
			who.className=who.className=="off"?"on":"off";
		}
	}
}


/* ______________________[ 06 | Ajout de la page courante aux favoris ]________________________ */

/* Mettre la page courante en favoris — MSIE and Firefox */
function AddBookmark(btn) {
	if (document.getElementById&&document.getElementById(btn)) {
		var el=document.getElementById(btn);
		var operaStr="« Ctrl + T » pour ajouter aux favoris.";
		if (document.all&&navigator.userAgent.indexOf("Opera")==-1) {
			el.onclick=function() {
				window.external.AddFavorite(document.location,document.title);
			}
		} else if (navigator.userAgent.indexOf("Firefox")!=-1) {
			el.onclick=function () {
				window.sidebar.addPanel(document.title,document.location,"");
			}
		} else if (navigator.userAgent.indexOf("Opera")!=-1) {
			el.title=operaStr;
			window.status=operaStr;
		}
	}
}

/* Get elements by class name(s) */
function getElementsByClassName(oElm, strTagName, oClassNames){		//src element, target element tag, class name(s)
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var arrRegExpClassNames = new Array();
	if(typeof oClassNames == "object"){
		for(var i=0; i<oClassNames.length; i++){
			arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
		}
	}
	else{
		arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
	}
	var oElement;
	var bMatchesAll;
	for(var j=0; j<arrElements.length; j++){
		oElement = arrElements[j];
		bMatchesAll = true;
		for(var k=0; k<arrRegExpClassNames.length; k++){
			if(!arrRegExpClassNames[k].test(oElement.className)){
				bMatchesAll = false;
				break;
			}
		}
		if(bMatchesAll){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
};


/* ______________________[ 07 | <select/> au clavier ]________________________ */

/* Thanks goes to Cameron Adams from http://www.themaninblue.com/ */

function initSelect(whichSelect) {
	if (document.getElementById&&document.getElementById(whichSelect)) {
		var theSelect=document.getElementById(whichSelect);
		theSelect.changed=false;
		theSelect.onfocus=selectFocussed;
		theSelect.onchange=selectChanged;
		theSelect.onkeydown=selectKeyed;
		theSelect.onclick=selectClicked;
		return true;
	}
}

function selectChanged(theElement) {
	var theSelect;
	if (theElement&&theElement.value) {
		theSelect=theElement;
	} else {
		theSelect=this;
	}
	if (!theSelect.changed) {
		return false;
	}
	if (theSelect.value&&theSelect.value!="0") window.location=theSelect.value;
	return true;
}

function selectClicked() {
	this.changed=true;
}

function selectFocussed() {
	this.initValue=this.value;
	return true;
}

function selectKeyed(e){
	var theEvent;
	var keyCodeTab="9";
	var keyCodeEnter="13";
	var keyCodeEsc="27";
	if (e) {
		theEvent=e;
	} else {
		theEvent=event;
	}
	if ((theEvent.keyCode==keyCodeEnter||theEvent.keyCode==keyCodeTab)&&this.value!=this.initValue) {
		this.changed=true;
		selectChanged(this);
	} else if (theEvent.keyCode==keyCodeEsc) {
		this.value=this.initValue;
	} else {
		this.changed=false;
	}
	return true;
}


/* ______________________[ 08 | Lancement des scripts ]________________________ */

window.onload=function() {
	SmartHover("NavigationPrincipale");
	SmartSize("ColA","ColB","ColC","ColMenu","ColContenu","ColContextuelle");
	/* IE 5-6 background flicker fix */
	try {document.execCommand('BackgroundImageCache', false, true);}
	catch(e) { }
	if(document.getElementById("SiteMap")) {
		document.getElementsByTagName("body")[0].className += " jsOn";
		var SMM = new SiteMapManager("SiteMap").apply();
	}
}



// jQuery
var $jQ = jQuery.noConflict();
$jQ(document).ready(function() {
	/* Fondu bandeau home	*/
	$jQ("#Banners, .bannergroup").cycle({
		fx:"fade",
		timeout:5000	
	});
	/* Bloc Références */
	$jQ("#References .inner2>div[id^=medias_r]").each(function(counter) {
		$jQ(this).find(">ul").wrap('<div class="jCarousel" id="jCarouselLite-'+counter+'"><div class="jCarouselLite"></div></div>');
		if($jQ(this).find(">.jCarousel>.jCarouselLite>ul").children().size() > 3) {
			$jQ(this).find(">.jCarousel").prepend('<a class="jCarouselPrev" title="R&eacute;f&eacute;rences pr&eacute;c&eacute;dentes"><span>&lt;&lt;</span></a>').append('<a class="jCarouselNext" title="R&eacute;f&eacute;rences suivantes"><span>&gt;&gt;</span></a>');
			var $id = $jQ(this).find(">.jCarousel").attr("id");
			$jQ(this).find(">.jCarousel>.jCarouselLite").jCarouselLite({
				btnPrev: "#"+$id+" .jCarouselPrev",
				btnNext: "#"+$id+" .jCarouselNext",
				visible:3,
				auto:2000
			});
		}
	});
	$jQ("#References .inner2>div").hide();
	$jQ("#References li").click(function() {
		$jQ(this).parent().children().removeClass("on");
		$jQ("#References .inner2>div").hide();
		$jQ("#References .inner2>div#medias_"+$jQ(this).attr("id")).show();
		$jQ(this).toggleClass("off");
		$jQ(this).toggleClass("on");
	});
	i=$jQ("#References .inner2>div").length;
	rnd=Math.round(Math.random()*i)%i;
	$jQ("#References li:eq("+rnd+")").toggleClass("on");
	$jQ("#References .inner2>div:eq("+rnd+")").show();
});

