﻿(function($) {
    var settings = {
        waittime: 2100,
        //fade: "normal"
        fade:1000
    };

    $.fn.Rotate = function(options) {
        settings = $.extend(settings, options);

        //filter out the ones widt 1 child
        var selected = this.filter(function() { return $(this).children().length > 1 });
        var count = selected.length;
        var current = 0;

        var rotate = function() {
            selected.eq(current).children(":visible").fadeOut(settings.fade, function() {
                var self = $(this);

                current++;
                if (current >= count) {
                    current = 0;
                }

                var next = (!self.is(":last-child") ? self.next() : self.parent().children(":first-child"));
                next.fadeIn(settings.fade, function() {
                    self.removeClass("hide");
                    setTimeout(rotate, settings.waittime);

                });

            });
        };

        if (count > 0) {
            setTimeout(rotate, settings.waittime);
        }

    };
})(jQuery);

$(function() {
$("#rotator").Rotate();
});


