;(function($){
    $.fn.scrollText = function (options) {
        
        var defaults = {
            coef : 10
        };
        
        var o = $.extend(defaults, options);
    
    
        return this.each(function () {
            var $this = $(this);
            var $span = $('<span></span>').html($this.text());
            var coef = o.coef;
            $this
            .css({
                'overflow':'hidden',
                'white-space':'nowrap'
            })
            .html($span);
            
            $this.mouseover(function(){
                var inner = $span;
                var elW = $this.width();
                var inW = inner.width();

                if(inW > elW){
                    var to = (inW - elW)+10;
                    var margin = inner.css('margin-left');
                    margin = parseInt(margin.replace('px',''));
                    var time = (to*coef)-(-margin*coef);
                    inner.stop(true,false).animate({
                        'margin-left':-to
                    },time,'linear');
                }
            })
        
            $this.mouseout(function(){
                var inner = $span;
                var elW = $this.width();
                var inW = inner.width();

                if(inW > elW){
                    var margin = inner.css('margin-left');
                    margin = parseInt(margin.replace('px',''));
                    var time = (-margin*coef);
                    inner.stop(true,false).animate({
                        'margin-left':0
                    },time,'linear');
                }
            });
        });
    }
})(jQuery);
