﻿var RAPPORT_MAX = 1.5;
var VITESSE = 1.05;
var PERIODE = 10;
function sel(id)
{
    var d = document.getElementById("c_"+id);
    d.style.border = 'solid 2px red';
    d.style.zIndex = 50;
    if(d.title == "")
    {
        d.title = "over";
        changeTaille(d.id, d.style.width, d.style.height,d.style.left , d.style.top);
    }
    else
        d.title = "over";
    
    if(typeDiaporama == "DIAPORAMA")
        goItem(id);
}
function desel(id)
{
    var d = document.getElementById("c_"+id);
    d.style.border = 'solid 2px #6c6364';
    if(d.title == "")
    {
        d.title = "out";
        var originalLeft = parseFloat(d.style.left) + (parseFloat(d.style.width) - parseFloat(d.style.width) / RAPPORT_MAX) / 2;
        var originalTop = parseFloat(d.style.top) + (parseFloat(d.style.height) - parseFloat(d.style.height) / RAPPORT_MAX) / 2;
        changeTaille(d.id, (parseFloat(d.style.width) / RAPPORT_MAX), (parseFloat(d.style.height) / RAPPORT_MAX), originalLeft, originalTop);
    }
    else
        d.title = "out";
}
function changeTaille(nom, width, height, left, top )
{
    var d = document.getElementById(nom);
    if(d.title == "over")
    {
        if(parseFloat(d.style.width) < parseFloat(width) * (RAPPORT_MAX))
        {
            d.style.height = parseFloat(d.style.height) * VITESSE + "px";
            d.style.width = parseFloat(d.style.width) * VITESSE + "px";
            d.style.top = (parseFloat(top) - (parseFloat(d.style.height) - parseFloat(height)) / 2  )+ "px";
            d.style.left = (parseFloat(left) - (parseFloat(d.style.width) - parseFloat(width)) / 2  )+ "px";
            setTimeout("changeTaille('"+nom+"','"+width+"','"+height+"','"+left+"','"+top+"')",PERIODE);
        }
        else
        {
            d.title = "";
            d.style.height = parseFloat(height) * RAPPORT_MAX + "px";
            d.style.width = parseFloat(width) * RAPPORT_MAX + "px";
            d.style.top = (parseFloat(top) - (RAPPORT_MAX * parseFloat(height) - parseFloat(height)) / 2  )+ "px";
            d.style.left = (parseFloat(left) - (RAPPORT_MAX * parseFloat(width) - parseFloat(width)) / 2  )+ "px";
        }
    }
    else if(d.title == "out")
    {
        if(parseFloat(d.style.width) > parseFloat(width))
        {
            d.style.height = (parseFloat(d.style.height) / VITESSE) + "px";
            d.style.width = (parseFloat(d.style.width) / VITESSE) + "px";
            d.style.top = (parseFloat(top) - (parseFloat(d.style.height) - parseFloat(height)) / 2  )+ "px";
            d.style.left = (parseFloat(left) - (parseFloat(d.style.width) - parseFloat(width)) / 2  )+ "px";
            setTimeout("changeTaille('"+nom+"','"+width+"','"+height+"','"+left+"','"+top+"')",PERIODE / 5);
        }
        else
        {
            d.title = "";
            d.style.height = parseFloat(height) + "px";
            d.style.width = parseFloat(width) + "px";
            d.style.top = parseFloat(top) + "px";
            d.style.left = parseFloat(left) + "px";
            d.style.zIndex = 0;
        }
    }
}
function goItem(id)
{
    currentID = id + firstID;
    putBorder();
}
function goL()
{
    if(firstID > 0)
        firstID--;
    if(currentID > 1)
        currentID--;           
    afficheDiap();
    
    if(typeDiaporama == "DIAPORAMA")
        putBorder();
}
function goR()
{
    if(firstID < (nbElements - nbCase))
        firstID++;
    if(currentID < nbElements)
        currentID++;          
    afficheDiap();
    
    if(typeDiaporama == "DIAPORAMA")
        putBorder();
}
function focusBD(btn, img)
{
    btn.src = img;
}
function afficheDiap()
{
    for(var i = 1; i <= nbCase ; i++)
        document.getElementById("c_"+i).src = document.getElementById("rs_"+(i + firstID)).src;
}
function putBorder()
{
    if(nbElements > 0)
    {
        for(var i = 1 ; i <= nbCase ; i++)
            document.getElementById("c_"+i).style.border = 'none';
        document.getElementById("c_"+(currentID - firstID)).style.border = 'solid 1px red';
        
        for(var i = 1 ; i <= nbElements ; i++)
        {
            document.getElementById("div_diapo_img"+i).style.display = 'none';
            document.getElementById("div_diapo_fond"+i).style.display = 'none';
            
            if(document.getElementById("div_legende_texte"+i).innerHTML.length < 2)
                document.getElementById("div_diapo_fond"+i).style.backgroundColor = 'transparent';
            else
                document.getElementById("div_diapo_fond"+i).style.backgroundColor = '#999999';
        }
        document.getElementById("div_diapo_img"+currentID).style.display = 'block';
        document.getElementById("div_diapo_fond"+currentID).style.display = 'block';
    }
}