﻿var DisplayZIndex = 40;
var FadeInZIndex = 45;
var CurrentBanner = 1;
var Delay = 5000;
var Timeout;
var TotalBanners;

function showBanner(banner) {
    clearTimeout(Timeout);

    if (banner == CurrentBanner) {
        Timeout = setTimeout(function () { nextBanner(); }, Delay);
        return;
    }

    $(".Banner-Image:nth-child(" + banner + ")").css("zIndex", FadeInZIndex).fadeIn("slow", function () { $(this).css("zIndex", DisplayZIndex); $(".Banner-Image:not(:nth-child(" + banner + "))").hide(); Timeout = setTimeout(function () { nextBanner(); }, Delay); });
    $(".Banner-Squares DIV:not(:nth-child(" + banner + "))").fadeTo("slow", 0.3);
    $(".Banner-Squares DIV:nth-child(" + banner + ")").fadeTo("slow", 0.6);
    CurrentBanner = banner;
};

function nextBanner() {
    if (CurrentBanner >= TotalBanners)
        showBanner(1);
    else
        showBanner(CurrentBanner + 1);
}

$(function () {
    TotalBanners = $(".Rotating-Banner").children(":not(.Banner-Squares)").length;

    $(".Rotating-Banner").children(":gt(0):not(.Banner-Squares)").hide().addClass("Banner-Image");
    $(".Rotating-Banner").children(":first").css("zIndex", DisplayZIndex).addClass("Banner-Image");
    $(".Banner-Squares DIV").fadeTo(0, 0.3);
    $(".Banner-Squares DIV:first").fadeTo(0, 0.6);

    Timeout = setTimeout(function () { nextBanner(); }, Delay);
});
