/**
 * Fonctions JS du skin principal
 *
 * @category   js
 * @version    1.0
 * @copyright  Copyright (c) 2007 Creactis, Yann Voumard
 * @license    All rights reserved
 */

/**
 * Fonctions du menu principal
 */
function initMainMenu()
{
    imgPreload('img/skin/title/cooperative.gif',
               'img/skin/title/scene.gif',
               'img/skin/title/cinema.gif',
               'img/skin/title/cafe.gif',
               'img/skin/title/bibliotheque.gif',
               'img/skin/title/ludotheque.gif',
               'img/skin/title/plan_acces.gif');
               
    imgPreload('img/skin/menu/cooperative_on.gif',
               'img/skin/menu/scene_on.gif',
               'img/skin/menu/cinema_on.gif',
               'img/skin/menu/cafe_on.gif',
               'img/skin/menu/bibliotheque_on.gif',
               'img/skin/menu/ludotheque_on.gif',
               'img/skin/menu/plan_acces_on.gif');
}

function overMainMenu(_entity)
{
    imgSwap('title', 'img/skin/title/' + _entity + '.gif');
    imgSwap(_entity, 'img/skin/menu/' + _entity + '_on.gif');
}

function outMainMenu()
{
    imgRestore();
}

registerInitFunction(initMainMenu);

/**
 * Fonctions du bouton "CONSULTEZ LE PROGRAMME"
 */
function overViewProgramme()
{
    document.getElementById('viewprogramme').style.color = '#FFFFFF';
}

function outViewProgramme()
{
    document.getElementById('viewprogramme').style.color = '#000000';
}

/**
 * Fonctions du menu de l'entit้
 */
var overElement = '';
var hideDelay = 50;

function overEntityMenu(_id, _color)
{
    document.getElementById('level1-' + _id).style.color = _color;
    if(document.getElementById('level2-' + _id))
    {
        document.getElementById('level2-' + _id).style.display = 'block';
    }
    overElement = _id;
}

function outEntityMenu(_id, _color)
{
    window.setTimeout('realOutEntityMenu(\'' + _id + '\', \'' + _color + '\');', hideDelay);
    overElement = '';
}

function realOutEntityMenu(_id, _color)
{
    if(overElement != _id)
    {
        document.getElementById('level1-' + _id).style.color = _color;
        if(document.getElementById('level2-' + _id))
        {
            document.getElementById('level2-' + _id).style.display = 'none';
        }
    }
}

/**
 * Fonctions du POST-it
 */
var runner = null;

function initPostIt()
{
    if(document.getElementById('postit_container') && document.getElementById('postit_child'))
    {
        var container = document.getElementById('postit_container');
        container.style.height = container.offsetHeight + 'px';
        container.style.overflow = 'hidden';
        container.style.position = 'relative';
        container.style.height = '24px';
        
        var child = document.getElementById('postit_child');
        child.style.cssText += ';white-space:nowrap;';
        child.style.overflow = 'hidden';
        child.style.whiteSpace = 'nowrap';
        child.style.position = 'absolute';
        child.style.height = '24px';
        child.style.top = '0px';
        child.style.left = container.offsetWidth + 'px';
        
        startPostIt();
    }
}

function animPostIt()
{
    var child = document.getElementById('postit_child');
    var position = parseInt(child.style.left);
    if(position <= -1 * child.offsetWidth)
    {
        child.style.left = document.getElementById('postit_container').offsetWidth + 'px';
    }
    else
    {
        child.style.left = (position - 1) + 'px';
    }
}

function startPostIt()
{
    runner = setInterval('animPostIt()', 18);
}

function stopPostIt()
{
    clearInterval(runner);
}

registerInitFunction(initPostIt);
