var play = true;
// Delay between animations in milliseconds
var animationDelay = "7000";
//Delay during fadein/fadeout
var fadeDelay = "1000";
var timeout = setTimeout(animationDelay);
$(document).ready(function () {
    $("#centerpiece .story").hide();
    $("#centerpiece .story").first().show();
    $("#centerpiece .nav li").first().addClass("active");
    ShowCenterpiece(1);
    var controls = $("#centerpiece .nav li a");
    controls.click(function (e) {
        e.preventDefault();
        var currentIndex = controls.index($(this)) + 1;
        // Set this to true if you want the click to stop the animation
        //play = false;
        ShowCenterpiece(currentIndex);
    });
});
function Animate() {
    var num = $(".story").index($(".story:visible")) + 1;
    if (play) {
        clearTimeout(timeout);
        timeout = setTimeout(function () {
            if (num >= $("#centerpiece .story").length) num = 0;
            ShowCenterpiece(num + 1);
        }, animationDelay);
    }
}
function ShowCenterpiece(num) {
    var pos = (num - 1);
    $("#centerpiece .nav li").removeClass("active");
    $("#centerpiece .nav li:eq(" + pos + ")").addClass("active");
    $("#centerpiece .story").fadeOut(fadeDelay);
    $("#centerpiece .story:eq(" + pos + ")").fadeIn(fadeDelay, function () {
        Animate();
    });
}
