﻿if (jsStartLoad('Slideshow')) {

jsRequire('Utils');
jsRequire('MinToolkit');

var slideVisible = true;
var slideTime = 7000;
var firstSlideTime = 11000;
var currentSlide = 0;

function slideObject(background, heading, byline) {
    this.background = background;
    this.heading = heading;
    this.byline = byline;
}

// Make the last one in this array match the base pic and blurb set in markup (cycle starts from 0)
var slideArray = [
    //new slideObject("/Content/images/fpManA.jpg", "/Content/images/text/fpInnovative.gif", "This is the area where some information or something about the service can attract people's attention"),
    //new slideObject("/Content/images/fpWomanA.jpg", "/Content/images/text/fpInnovative.gif", "Back to the same woman we had before, but with the heading that originally came with the man's picture"),
    //new slideObject("/Content/images/fpManA.jpg", "/Content/images/text/fpConnecting.gif", "Now the man again with the woman's heading. This one is the last slide"),
    //new slideObject("/Content/images/fpWomanA.jpg", "/Content/images/text/fpConnecting.gif", "Meetseeker is a revolutionary employment and networking tool connecting seekers and employers")
    new slideObject("/Content/images/home-heading2-small.png", "", ""),
    new slideObject("/Content/images/home-heading1-small.png", "", "")
    
];

// animation objects
//var fadeIn, fadeOut;
var preloadedImgs = new Array();
var fpMain, fpHeading, fpByline;

function setupSlideshow() {

    // find the animation target (and other participants)
    fpMain = ElId("fpMain");
    fpHeading = ElId("fpHeading");
    fpByline = ElId("fpByline");

    // start the slideshow
    setTimeout("nextSlide()", firstSlideTime);

    // preload the slideArray pics
    for ( var i = 0; i < slideArray.length; i++ )
    {
        preloadedImgs[i] = new Image();
        preloadedImgs[i].src = slideArray[i].background;
        preloadedImgs[i].src = slideArray[i].heading;
    }
}

// called twice for each change: 1) fade out 2) change pic, change blurb, fade in
function nextSlide() {

    // play the appropriate animation
    if (slideVisible) { // fade it out
        fade(fpMain, 0.4, nextSlide, 1.0, 0);
    }
    else {                  // change the pic, fade back in, restart timer
        // change the image and text
        fpMain.style.backgroundImage = "url(" + slideArray[currentSlide].background + ")";
        fpHeading.src = slideArray[currentSlide].heading;
        fpByline.innerHTML = slideArray[currentSlide].byline;
        // change the counter
        currentSlide += 1;
        if (currentSlide > slideArray.length - 1)
            currentSlide = 0;
        // and fade back in
        fade(fpMain, 0.4, null, 0, 1.0);
        setTimeout("nextSlide()", slideTime);
    }
    slideVisible = !slideVisible;
}

// setupSlideshow() when window finishes loading
addListener(window, 'load', setupSlideshow);

} // Slideshow_js
