﻿var timeout;
var animating = false;
function InitHeaders(time) {
    $(".image-headers").hide().first().show();
    ResetTimeoutTime(time + 1000);
    $(".thumb-headers").click(function() {
        if (!animating) {
            animating = true;
            var headerImageId = $(this)[0].id.replace("smallImage", "bigImage");
            $(".headerThumbActive").removeClass("headerThumbActive");
            $(this).addClass("headerThumbActive");
            $(".image-headers:visible").fadeOut(600); //.hide();
            var toShow = $("#" + headerImageId);
            toShow.fadeIn(600, function() {
                animating = false;
                toShow.css("display", "block");
            });   //.show();
            ResetTimeoutTime(time + 1000);
        }
    }).first().addClass("headerThumbActive");
}
function GoNext(timeoutTime) {
    if (!animating) {
        animating = true;
        var toHide = $(".image-headers:visible");
        toHide.fadeOut(600); //.hide();
        var toShow = ((toHide.next().length == 1) ? toHide.next() : toHide.parent().children(":first")).fadeIn(600, function() {
            animating = false;
            toShow.css("display", "block");
        });   //.show();
        $(".headerThumbActive").removeClass("headerThumbActive");
        $("#" + toShow[0].id.replace("bigImage", "smallImage")).addClass("headerThumbActive");
        ResetTimeoutTime(timeoutTime);
    }
};
function ResetTimeoutTime(timeoutTime) {
    clearTimeout(timeout);
    var delay = function() { GoNext(timeoutTime); };
    timeout = setTimeout(delay, timeoutTime);
}
