﻿var startPageBannerTimerId = undefined;
var startPageBannerTimerTime = 3000;
function startBanner() {
    if (startPageBannerTimerId == undefined) {
        startPageBannerTimerId = setTimeout(slideBanner, startPageBannerTimerTime);
    }
};

function slideBanner() {
    if ($(".start_page_banner").length && ($(".start_page_banner a img").length > 1)) {

        var currentLink = $(".start_page_banner a.start_page_banner_show");
        if (!currentLink.length) {
            currentLink = $(".start_page_banner a#start_page_banner_link_first");
        }

        var nextLink = currentLink.next();
        if (currentLink.attr("id") == "start_page_banner_link_last") {
            // If currentLink is tha last link we should start over from the the first link
            nextLink = $(".start_page_banner a#start_page_banner_link_first");
        }

        currentLink.find("img").fadeOut(1000, function () {
            currentLink.removeClass("start_page_banner_show");
            currentLink.hide();
            nextLink.show();
            nextLink.find("img").fadeIn(600, function () {
                nextLink.addClass("start_page_banner_show");
                startPageBannerTimerId = setTimeout(slideBanner, startPageBannerTimerTime);
            });
        });
    } else {
        startPageBannerTimerId = undefined;
    }
};

$(document).ready(function () {
    startBanner();
});
