/** @file
 * Implement over-labels for input elements.
 *
 * @copyright All rights reserved.
 * @author Thomas Sutton <thomas@bouncingorange.com>
 */
(function($){

    /**
     * jQuery function applicable to input[@type='text'] and textarea elements.
     */
    $.fn.overlabel = function(settings){
        // Get the settings
        var settings = $.extend({}, $.fn.overlabel.settings, settings);

        // Process the matching elements
        return $(this).each(function(index){
            var $label = $(this);
            var $container = $($label.parent());

            $container.css('position', 'relative');
            $container.addClass('overlabel-wrapper');

            var id = $label.get(0).htmlFor || $label.attr('for');
            $('#'+ id )
              .focus(function(){$label.css('text-indent','-9999px');})
              .blur(function(){this.value || $label.css('text-indent','0px');})
              .trigger('focus').trigger('blur').length 
            && $label.addClass(settings.activeclass);
            $('body').trigger('focus');
        });
    };

    /**
     * Define the default settings. These may be overridden globally by
     * modifying the members of this hash, or per-call by passing a hash of
     * overriding values to the call.
     */
    $.fn.overlabel.settings = {
        'activeclass' : 'overlabel-apply'
    };
})(jQuery);
