(function($) {
    $.fn.marquee = function(options) {
        var settings = {
            speed: 25
        };
        $.extend(settings, options);
        return this.each(function() {
            var  $e = $(this),
                  t = $e.html(),
                 mw = $e.innerWidth(),
                 mh = $e.innerHeight(), 
                ctr = 0
            // elemente erzeugen
               mask = $('<div />').css({ width: mw, height: mh, overflow: "hidden"}),
                div = $('<div />').html(t)
                                  .css({ float: 'left', marginLeft: 0, whiteSpace: 'nowrap' })
                                  .appendTo(mask);
            // element injecten 
            $e.replaceWith(mask);

            // mindestlänge erreichen
            var  dw = div.outerWidth(true);
            while(div.outerWidth(true) < mw+dw && ctr++ < 25) {
                div.append(t);
            }

            // animation
            var speed = dw * settings.speed;
            var animate = function() {
                div.css('margin-left', 0)
                   .animate({ marginLeft: (-1)*dw  }, speed, 'linear', animate);
            }; animate();
        });
    };
})(jQuery);

