/**
 * jQuery under_label plugin
 * creates labels under the form text inputs
 * @author Michał Kraszewski
 * @copyright (c) 2009 Michał Kraszewski
 * @version 0.1
 * @license sys/license.txt
 */

jQuery.fn.under_label = function() {
    return jQuery(':text', this).add('textarea', this).each(function(index, elem) {
        var e = $(elem);
        
        e.focus(function() {
            if ($(this).val() == "               ")
                $(this).val("");
            $(this).siblings(".input_under_label").html('&nbsp;');
        });
        
        e.blur(function() {
            var id = $(this).attr('id');
            if ($(this).val() == "")
                $(this).val("               ");
            setTimeout('if ($("#' + id + '").val() == "               ") '+
                '$("#' + id + '").siblings(".input_under_label").html($("#' + id + '").attr("title"));', 200);
        });
        
        var l = $(document.createElement('div'));

        l.attr('class','input_under_label');
        l.css('height', elem.offsetHeight + 2);
        
        if (e.val() == "") 
            e.val("               ");
        if (e.val() == "               ")
            l.html(e.attr('title'));
                    
        e.before(l);
    });
};

