/**
 * Fonctions pour la navigation
 */
function goInternal(_url)
{
    location.href = document.getElementsByTagName('base')[0].href + _url;
}

function goAnchor(_id)
{
    location.href = location.href.split('#')[0] + '#' + _id;
}

/**
 * Gestionnaire des fonctions d'initialisation
 */
var initFunctions = new Array;

function registerInitFunction(_function)
{
    initFunctions[initFunctions.length] = _function;
}

function fireInitFunctions()
{
    for(i = 0; i < initFunctions.length; i++)
    {
        initFunctions[i]();
    }
}

window.onload = fireInitFunctions;

/**
 * Fonctions utilitaires pour les images
 */
var swappedImg = new Array;
var version = navigator.appVersion.split("MSIE");
version = parseFloat(version[1]);

function imgPreload()
{
    var d = document;
    if(d.images){
        var i, j = 0, p = new Array, a = imgPreload.arguments;
        for(i = 0; i < a.length; i++)
        {
            p[j] = new Image;
            p[j++].src = a[i];
        }
    }
}

function imgSwap()
{
    var i, j = swappedImg.length, x, a = imgSwap.arguments;
    for(i = 0; i < a.length - 1; i += 2)
    {
        x = document.getElementById(a[i]);
        if(x != null){
            swappedImg[j++] = x;
            if(!x.o) x.o = x.src;
            if(x.className == 'replace' && version < 7 && version >= 5.5)
            {
                x.src = a[i + 1].substring(0, a[i + 1].length - 3) + 'gif';
            }
            else
            {
                x.src = a[i + 1];
            }
        }
    }
}

function imgRestore()
{
    var i, x, a = swappedImg;
    for(i = 0; i < a.length; i++)
    {
        x = a[i];
        if(x.o) x.src = x.o;
    }
}

/**
 * Préchargement des images du menu
 */
function preLoadMenu(section)
{
    if(section == 'index')
    {
        imgPreload('img/menu/index/decolletage/apprendre_on.png',
                   'img/menu/index/decolletage/decolletage_on.png',
                   'img/menu/index/decolletage/mecapraticien_on.png',
                   'img/menu/index/decolletage/polymecanicien_on.png',
                   'img/menu/index/decolletage/secteur_on.png',
                   'img/menu/index/formations/mecapraticien-duale_on.png',
                   'img/menu/index/formations/mecapraticien-modulaire_on.png',
                   'img/menu/index/formations/mecapraticien-pratique_on.png',
                   'img/menu/index/formations/polymecanicien-duale_on.png',
                   'img/menu/index/formations/polymecanicien-ecoles_on.png',
                   'img/menu/index/portrait_on.png',
                   'img/menu/index/contactez-nous_on.png');
    }
    else if(section == 'decolletage')
    {
        imgPreload('img/menu/decolletage/apprendre_on.png',
                   'img/menu/decolletage/decolletage_on.png',
                   'img/menu/decolletage/mecapraticien_on.png',
                   'img/menu/decolletage/polymecanicien_on.png',
                   'img/menu/decolletage/secteur_on.png');
    }
    else if(section == 'formations')
    {
        imgPreload('img/menu/formations/mecapraticien-duale_on.png',
                   'img/menu/formations/mecapraticien-modulaire_on.png',
                   'img/menu/formations/mecapraticien-pratique_on.png',
                   'img/menu/formations/polymecanicien-duale_on.png',
                   'img/menu/formations/polymecanicien-ecoles_on.png');
    }
}
