/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \
|		
|		Copyright (c) 2006 IMM
|		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 DivSetVisible(state, liel)
  {
  // var nodechild=liel.getElementsByTagName('UL')[0];
   var DivRef = liel.getElementsByTagName('UL')[0];  
   var IfrRef = document.getElementById('DivShim');
   if(state)
   {
    DivRef.style.display = "block";
    IfrRef.style.width = DivRef.offsetWidth;
    IfrRef.style.height = DivRef.offsetHeight;
    IfrRef.style.top = DivRef.offsetTop;
    IfrRef.style.left = DivRef.offsetLeft;
    IfrRef.style.zIndex = 1000;
    IfrRef.style.display = "block";
   }
   else
   {
    DivRef.style.display = "none";
    IfrRef.style.display = "none";
   }
  }

function SmartHover(who) {
	if (document.all&&document.getElementById&&document.getElementsByTagName&&document.getElementById(who)) {
		navRoot=document.getElementById(who);
		navRoot.innerHTML+="<iframe id='DivShim' src='javascript:;' scrolling='no' frameborder='0' style='position:absolute; display:none; left:auto; top: auto;'></iframe>";		
		for (i=0;i<navRoot.childNodes.length;i++) {
			node=navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {this.className+=" over";DivSetVisible(true, this);}
				node.onmouseout=function() {this.className=this.className.replace(" over", "");DivSetVisible(false, this);}
			}
		}
	}
	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 | Lancement d’une impression pour les navigateurs compatibles ]________________________ */

function DirectPrint() {
	if (window.print) self.print();
}


/* ______________________[ 03 | Miscellaneous ]________________________ */

function OpenPopup(url,nom,option) {
	window.open(url,nom,option);
}

function SmartRescueForm() {
	var args=SmartRescueForm.arguments;
	for (n=0;n<args.length;n++) {
		var cibleSelectName=args[n];
		if (document.getElementById&&document.getElementById(cibleSelectName)) {
			var cibleSelect=document.getElementById(cibleSelectName);
			cibleSelect.className="show";
		}
	}
}


/* ______________________[ 04 | 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";
	}
}


/* ______________________[ 05 | <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;
}


/* ______________________[ 06 | 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;
    }
}

/*              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;
  }
}


/* ______________________[ 07 | Lancement des scripts : méthode dite « Unobtrusive JavaScript » ]________________________ */

window.onload=function() {
	SmartHover("NavigationPrincipale");
	SmartRescueForm("specialites");
	externalLinks();
	initSelect("specialites");
}



