/**
 * Fonctions JS communes à toutes les pages
 *
 * @category   js
 * @version    1.0
 * @copyright  Copyright (c) 2007 Creactis, Yann Voumard
 * @license    All rights reserved
 */

/**
 * 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 pour la navigation
 */
function goInternal(_url)
{
    location.href = document.getElementsByTagName('base')[0].href + _url;
}

function showSpectacle(_id)
{
    var win = window.open(document.getElementsByTagName('base')[0].href + 'scene/spectacle/' + _id, 'spectacle_' + _id, 'hotkeys=no,toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,resizable=yes,status=yes,width=700,height=700');
    win.resizeTo(700, 700);
    win.moveTo((screen.width / 2) - 350, (screen.height / 2) - 350);
    win.focus();
}

/**
 * Fonctions utilitaires pour les images
 */
var swappedImg = new Array;

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;
            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;
    }
}