function delayTimer(delay){
    var timer;
    return function(fn){
        timer=clearTimeout(timer);
        if(fn)
            timer=setTimeout(function(){
                fn();
            },delay);
        return timer;
    }
}

function loadImage(text, color, font){
    $('#target').attr('src', 'font.php?color=' + color + '&text=' + text + '&font=' + font + '&size=40');
}

var text = 'example';
var color = 'black';
var font = 'mistral';
google.setOnLoadCallback(function() {
    $('#txtUserInput').keyup(function(){
        delayTimer(1000)(function(){
            text = $('#txtUserInput').val();
            if(text == '') text = 'example';
            loadImage(text, color, font);
        });
    });
    $('.color').click(function(event){
        event.preventDefault();
        color=$(this).attr('color');
        loadImage(text, color, font);
    });
    $('.font').click(function(event){
        event.preventDefault();
        font=$(this).attr('font');
        loadImage(text, color, font);
    });
});