(function($) {

    $.fn.infoline = function(text, options) {        
        var opts = $.extend({}, $.fn.infoline.defaults, options);
        
        this.each(function() {
            var progress = 0, line = 0;
            var obj = $(this);
            var str = text;
            
            if (str == null) {
                 str = new Array(obj.html());
            }
 
            var render = function() {
                var curstr = str[line];
                obj.text(curstr.substring(0, progress++) + ((progress > 0 && progress < curstr.length) ? opts.typingChar : ''));
                if (progress > curstr.length) {
                    clearInterval(timer);
                    
                    progress = 0;
                    line++;
                    if (line >= str.length) {
                        line = 0;
                    }
                    
                    setTimeout(function() {
                        timer = setInterval(render, opts.speed);
                    }, opts.pause);
                }
            }
            
            var timer = setInterval(render, opts.speed);
            
        });
        return this;
    };
    
    $.fn.infoline.defaults = {
        typingChar: '_',
        speed: 50,
        pause: 2000
    };

})(jQuery);
