// JavaScript Document

var menu = document.getElementById('menu');
var itemsMenu = menu.getElementsByTagName('li');

function ecouteur(cible){
	if (typeof document.addEventListener == "function")	{
		cible.addEventListener("mouseover", function(event){liover(cible);chgFond(cible, 'on');}, false);
		cible.addEventListener("mouseout", function(event){liout(cible);chgFond(cible, 'off');}, false);
	}
	/* IE */
	else	{
		cible.attachEvent("onmouseover", function(event){liover(cible);chgFond(cible, 'on');});
		cible.attachEvent("onmouseout", function(event){liout(cible);chgFond(cible, 'off');});
	}
}

for(var i=0; i<itemsMenu.length; i++){
	if(itemsMenu[i].id!=''){
		var liste=itemsMenu[i];
		ecouteur(liste);
		}
}

function getStyle (a_element, a_cssproperty) {
    if (window.getComputedStyle) {
        return window.getComputedStyle(a_element,null).getPropertyValue(a_cssproperty);
    } else if (a_element.currentStyle) {
        while (a_cssproperty.indexOf('-') != -1) {
            var letter = a_cssproperty.charAt(a_cssproperty.indexOf('-')+1);
            a_cssproperty = a_cssproperty.replace(/-\S{1}/,letter.toUpperCase());
        }
        return eval('a_element.currentStyle.' + a_cssproperty);
    }
    return "";
}




function findUl(obj){
	var ul=null;
	if(obj.hasChildNodes){
		var lien=obj.firstChild;
		if(lien.nextSibling.nodeName=="UL")ul = lien.nextSibling;
	}
	return ul;
}


function chgFond(obj, etat){
try{
	var src=getStyle(obj, "background-image").split("url(");
	src=src[src.length-1].split(")");
	var quote=/\"/gi;
	src=src[0].replace(quote,"");
	
	if(etat=='on')var roll=src.replace("_off","_on");
	if(etat=='off')var roll=src.replace("_on","_off");
	
	obj.style.backgroundImage="url('"+roll+"')";
	
	} catch(e){};
}

function liover(obj){
	try{
	// masque - affiche
	var ul=findUl(obj);
	if(ul!=null)ul.style.visibility='visible';
	} catch(e){};
}


function liout(obj){
	try{
	// masque - affiche
	var ul=findUl(obj);
	if(ul!=null)ul.style.visibility='hidden';

	} catch(e){};
}