/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \
|		
|		Copyright (c) 2006 Généthon
|		Design + HTML/CSS/DOM JavaScript : Smart Agence
|		http://www.smartagence.com/
|		
\ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */


/* ______________________[ 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&&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", "");}
			}
		}
	}
	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):11;
					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):11;
					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);
}

function xt_flash(typefl,page){
	Xt_r = document.referrer;
	Xt_h = new Date();
	xt_img = new Image();
	Xt_i = 'http://logi3.xiti.com/hit.xiti?s=69191&s2=1';
	Xt_i += '&p='+page+'&type='+typefl+'&hl=' + Xt_h.getHours() + 'x' + Xt_h.getMinutes() + 'x' + Xt_h.getSeconds();
	if(parseFloat(navigator.appVersion)>=4)
	{Xiti_s=screen;Xt_i += '&r=' + Xiti_s.width + 'x' + Xiti_s.height + 'x' + Xiti_s.pixelDepth + 'x' + Xiti_s.colorDepth;}
	Xt_i += '&ref=' + Xt_r.replace(/[<>"]/g, '').replace(/&/g, '$');
	xt_img.src = Xt_i;
	return;
}

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

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";
	}
}


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

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


function SmartOpenClose(who) {

		if (who.nextSibling.nextSibling&&who.nextSibling.nextSibling.className=="treeview") 
		{
			var Sister=who.nextSibling.nextSibling;
			Sister.style.display="block";
			who.className="on";
		}
	
		else if (who.nextSibling&&who.nextSibling.className=="treeview") {
			var Sister=who.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";
				}
			}	
}		

function SmartPlanDL(arg) {
	if (document.getElementById&&document.getElementById(arg)) {
		var root=document.getElementById(arg).getElementsByTagName("DT");
		for (a=0;a<root.length;a++) {
		if (root[a].nodeName=="DT") {
				SmartOpenCloseDL(root[a]);
			}
		}
	}	
}		


function SmartOpenCloseDL(who2) {

		if (who2.nextSibling.nextSibling&&who2.nextSibling.nextSibling.nodeName=="DD") 
		{
			var Sister=who2.nextSibling.nextSibling;
			Sister.style.display="none";
			who2.className="off";
		}
	
		else if (who2.nextSibling&&who2.nextSibling.nodeName=="DD") {
			var Sister=who2.nextSibling;
			Sister.style.display="none";
			who2.className="off";
		}
		
		
		who2.onclick=function() {
				if (Sister)
				{
				Sister.style.display=Sister.style.display=="none"?"block":"none";
				who2.className=who2.className=="off"?"on":"off";
				}
			}	
}	

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

window.onload=function() {
	SmartHover("NavigationPrincipale");
	SmartSize("ColA","ColB","ColC","ColD","ColMenu","ColContenu","ColContextuel");
	SmartPlan("plansite");
	SmartPlanDL("Newsletter");
	externalLinks();
}


/* ______________________[ 08 | Plan du site ]________________________ */

/*
aqtree3clickable.js

Converts an unordered list to an explorer-style tree, with clickable
icons

To make this work, simply add one line to your HTML:
<script type="text/javascript" src="aqtree3clickable.js"></script>

and then make the top UL of your nested unordered list of class
"aqtree3clickable".

That's it. No registration function, nothing.

http://www.kryogenix.org/code/browser/aqlists/

Stuart Langridge, November 2002
sil@kryogenix.org

Inspired by Aaron's labels.js (http://youngpup.net/demos/labels/) and Dave Lindquist's menuDropDown.js (http://www.gazingus.org/dhtml/?id=109)

*/

addEvent(window, "load", makeTreesC);

function makeTreesC() {
     // We don't actually need createElement, but we do
    // need good DOM support, so this is a good check.
    if (!document.createElement) return;
    
    uls = document.getElementsByTagName("ul");
    for (uli=0;uli<uls.length;uli++) {
        ul = uls[uli];
        if (ul.nodeName == "UL" && ul.className == "treeview") {
            processULELC(ul);
        }
		  
	 } 
}




function processULELC(ul) {
    if (!ul.childNodes || ul.childNodes.length == 0) return;
    // Iterate LIs
    for (var itemi=0;itemi<ul.childNodes.length;itemi++) {
        var item = ul.childNodes[itemi];
        if (item.nodeName == "LI") {
            // Iterate things in this LI
            var a;
            var subul;
	    subul = "";
            for (var sitemi=0;sitemi<item.childNodes.length;sitemi++) {
                var sitem = item.childNodes[sitemi];
                switch (sitem.nodeName) {
                    case "A": a = sitem; break;
                    case "UL": subul = sitem; 
                               processULELC(subul);
                               break;
                }
            }
            if (subul) {
                associateELC(a,subul);
            } else {
                a.parentNode.className = "aq3bullet";
            }
        }
    } 
}

function associateELC(a,ul) {
	
     if (a.parentNode.className.indexOf('aq3open') == -1)
      a.parentNode.className = 'aq3closed';
    a.onclick = function () {
        this.parentNode.className = (this.parentNode.className=='aq3open') ? "aq3closed" : "aq3open";
        return false;
	 }
}


/* tout afficher / tout masquer */

function affichage(element) 
	{
		var uls = document.getElementsByTagName('ul');
		var lis = document.getElementsByTagName('li');
		var hs = document.getElementsByTagName('h2')
		
		if (element=='all')
		{
			for(var i = 0; i < uls.length; ++i) 
			{
				if (uls[i].className=='treeview') {
					uls[i].style.display=uls[i].style.display=="none"?"block":"block";
					
				}
			
			}
			
			for(var i = 0; i < hs.length; ++i) 
			{
				if ((hs[i].nextSibling&&hs[i].nextSibling.className=="treeview") || (hs[i].nextSibling.nextSibling&&hs[i].nextSibling.nextSibling.className=="treeview"))
				hs[i].className="on"
			}
		
			for(var i = 0; i < lis.length; ++i) 
			{
				if (uls.className=='treeview' || lis[i].parentNode.className=='treeview')
				{
				lis[i].className = (lis[i].className=='aq3bullet') ? "aq3bullet" : "aq3open";
				}
			}
		}
		
		else
		{
			for(var i = 0; i < uls.length; ++i) 
			{
				if (uls[i].className=='treeview')
				{
					uls[i].style.display=uls[i].style.display=="block"?"none":"none";
					
				}
			}
			
			for(var i = 0; i < hs.length; ++i) 
			{
				if ((hs[i].nextSibling&&hs[i].nextSibling.className=="treeview") || (hs[i].nextSibling.nextSibling&&hs[i].nextSibling.nextSibling.className=="treeview"))
				hs[i].className="off"
			}
		
			for(var i = 0; i < lis.length; ++i) 
			{
				if (uls.className=='treeview' || lis[i].parentNode.className=='treeview')
				{
				lis[i].className = (lis[i].className=='aq3bullet') ? "aq3bullet" : "aq3open";
				}
			}
		}
	} 


	
/*              Utility functions                    */

function addEvent(obj, evType, fn){
  /* adds an eventListener for browsers which support it
     Written by Scott Andrew: nice one, Scott */
  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;
  }
}


