var iCall = 0;
var iHideCall = 0;
var lastClass = '';
var oLink = null;
var oShadow1, oShadow2, oShadow3;

//Affiche le menu
function showMenu(element,child)
{
if(oShadow1==null)
{var oBody = document.getElementsByTagName('BODY');
oShadow1 = document.createElement("DIV");
oShadow1.id = 'menuShadow1';
oShadow1.className = 'menuShadow';
oShadow1 = oBody[0].appendChild(oShadow1);
oShadow2 = document.createElement("DIV");
oShadow2.id = 'menuShadow2';
oShadow2.className = 'menuShadow';
oShadow2 = oBody[0].appendChild(oShadow2);
oShadow3 = document.createElement("DIV");
oShadow3.id = 'menuShadow3';
oShadow3.className = 'menuShadow';
oShadow3 = oBody[0].appendChild(oShadow3);}

    clearTimeout(iHideCall);
    
    //stockage menu actif
    var oCurrentLink;
    for(var i=0; i<element.childNodes.length;i++)
    {
        if(element.childNodes[i].tagName=='A')
            oCurrentLink = element.childNodes[i];
    }
    if(oCurrentLink!=oLink)
        doHideMenu();
    oLink = oCurrentLink;

    var oMenu = document.getElementById(child);
    var oDestMenu = document.getElementById('subMenu');
    if(oMenu==null || oDestMenu==null)
        return;
    //positionnement
    setMenuPos(totalOffsetLeft(element),totalOffsetHeight(element))
    //clone le menu
    while(oDestMenu.hasChildNodes()==true)
        oDestMenu.removeChild(oDestMenu.childNodes[0]);
    //Clone notre menu dans la div d'accueil
    for(j=0;j<oMenu.childNodes.length;j++)
        oDestMenu.appendChild(oMenu.childNodes[j].cloneNode(true));
    
    //Appelle affichage du menu
    iCall = setTimeout('unhideMenu()',250);
}

//Rend le tooltip visible
function unhideMenu()
{
    var oMenu = document.getElementById('subMenu');
    if(oMenu!=null)
    {
        oMenu.style.display='block';
        oMenu.style.visibility = 'visible';
        if(oLink!=null)
        {
            if(oLink.className!='open')
                lastClass = oLink.className;
            oLink.className = 'open';
        }
        displayShadow(oShadow1,oMenu);
        displayShadow(oShadow2,oMenu);
        displayShadow(oShadow3,oMenu);
    }
}

function displayShadow(oShadow, oDiv)
{
    var iPaddingOffsetX = 0;
    var iPaddingOffsetY = 0;
    if(oShadow!=null)
    {oShadow.style.width = oDiv.offsetWidth+'px';
    oShadow.style.height = oDiv.offsetHeight+'px';
    oShadow.style.visibility = 'visible';
    oShadow.style.display = 'block';
    if(oShadow.offsetWidth > oDiv.offsetWidth){iPaddingOffsetX = oShadow.offsetWidth - oDiv.offsetWidth;}
    if(oShadow.offsetHeight > oDiv.offsetHeight){iPaddingOffsetY = oShadow.offsetHeight - oDiv.offsetHeight;}
    oShadow.style.width = (oDiv.offsetWidth - iPaddingOffsetX)+'px';
    oShadow.style.height = (oDiv.offsetHeight - iPaddingOffsetY)+'px';}
}
function hideShadow(oShadow)
{
    if(oShadow!=null)
    {
    oShadow.style.visibility = 'hidden';
    oShadow.style.display = 'none';
    }
}

//Appele le cache du menu
function hideMenu()
{
    clearTimeout(iCall);
    iHideCall = setTimeout('doHideMenu()',1000);
}

//Cache le menu
function doHideMenu()
{
    var oMenu = document.getElementById('subMenu');
    if(oMenu!=null)
    {
        if(oMenu.style.visibility=='visible')
        {
            oMenu.style.display = 'none';
            oMenu.style.visibility = 'hidden';
            if(oLink!=null)
                oLink.className = lastClass;
            hideShadow(oShadow1);
            hideShadow(oShadow2);
            hideShadow(oShadow3);
        }
    }
}

//Annule le cache du menu
function fixMenu()
{
    clearTimeout(iHideCall);
}

function totalOffsetHeight(object)
{
    var offset = object.offsetTop + object.parentNode.offsetHeight;
    var oParent = object.parentNode;
    while(oParent!=null)
    {
        if(oParent.offsetTop)
            offset += Number(oParent.offsetTop);
        oParent = oParent.parentNode;
    }
    return offset;
}
function totalOffsetLeft(object)
{
    var offset = Number(object.offsetLeft);
    var oParent = object.parentNode;
    while(oParent!=null)
    {
        if(oParent.offsetLeft)
            offset += Number(oParent.offsetLeft);
        oParent = oParent.parentNode;
    }
    return offset;
}

function setMenuPos(x,y)
{var oDiv = document.getElementById('subMenu');
oDiv.style.top = y + 'px';
oDiv.style.left = x + 'px';
if(oShadow1!=null)
{oShadow1.style.left = (x + 2)+'px';oShadow1.style.top = (y + 2)+'px';}
if(oShadow2!=null)
{oShadow2.style.left = (x + 3)+'px';oShadow2.style.top = (y + 3)+'px';}
if(oShadow3!=null)
{oShadow3.style.left = (x + 4)+'px';oShadow3.style.top = (y + 4)+'px';}
}
