﻿(function ($) {
    $.fn.HeaderRotator = function () {
        var Logotype = $(this);
        
        var Items = [];
        var CurrentIndex = 0;

        var FadeSpeed = (125 * 10);
        var ChangePeriod = (15 * 1000);

        var intervalObject;

        var Initialize = function () {
            var posEl = null;

            $.each(Logotype.find("div"), function (index, value) {
                if (index > 0) {
                    Items[CurrentIndex = (index - 1)] = $(value).css({
                        left: posEl.position().left,
                        top: posEl.position().top
                    }).hide();
                } else {
                    posEl = $(value);
                }
            });

            RotateBanner();

            intervalObject = setInterval(RotateBanner, ChangePeriod);
        };

        var RotateBanner = function () {
            Items[CurrentIndex].fadeOut(FadeSpeed);

            CurrentIndex = (CurrentIndex < (Items.length - 1))
                ? (CurrentIndex + 1) : 0;

            Items[CurrentIndex].fadeIn(FadeSpeed);
        };

        Initialize();
    };
})(jQuery);

$(document).ready(function (evt) {
    $(".Logotype").HeaderRotator();
});
