var Prompter = Class.create({
  initialize: function(inputElement, labelElement) {
    this.inputElement = inputElement;

    this.labelElement = labelElement ? labelElement : inputElement.up('.labelAndInput').down('label');
    this.isInputElementBlank() ? this.showLabel() : this.hideLabel();
    
    this.labelElement.observe('click', this.onLabelClick.bind(this));
    this.inputElement.observe('focus', this.onFocus.bind(this));
    this.inputElement.observe('blur', this.onBlur.bind(this));
  },
  
  onLabelClick: function(event) {
    this.inputElement.focus();
  },
  
  onFocus: function(event) { 
    this.hideLabel();
  },
  
  onBlur: function(event) {
    this.reset();
  },
  
  reset: function() {
    this.isInputElementBlank() ? this.showLabel() : this.hideLabel();
  },
  
  isInputElementBlank: function() {
    return this.inputElement.value.strip() == '';
  },
  
  showLabel: function() {
    this.labelElement.show();
  },
  
  hideLabel: function() {
    this.labelElement.hide();
  }
});

Prompter.create = function(inputElement, labelElement) {
  return new Prompter(inputElement, labelElement);
};
