/**
 * This class is used to create a label inside an input element which disappears when the 
 * user enters something in the input.
 */
var InnerLabel = new Class({

    initialize: function (input, label)
    {
        
        this.inputId = input.id;
        this.label   = label;
        this.labeled = false;
        this.type    = input.type;
        
        // Start the label as visible.
        this._blur();
        
        // Needed to capture this for the closure.
        var self = this;
        
        $(input).addEvent( 'blur',  function () { self._blur(); } );
        $(input).addEvent( 'focus', function () { self._focus(); } );
        
        // We also need to add an even to clear the input of our label when the parent form is submit.
        var form = $(input).getParent("form");
        form.addEvent( 'submit', function () { self._submit(); } );

    },
    
    _blur: function ()
    {
        var input = $(this.inputId);

        if (input.value == '')
        {
            // Add the label.
            input.addClass("labeled");
            input.value = this.label;
            this.labeled = true;
        }
        
    },
    
    _focus: function ()
    {
        if (this.labeled)
        {
            // Clear out the label.
            var input = $(this.inputId);
            input.value = '';
            input.removeClass("labeled");
            this.labeled = false;
        }
    },
    
    _submit : function ()
    {
        // Remove the label so we don't submit it.
        if (this.labeled)
        {
            var input = $(this.inputId);
            input.value = '';
        }
    }

});