if ( typeof Kawara == 'undefined' ) Kawara = {};
Kawara.InputShadow = new Class(
    {
        initialize: function( element, text, options ){
            if ( !options ) options = {};
            this.element      = element;
            this.text         = text;
            this.shadowColor  = options.shadowColor  || '#aaaaaa';
            this.defaultColor = options.defaultColor || this.element.style.color || '';
            this.active       = false;
            this.element.addEvent( 'focus', this.focus.bindWithEvent(this) );
            this.element.addEvent( 'blur', this.blur.bindWithEvent(this) );
            this.element.addEvent( 'keyup', this.keyup.bindWithEvent(this) );
            if ( options.form )
                options.form.addEvent( 'submit', this.clear.bindWithEvent(this) );
            else
                this.element.addEvent( 'submit', this.clear.bindWithEvent(this) );

            this.blur();
        },
        focus: function() {
            if ( !this.active ) {
                this.element.value = '';
                this.element.style.color = this.defaultColor;
            }
        },
        blur: function() {
            if ( !this.active ) {
                this.element.value = this.text;
                this.element.style.color = this.shadowColor;
            }
        },
        keyup: function() {
            if ( this.element.value == '' )
                this.active = false;
            else
                this.active = true;
        },
        clear: function() {
            if ( !this.active )
                this.element.value = '';
        }
    }
);
