/****** BEGIN LICENSE BLOCK *****
 * Copyright (c) 2005-2006 Harmen Christophe and contributors. All rights reserved.
 * 
 * This script is free software; you can redistribute it and/or
 *   modify under the terms of the Creative Commons - Attribution-ShareAlike 2.0
 * <http://creativecommons.org/licenses/by-sa/2.0/>
 * You are free:
 *     * to copy, distribute, display, and perform the work
 *     * to make derivative works
 *     * to make commercial use of the work
 * 
 * Under the following conditions:
 * _Attribution_. You must attribute the work in the manner specified by the
 *   author or licensor.
 * _Share Alike_. If you alter, transform, or build upon this work, you may
 *   distribute the resulting work only under a license identical to this one.
 *     * For any reuse or distribution, you must make clear to others 
 *      the license terms of this work.
 *     * Any of these conditions can be waived if you get permission from 
 *      the copyright holder.
 * 
 * Your fair use and other rights are in no way affected by the above.
 * 
 * This is a human-readable summary of the Legal Code (the full license). 
 * <http://creativecommons.org/licenses/by-sa/2.0/legalcode>
 ***** END LICENSE BLOCK ******/



/******************************************************************************
 * Le script est dans une version light sans :
 *  - gestion de la désactivation des couleurs
 *  - possibilité de désactiver le dit menu 
 *  - prise en charge des niveaux sans scripting
 *  .... bref, une version bien bridée ;-(  
//*/
function trim(s) {return s.replace(/^\s+|\s+$/g,"");}
function hasClassName(oNode,className) {
	return (oNode.nodeType==1)?
		((" "+oNode.className+" ").indexOf(" "+className+" ")!=-1):false;
}
function addClassName(oNode,className) {
	if ((oNode.nodeType==1) && !hasClassName(oNode,className))
		oNode.className = trim(oNode.className+" "+className);
}
function deleteClassName(oNode,className) {
	if (oNode.nodeType==1)
    oNode.className = trim((" "+oNode.className+" ").replace(" "+className+" "," "));
}
function isChildNodeOf(oNode,other) {
	if (oNode.compareDocumentPosition) {
		return (oNode.compareDocumentPosition(other)==10);
	} else if (other.contains) {
		return other.contains(oNode);
	}
	var bIsChildNodeOf = false;
	function _isChildNodeOf(oNode,other) {
		while (other) {
			if (other==oNode) {
				bIsChildNodeOf = true;
				return;
			} else _isChildNodeOf(oNode,other.firstChild);
			other = other.nextSibling;
		}
	}
	_isChildNodeOf(oNode,other.firstChild);
	return bIsChildNodeOf;
}
function addEventLst(EventTarget,type,listener,useCapture) {
	useCapture = typeof(useCapture)=="boolean"?useCapture:false;
	if (EventTarget.addEventListener) {
		EventTarget.addEventListener(type, listener, useCapture);
	} else if ((EventTarget==window) && document.addEventListener) {
		document.addEventListener(type, listener, useCapture);
	} else if (EventTarget.attachEvent) {
		EventTarget["e"+type+listener] = listener;
		EventTarget[type+listener] = function() {EventTarget["e"+type+listener](window.event);}
		EventTarget.attachEvent("on"+type, EventTarget[type+listener]);
	}
}
function removeEventLst(EventTarget,type,listener,useCapture) {
	useCapture = typeof(useCapture)=="boolean"?useCapture:false;
	if (EventTarget.removeEventListener) {
		EventTarget.removeEventListener(type,listener, useCapture);
	} else if ((EventTarget==window) && document.removeEventListener) {
		document.removeEventListener(type,listener, useCapture);
	} else if (EventTarget.detachEvent) {
        try { // MSIE ne semble pas gérer le unload correctement (¿)
            EventTarget.detachEvent("on"+type, EventTarget[type+listener]);
            EventTarget[type+listener]=null;
            EventTarget["e"+type+listener]=null;
        } catch(e) {}
	}
}
function evtLstLoad() {
    removeEventLst(window,"load",evtLstLoad); // MSIE Memory Leaks
    loadMenus();
}
function evtLstUnLoad() {
    removeEventLst(window,"unload",evtLstLoad); // MSIE Memory Leaks
    unloadMenus();
}
addEventLst(window,"load",evtLstLoad);
addEventLst(window,"unload",evtLstUnLoad); // MSIE Memory Leaks

var menu_timerID = null;
function loadMenus() {
    var nMenu;
    if (!(nMenu = document.getElementById("navigation"))) {return;}
	if (nMenu.addEventListener) {
		nMenu.addEventListener("mouseover",eventLstMontrerMenu,true);
		nMenu.addEventListener("focus",eventLstMontrerMenu,true);
		nMenu.addEventListener("DOMFocusIn",eventLstMontrerMenu,true);
		nMenu.addEventListener("mouseout",eventLstCacherMenus,true);
		nMenu.addEventListener("blur",eventLstCacherMenus,true);
		nMenu.addEventListener("DOMFocusOut",eventLstCacherMenus,true);
	} else {
		var nA;
		var nChild=nMenu.firstChild;
		while (nChild) {
			if (hasClassName(nChild,"theme")) {
				addEventLst(nChild,"mouseover",eventLstMontrerMenu);
				addEventLst(nChild,"mouseout",eventLstCacherMenus);
				for (var j=0; nA = nChild.getElementsByTagName("a")[j]; j++) {
					addEventLst(nA,"focus",eventLstMontrerMenu);
					addEventLst(nA,"blur",eventLstCacherMenus);
				}
			}
			nChild=nChild.nextSibling;
		}
	}
}
function unloadMenus() {
    var nMenu;
    if (!(nMenu = document.getElementById("navigation"))) {return;}
	if (nMenu.removeEventListener) {
		nMenu.removeEventListener("mouseover",eventLstMontrerMenu,true);
		nMenu.removeEventListener("focus",eventLstMontrerMenu,true);
		nMenu.removeEventListener("DOMFocusIn",eventLstMontrerMenu,true);
		nMenu.removeEventListener("mouseout",eventLstCacherMenus,true);
		nMenu.removeEventListener("blur",eventLstCacherMenus,true);
		nMenu.removeEventListener("DOMFocusOut",eventLstCacherMenus,true);
	} else {
		var nA;
		var nChild=nMenu.firstChild;
		while (nChild) {
			if (hasClassName(nChild,"theme")) {
				removeEventLst(nChild,"mouseover",eventLstMontrerMenu);
				removeEventLst(nChild,"mouseout",eventLstCacherMenus);
				for (var j=0; nA = nChild.getElementsByTagName("a")[j]; j++) {
					removeEventLst(nA,"focus",eventLstMontrerMenu);
					removeEventLst(nA,"blur",eventLstCacherMenus);
				}
			}
			nChild=nChild.nextSibling;
		}
	}
}
function eventLstMontrerMenu(evt) {
	var oNode;
	if (evt && evt.target) {
		oNode = evt.target;
	} else if (window.event) {
		oNode = window.event.srcElement;
	} else {
		oNode = this;
	}
	if (menu_timerID!=null) {cacherMenus();}
	while (oNode.id!="navigation") {
		if (hasClassName(oNode,"theme")) {
			addClassName(oNode,"currentTheme");
			if (oNode.getElementsByTagName("a").item(0)) {
                addClassName(oNode.getElementsByTagName("a").item(0),'hoverChilds');
            }
			break;
		}
		oNode = oNode.parentNode;
	}
	
	if (window.event &&
		(typeof(window.event.cancelBubble)=="boolean") )
	{
		window.event.cancelBubble = true;
	}
	return false;
}
function eventLstCacherMenus(evt) {
	var oNode, nRelatedTarget;
	if (evt && evt.target) {
		oNode = evt.target;
		nRelatedTarget = evt.relatedTarget;
	} else if (window.event) {
		oNode = window.event.srcElement;
		nRelatedTarget = window.event.toElement;
	} else {
		oNode = this;
	}
	while (oNode.id!="navigation") {
		if (hasClassName(oNode,"theme")) {
			if (nRelatedTarget && (!isChildNodeOf(nRelatedTarget,oNode))) {
				menu_timerID = setInterval("cacherMenus()",800);
			} else if (!nRelatedTarget) {
				cacherMenus();
			}
			break;
		}
		oNode = oNode.parentNode;
	}
	if (window.event &&
		(typeof(window.event.cancelBubble)=="boolean") )
	{
		window.event.cancelBubble = true;
	}
	return false;
}
function cacherMenus() {
	if (menu_timerID!=null) {
		clearInterval(menu_timerID);
		menu_timerID = null;
	}
	var nChild=document.getElementById("navigation").firstChild;
	while (nChild) {
		if (hasClassName(nChild,"theme")) {
            deleteClassName(nChild,"currentTheme");
            if (nChild.getElementsByTagName("a").item(0)) {
                deleteClassName(nChild.getElementsByTagName("a").item(0),'hoverChilds');
            }
        }
		nChild=nChild.nextSibling;
	}
}

