var imgs = new Array();

var animTime = 5;
var timer = animTime; //Starts animation onPageLoad
var index = 0; //Index of image being animated
var previous = 0; //Index of i

function runBanner(numImgs) {
    for (var i = 0; i < numImgs; i++)
        imgs[i] = String(i);
    var t = setTimeout("timedCount()", 1000);
}

function timedCount() {
    timer++;
    if (timer >= animTime) {
        $("#" + imgs[index]).css("z-index", "50");
        $("#" + imgs[index]).animate({ opacity: 1 }, "slow", function () { endAnimation(); });
    }
    t = setTimeout("timedCount()", 1000);
}

function endAnimation() {
    timer = 0;

    if (index < imgs.length - 1) {
        if (index == 0) {
            document.getElementById(imgs[previous]).style.zIndex = "-5"
        }
        previous = index;
        index++;
    }
    else {
        for (var i = 0; i < imgs.length - 1; i++) //put images in correct order except for last so last image stays on top for transition
            document.getElementById(imgs[i]).style.zIndex = "0";
        document.getElementById(imgs[index]).style.zIndex = "0";
        previous = index;
        index = 0;
    }
    document.getElementById(imgs[index]).style.zIndex = "10";
    $("#" + imgs[index]).css("opacity", 0);
}
