var $logo;
var $logoRefresh = 500; // ms
var $logoChars = 600;
var $logoAnimate = false;

$(document).ready(function() {
    
    FlattrLoader.setup();
    
    $logo = $('#logo');
    $logo.css('background', '#FFF');
    fillLogo();
    $('a', $logo.parent()).hover(function () { 
        $logoAnimate = true;
        setTimeout("fillLogo();", $logoRefresh);
    }, function() {
       $logoAnimate = false; 
    });
    
    $('textarea').focus(function() {
        if ($(this).val() == $(this).html()) {
            $(this).val('');
            $(this).css('color', '#333');
        }
    });
    
    $('#generate-form').submit(function() {
        $('.submit', this).attr('disabled', 'disabled');
        $('.loading', this).show();
    })
    
});


function fillLogo() {
    var $randstr = '';
    for ($randchars=$logoChars; $randchars>0; $randchars--) {
        $randstr += genRand();
    }
    $logo.html($randstr);
    if ($logoAnimate) setTimeout("fillLogo();", $logoRefresh);
}

function genRand() {
    return Math.floor(Math.random()*10)
}
