﻿(function ($) {

    $.fn.rotator = function (delayTime, delayStart) {
        // global container variables
        var parentContainer = "";
        var childContainer = "";
        var currentIndex = 0;
        var maxIndex = 0;


        function fadeInContent() {
            childContainer.eq(currentIndex).fadeIn(1000);
            window.setTimeout(function () { fadeOutContent() }, delayTime);
        }

        function fadeOutContent() {
            childContainer.eq(currentIndex).fadeOut(1000);

            currentIndex++;
            if (currentIndex >= maxIndex) {
                currentIndex = 0;
            }

            window.setTimeout(function () { fadeInContent() }, 1500);
        }

        this.each(function () {
            parentContainer = $(this);
            childContainer = $(parentContainer.children("div"));
            maxIndex = childContainer.size();

            childContainer.css('display', 'none');

        });

        window.setTimeout(function () { fadeInContent() }, delayStart);

        return this;
    };

})(jQuery);

