//
// Returns an array of URLs of banner images; the length of the array is the numRandBanners parameter.
//
function randomBannerUrls(numRandBanners) {
    var bannerUrls = new Array();
    var numBanners = 14;

    for (var i = 0; i < numRandBanners; i++) {
        var r = Math.round(Math.random() * (numBanners - 1)) + 1;
        bannerUrls.push("/images/banner" + r + ".jpg");
    }

    return bannerUrls;
}

//
// Post-load banner images to improve perceived page load time.
//
function postLoadBanners() {
    var randBanners = randomBannerUrls(4);

    $("#banner2").css({ "background-image": "url(" + randBanners[0] + ")" });
    $("#banner3").css({ "background-image": "url(" + randBanners[1] + ")" });
    $("#banner4").css({ "background-image": "url(" + randBanners[2] + ")" });
    $("#banner5").css({ "background-image": "url(" + randBanners[3] + ")" });
}

function animation() {
    //
    // Animation.
    //
    $("#banner2").fadeIn({ duration: 2500, preDelay: 12500, easing: "easeOutSine", queue: "banner" });
    $("#banner3").fadeIn({ duration: 2500, preDelay: 12500, easing: "easeOutSine", queue: "banner" });
    $("#banner4").fadeIn({ duration: 2500, preDelay: 12500, easing: "easeOutSine", queue: "banner" });
    $("#banner5").fadeIn({ duration: 2500, preDelay: 12500, easing: "easeOutSine", queue: "banner" });
    $("#banner5").fadeOut({ duration: 2500, preDelay: 12500, easing: "easeOutSine", queue: "banner" });
    $("#banner4").fadeOut({ duration: 2500, preDelay: 12500, easing: "easeOutSine", queue: "banner" });
    $("#banner3").fadeOut({ duration: 2500, preDelay: 12500, easing: "easeOutSine", queue: "banner" });
    $("#banner2").fadeOut({ duration: 2500, preDelay: 12500, easing: "easeOutSine", queue: "banner" });
    $("#banner2").fadeIn({ duration: 2500, preDelay: 12500, easing: "easeOutSine", queue: "banner" });
    $("#banner3").fadeIn({ duration: 2500, preDelay: 12500, easing: "easeOutSine", queue: "banner" });
    $("#banner4").fadeIn({ duration: 2500, preDelay: 12500, easing: "easeOutSine", queue: "banner" });
    $("#banner5").fadeIn({ duration: 2500, preDelay: 12500, easing: "easeOutSine", queue: "banner" });
}

$(document).ready(function() {
    postLoadBanners();
    animation();
});
