﻿(function ($) {
    $.fn.Scroller = function (options) {
        var defaults = { speed: 1, center: true };
        var options = $.extend(defaults, options);

        //Init
        window.scrollerBegin = function (elem) {
            if (elem == undefined) elem = window.scrollerElement;
            $(elem).css({ marginLeft: 0 }).animate({ marginLeft: -$(elem).attr("totalWidth") }, ($(elem).width() * 10) / parseInt(options["speed"]), "linear", function () { window.scrollerBegin(this); });
        }
        this.each(function () {
            var scroller = this;
            var max = 60;
            window.scrollerElement = this;
            $(this).attr("totalwidth", 0);
            $(this).children().each(function () {
                this.scroller = scroller;
                $(this).bind("load", function () {
                    if (options.center) $(this).css("margin-top", (max - $(this).height()) / 2);
                    var width = parseInt($(this.scroller).attr("totalwidth")) + parseInt($(this).outerWidth(true));
                    $(this.scroller).attr("totalwidth", width).width(width * 2);
                    $(this).siblings().filter(":last").after($(this).clone());
                    $(this).css({ backgroundColor: "#f00" });
                });
                $(this).attr("src", $(this).attr("src"));
            });
            setTimeout("window.scrollerBegin()", 200);


        });



    };
})(jQuery);
