﻿/*****************************************/
/*                                       */
/*  Menu déroulant accessible            */
/*  Version de développement             */
/*  Script DOM dev-menu.js               */
/*  Auteur: koala64                      */
/*  Contact: contact_koala64@yahoo.fr    */
/*                                       */
/*****************************************/

var d = document,
	o = {};

o.Menu =
{

    __Load__: function()
	{

        o.Menu.__Test__();

    },

    __Test__: function()
	{

        if ( !d.getElementById ||
		     !d.getElementsByTagName ||
		     !d.createElement ||
		     !d.createTextNode ||
		     !d.getElementById('menu') ||
		     !d.getElementById('menu').setAttribute ||
		     !d.getElementById('menu').replaceChild ||
		     !d.getElementById('menu').appendChild ||
		     !d.getElementById('menu').getElementsByTagName('dl') ) return false;

		var iA, iB, iC, iD,
			oMenu = d.getElementById('menu'),
			oDl = oMenu.getElementsByTagName('dl');

		for ( iA = oDl.length - 1; iA >= 0; iA-- )
		{
			var oDt = oDl[iA].getElementsByTagName('dt');
			if ( !oDt ) return false;
		}

		for ( iA = oDl.length - 1; iA >= 0; iA-- )
		{
			var oDd = oDl[iA].getElementsByTagName('dd');
			if ( !oDd ) return false;
			else
			{
				for ( iB = oDd.length - 1; iB >= 0; iB-- )
				{
					var oUl=oDd[iB].getElementsByTagName('ul');
					if( !oUl ) return false;
					else
					{
						for ( iC = oUl.length - 1; iC >= 0; iC-- )
						{
							var oLi = oUl[iC].getElementsByTagName('li');
							if( !oLi ) return false;
							else
							{
								for ( iD = oLi.length - 1; iD >= 0; iD-- )
								{
									var oA = oLi[iD].getElementsByTagName('a')[0];
									if( !oA ) return false;
								}
							}
						}
					}
				}
			}
		}

		return o.Menu.__Init__();

	},

	__Init__:function()
	{

        var iA,
			oMenu = d.getElementById('menu'),
			oDl = oMenu.getElementsByTagName('dl');

        o.Menu.__HideLists__();

        for ( iA = oDl.length - 1; iA >= 0; iA-- )
        {
            var oDt = oDl[iA].getElementsByTagName('dt')[0],
				oNewDt = d.createElement('dt'),
				oA = d.createElement('a'),
				oTextA = d.createTextNode('');

			oA.setAttribute('href','#');
            oTextA.data = oDt.firstChild.nodeValue;

            oA.appendChild(oTextA);
            oNewDt.appendChild(oA);
            oDl[iA].replaceChild(oNewDt,oDt);

			oA.onclick = o.Menu.__Discard__;
            oDl[iA].onmouseover = o.Menu.__MouseDisplay__;
            oA.onfocus = o.Menu.__TabDisplay__;
			oA.onkeypress = o.Menu.__TabDisplay__;
        }

    },

    __MouseDisplay__:function()
	{

        o.Menu.__HideLists__();

        var oDd = this.getElementsByTagName('dd')[0];

        oDd.style.display = 'block';

        this.onmouseout = o.Menu.__HideLists__;

    },

    __TabDisplay__:function()
	{

        o.Menu.__HideLists__();

        var oDd = this.parentNode.parentNode.getElementsByTagName('dd')[0];

        oDd.style.display = 'block';

        oDd.getElementsByTagName('a')[0].focus();

    },

    __HideLists__:function()
	{

        var iA,
			oDd = d.getElementById('menu').getElementsByTagName('dd');

        for (iA = oDd.length - 1; iA >= 0; iA-- )
		{
            oDd[iA].style.display = 'none';
		}

    },

    __Discard__:function()
	{

        return false;

    }

};

window.onload=o.Menu.__Load__;