/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \
|		
|		Copyright (c) 2008
|		Design + HTML/CSS/DOM JavaScript : Smart Agence
|		http://www.smartagence.com/
|		
\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

var $jQ = jQuery.noConflict();


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", "");}
			}
		}
	}
	SmartFocus(who);
}

function SmartFocus(who) {
	var navLnk=$id(who).getElementsByTagName("A");
	var navItm=$id(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&&$id("Tplus")&&$id("Tmoins")) {
		var cibleplus=$id("Tplus");
		var ciblemoins=$id("Tmoins");
		cibleplus.onclick=function() {
			for (n=0;n<args.length;n++) {
				if ($id(args[n])) {
					var cibletxt=$id(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 ($id(args[n])) {
					var cibletxt=$id(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 ]________________________ */


/*	DL refermable	*/

function SmartDL() {
	var args=SmartDL.arguments;
	if(typeof args[0] === "object") {
		SmartDLEffect(args[0],args[1]);
	} else {
		for (n=0;n<args.length;n+=2) {
			 if (document.getElementById && $id(args[n])) {
				SmartDLEffect($id(args[n]),args[n+1]);
			 }
		}
	}
};


function SmartDLEffect(oRoot,ClickFx) {
	var root=oRoot.getElementsByTagName("DT");
	var Sister;
	for (a=0;a<root.length;a++) {
		Sister = null;
		root[a].innerHTML = '<a>'+root[a].innerHTML+'</a>';
		if (root[a].nextSibling.nodeName=="DD") {Sister=root[a].nextSibling;}
		else if (root[a].nextSibling.nextSibling.nodeName=="DD") {Sister=root[a].nextSibling.nextSibling;}
		if (root[a].className!="on") {
			Sister.className="off";
		}
		else {
			Sister.className="on";
		} 
		SmartOpenClose(root[a],Sister,ClickFx);
	}
};

function SmartOpenClose(who,Sister,ClickFx) {
	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<who.parentNode.childNodes.length;a++) {
				if (who.parentNode.childNodes[a].nodeName=="DT") {who.parentNode.childNodes[a].className="";}
				else if (who.parentNode.childNodes[a].nodeName=="DD") {who.parentNode.childNodes[a].className="off";}
			}
			AllDT=who.parentNode.getElementsByTagName("DT");
			AllDD=who.parentNode.getElementsByTagName("DD");
			for (b=0;b<AllDT.length;b++) {
				AllDT[b].className="off";
			}
			for (c=0;c<AllDD.length;c++) {
				AllDD[c].className="off";
			}
			who.className="on";
			Sister.className=(Sister.className==" on"?"":"on");
		}
	}
};



/* 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)
};

/* ______________________[ 08 | Lancement des scripts ]________________________ */

window.onload=function() {
	document.getElementsByTagName("body")[0].className += " jsOn";
	SmartHover("NavigationPrincipale");
	SmartSize("ColA","ColB","ColContenu");
	SmartDL("Tendances",1);
	/* IE 5-6 background flicker fix */
	try {document.execCommand('BackgroundImageCache', false, true);}
	catch(e) { }
}



/*		jQuery stuff		*/

$jQ(document).ready(function() {
	$jQ("#galerie").transition({
		thumbSize: 100,
		width: 520,
		height: 510,
		transitionTime: 500,
		displayTime: 3000,
		displayInfoFrom: ".captionInfo"
	});
});
