/**
 * Creates a label that hovers over an input box and auto-hides
 * on focus/click, and auto-shows when search is blank.  This helps
 * prevent accidental submission of the overtext
 */

jQuery.fn.overtext = function(overText, classLabel, cssInput) {
	return this.each(function(){
		var input  = jQuery(this),
            offset = input.offset(),
            label  = $('<label>');

        label
            .addClass(classLabel)
            .text(overText).css(input.offset()).css('color', input.css('color')).css({
                position: 'absolute',
                marginLeft: '5px',
                marginTop:  '5px',
                fontWeight: 'normal',
                cursor: 'text',
                display: 'none'
            })
            .bind('focus, click', function(){
                label.hide();
                input.focus();
            })
            .appendTo('body:first');

        if ($.isPlainObject(cssInput) && !$.isEmptyObject(cssInput)) {
            label.css(cssInput);
        }

        input
            .blur(function(){
                if ('' == jQuery.trim(input.val()))
                    label.show();
            })
            .focus(function(){
                label.hide();
            });

        // wait for 1/10th of a second before showing so all can be properly positioned
        setTimeout(function(){
            label.css(input.offset());
            if ('' == jQuery.trim(input.val()))
                label.show();
        }, 100);

        $(window).resize(function(){
            label.css(input.offset());
        });
    });
}
