(function(){
    $('.ask-a-question footer a').click(function(){
        var form = $(this).closest('form')
        ,   textarea = form.find('textarea')
        ,   status = form.find('[name=status]')
        ,   prefix = form.find('.tweet-box p').text()
        ;

        status.val(prefix + ' ' + textarea.val());
        form.submit();
        return false;
    });

    function update_count() {
        var text = $(this).val()
        ,   text_length = text.length
        ,   form = $(this).closest('form')
        ,   count = form.find('.tweet-character-count-value')
        ,   prefix = form.find('.tweet-box p').text()
        ;

        count.text(140 - text_length - prefix.length - 1);
    }
    $('.ask-a-question textarea').keyup(update_count).each(update_count);
})();

