﻿
var m_dataXML = null;

var m_arraySlide = null;
var m_arrayLegende = null;

var m_demarrage = false;
var m_StopSlideShow = false;
var m_numSlideActuel = 0;
var m_etape = 0;

var m_LegendeAffiche = "";

function initSlideshowHome() {

    stFile = "../slideshow/slideshowHome.xml";

    m_arraySlide = new Array;
    m_arrayLegende = new Array;

    LectureDataSlideShow(stFile);

    setInterval('animate()', 1500);
}



function LectureDataSlideShow(stFile) {

    // lecture du fichier xml
    if (m_dataXML == null) {
        $.get(stFile, processDataSlideShow);
    }
}



function processDataSlideShow(data, textStatus) {

    // data xml gardé en mémoire
    m_dataXML = data;

    // parcours des données du Slide Show
    $(data).find("slide").each(lectureXML);
}


function lectureXML() {

    var stImage;
    stImage = $(this).find("imageURL").text();
    m_arraySlide.push(stImage);

    var stLegende;
    stLegende = $(this).find("legende").text();
    m_arrayLegende.push(stLegende);

    if (!m_demarrage) {
        m_demarrage = true
        afficheSlide();
    }
}

function afficheSlide(nSlide) {

    var i = m_numSlideActuel;

    m_LegendeAffiche = m_arrayLegende[i];

    var stSlide = m_arraySlide[i];


    if (nSlide == 1) {
        $('#imgSlide1').attr("src", stSlide);
    }

    if (nSlide == 2) {
        $('#imgSlide2').attr("src", stSlide);
    }


    m_numSlideActuel++;
    if (m_numSlideActuel >= m_arrayLegende.length) {
        m_numSlideActuel = 0;
    }
}



function animate() {

    if (!m_StopSlideShow) {

        if (m_etape == 0) {
            $('#divSlide1').show();
            $('#divSlide2').hide();
            afficheSlide(1);
            afficheSlide(2);
            $('#divLegende').html(m_arrayLegende[0]);
        }


        if (m_etape == 1) {
            $('#divSlide1').fadeOut('slow');
            $('#divSlide2').show();
            $('#divLegende').html(m_LegendeAffiche);
        }


        if (m_etape == 2) {
            $('#divSlide1').hide();
            afficheSlide(1);
        }

        if (m_etape == 3) {
            $('#divSlide1').fadeIn('slow');
            $('#divSlide2').fadeOut('slow');
            $('#divLegende').html(m_LegendeAffiche);
        }

        if (m_etape == 4) {
            $('#divSlide1').show();
            $('#divSlide2').hide();
            afficheSlide(2);
        }

        if (m_etape == 5) {
            $('#divSlide1').fadeOut('slow');
            $('#divSlide2').fadeIn('slow');
            $('#divLegende').html(m_LegendeAffiche);
        }


        m_etape++;
        if (m_etape >= 6) {
            m_etape = 2
        }
    }
}


function stopSlideShow() {
    m_StopSlideShow = true;
}


function continueSlideShow() {
    m_StopSlideShow = false;
}
