﻿$(document).ready(function() {
    PreloadImages();
    CallTimeoutForAnimation();
});

var AnimIndex = 0;
var AnimArray = new Array(new GeneralAnimation(), new EconomiqueAnimation(), 
    new CommercialAnimation(), new EducationAnimation(), new FamilleAnimation());

function PreloadImages() {
    var i = 0;
    var objImage = new Image();
    for (i = 0; i < AnimArray.length; i++) {
        objImage.src = AnimArray[i].Picture;
        objImage.src = AnimArray[i].Arrow;
    }
}

function CallTimeoutForAnimation() {
    setTimeout(ThickAnimation, 2000);
}

function ThickAnimation() {
    if (++AnimIndex >= AnimArray.length) { AnimIndex = 0; }

    $("#Animation #Picture").animate({ height: "0px" }, 2000, function() {
        $("#Animation #Picture img").attr("src", AnimArray[AnimIndex].Picture);
        $("#Animation #Picture h6").html("");

        $("#Animation #Picture").animate({ height: "310px" }, 2000, function() {
            $("#Animation #Picture h6").html(AnimArray[AnimIndex].PictureText).css("left", "400px");
            $("#Animation #Picture h6").animate({ left: "20px" }, 2000, function() {
                CallTimeoutForAnimation();
            });
        });
    });

    $("#Animation #Arrow").animate({ opacity: 0 }, 2000, function() {
        $("#Animation #Arrow img").attr("src", AnimArray[AnimIndex].Arrow);
        $("#Animation #Arrow").animate({ opacity: 1 }, 2000);
    });
    
}

function GeneralAnimation() {
    this.Arrow = "/medias/communs/animation-arrow-black.jpg";
    this.Picture = "/medias/communs/animation-general.jpg";
    this.PictureText = "CLD de<br /><strong>Thérèse-De Blainville</strong>";
}
function EconomiqueAnimation() {
    this.Arrow = "/medias/communs/animation-arrow-blue.jpg";
    this.Picture = "/medias/communs/animation-economique.jpg";
    this.PictureText = "Un climat <strong>propice à la<br />croissance</strong>";
}
function CommercialAnimation() {
    this.Arrow = "/medias/communs/animation-arrow-orange.jpg";
    this.Picture = "/medias/communs/animation-commercial.jpg";
    this.PictureText = "Des <strong>commerces et des<br />services</strong> en abondance";
}
function EducationAnimation() {
    this.Arrow = "/medias/communs/animation-arrow-gray.jpg";
    this.Picture = "/medias/communs/animation-education.jpg";
    this.PictureText = "Un pôle d'excellence en <strong>formation<br />spécialisée</strong>";
}
function FamilleAnimation() {
    this.Arrow = "/medias/communs/animation-arrow-green.jpg";
    this.Picture = "/medias/communs/animation-famille.jpg";
    this.PictureText = "Une <strong>qualité de vie<br />incomparable</strong>";
}