$().ready(function(){
    proxy = $('<div class="q proxy"></div>');
    proxy.hide();
    q = $('textarea[name=q]');
    q.after(proxy);
    $('label').click(function(e) {
        $(this).parent().addClass('selected');
        $(this).hide()
        $(q).focus();
    });
    q.click(function(e) {
        label = $('label[for='+$(this).attr('name')+']');
        $(this).parent().addClass('selected');
        label.hide();
    });
    q.keyup(function() {
        proxy.text($(this).val());
        height = proxy.height();
        if (height % 40 != 0) height += 20;
        height -= 2;
        $(this).height(height+'px');
    });
    q.blur(function(){
        label = $('label[for='+$(this).attr('name')+']');
        if ($(this).val() == '') {
            $(label).parent().removeClass('selected');
            $(label).show();
        }
    });
    if (q.val()) {
        $('label').hide();
    }
});
