var LabelInField = new Class(
{
  Implements: Options,

  options: {
    'form': null, // CSS Selector or Element
    'passive_color':'#666666',
    'active_color':'#000000'
  },

  inputRegister: new Array(),

  initialize: function ( options )
  {
    document.addEvent( 'domready', this.boot.bind(this) );
    this.setOptions( options );
  },

  boot: function ()
  {
    if ( $type( this.options.form ) == 'string' ) {
      this.options.form = document.getElement( this.options.form );
    }
    if ( !this.options.form ) return;
    this.options.form.getElements('input').each( function ( input ) {
      var label, description;
      var id = input.get( 'id' ) ? input.get( 'id' ) : input.get( 'name' );
      if ( id ) label = document.getElement( 'label[for='+id+']' );
      if ( label ) {
        label.setStyle( 'display', 'none' );
        description = label.get('text');
      } else {
        description = input.get( 'alt' );
        if ( !description ) description = input.get( 'title' );
        else if ( !description ) description = input.get( 'name' );
      }
      input.store( 'description', description );
      input.set( 'value', description );
      input.setStyle( 'color', this.options.passive_color );

      // Attach the event handlers
      input.addEvent( 'focus', this.onFocus.bind( this, input ) );
      input.addEvent( 'blur', this.onBlur.bind( this, input ) );

      this.inputRegister.push( input );
    }.bind(this) );

    this.options.form.addEvent( 'submit', this.onSubmit.bind(this) );
  },

  onSubmit: function ()
  {
    this.inputRegister.each( function ( input ) {
      if ( input.get('value') == input.retrieve( 'description' ) ) {
        input.set('value', '');
      }
    }.bind(this) );
  },

  onFocus: function ( input )
  {
    if ( input.get('value') == input.retrieve( 'description' ) ) {
      input.set('value', '');
      input.setStyle( 'color', this.options.active_color );
    }
  },

  onBlur: function ( input )
  {
    if ( input.get('value') == '' ) {
      input.set('value', input.retrieve( 'description' ) );
      input.setStyle( 'color', this.options.passive_color );
    }
  }
} );

new LabelInField( {'form' : 'div.subscribeAction form' } );