﻿var homePageRotatorTime = 5000;
var homePageRotatorCurrentDisplay = 1;

$(document).ready(HomePageRotatorLoad);

function HomePageRotatorLoad() {

    if ($(".HomePageRotatorItem").length > 0) {

        $(".HomePageRotatorItem").hide();
        $(".HomePageRotatorItem").first().show();

        if ($(".HomePageRotatorItem").length > 1) {
            setTimeout(HomePageRotatorRotate, homePageRotatorTime);
        }

    }

}

function HomePageRotatorRotate() {

    var nextDisplay = homePageRotatorCurrentDisplay + 1;

    if (nextDisplay > $(".HomePageRotatorItem").length) {
        nextDisplay = 1;
    }

    $(".HomePageRotatorItem").hide();
    $("#HomePageRotatorItem" + nextDisplay).animate({ 'opacity': 'toggle' }, { duration: 1500 });

    homePageRotatorCurrentDisplay = nextDisplay;

    setTimeout(HomePageRotatorRotate, homePageRotatorTime);
}
