(function ($) {
    $.fn.simpleFade = function (options) {
        var defaults = {
            child: "img",
            speed: 1000,
            duration: 4000,
            loop: true,
            hover: true
        };
        var options = $.extend(defaults, options);
        return this.each(function () {
            var a = [];
            a[0] = options.child;
            a[1] = options.speed;
            a[2] = options.duration;
            a[3] = options.loop;
            a[4] = options.hover;
            a[5] = $(this);
            a[6] = false;
            a[5].css({ "position": "relative", "height": a[5].children(a[0]).first().height() + "px" }).bind("mouseenter", function () {
                a[6] = true;
            }).bind("mouseleave", function () {
                a[6] = false;
            }).children(a[0]).css({ "position": "absolute", "top": "0px", "left": "0px" });
            var i = 0;
            var l = a[5].children(a[0]).length;
            function fadeLoop() {
                if (a[4] == true && a[6] == true) {
                    setTimeout(fadeLoop, 100);
                } else {
                    if (a[3] == false) {
                        i += 1;
                        if (i >= l) {
                            return false;
                        };
                    };
                    a[5].children(a[0]).last().delay(a[2]).fadeTo(a[1], 0, function () {
                        $(this).prependTo(a[5]).fadeTo(0, 1, function () {
                            fadeLoop();
                        });
                    });
                }
            }
            $(window).load(function () {
                a[5].css("height", a[5].children(a[0]).first().height() + "px");
                fadeLoop();
            });
        });
    };
})(jQuery);
