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


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

/* 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)
};

/* ______________________[ 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() {
	var args=SmartHover.arguments;
	for (var a=0;a<args.length;a++) {
		if (document.all&&document.getElementById&&document.getElementsByTagName&&$id(args[a])) {
			node=$id(args[a]).getElementsByTagName("LI");
			for (var i=0;i<node.length;i++) {
				node[i].onmouseover=function() {this.className+=" over";}
				node[i].onmouseout=function() {this.className=this.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.getElementsByClassName(args[n])) {
					var cibletxt=document.getElementsByClassName(args[n])[0];
					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.getElementsByClassName(args[n])) {
					var cibletxt=document.getElementsByClassName(args[n])[0];
					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);
}


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

/* Mettre la page courante en favoris — MSIE; Opera, and Firefox */
function myBookmark() {
	//if (document.getElementById&&document.getElementById(sElementID)) {
	/*	var el=document.getElementById(sElementID);
		var operaStr="&lsaquo; Ctrl + T &rsaquo; pour ajouter aux favoris.";
		if (document.all&&!window.opera) {
			window.external.AddFavorite(document.location,document.title);
		} else if (window.sidebar) {
			window.sidebar.addPanel(document.title,document.location.href,"");
		} else if (window.opera && window.print) {
			el.title=operaStr;
			window.status=operaStr;
		}*/
		bookmarksite(document.title,document.location.href);
//	}
};

function bookmarksite(title,url) {
	if (window.sidebar) { // firefox
		window.sidebar.addPanel(title, url, "");
	}
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all) {// ie
		window.external.AddFavorite(url, title);
	}
};


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

window.onload=function() {
	if($id("plansite")) {
		var SiteMap = new SiteMapManager("plansite").setToggleSwitch(true,"plansite").apply();
	}
	SmartHover("navPrincipale");
	SmartSize("colonneCentre");
	/* IE 5-6 background flicker fix */
	try {document.execCommand('BackgroundImageCache', false, true);}
	catch(e) { }
}
