/*
/*  placeholder.js
*/

var Placeholder = Class.create({
  initialize: function (el) {
    this.el = el;
    this.el.observe("focus", this.hide.bind(this));
    this.el.observe("blur",  this.show.bind(this));
  },
  
  getValue: function () {
    return this.el.value;
  },
  
  getPlaceholderValue: function () {
    return this.el.getAttribute("value");
  },
  
  hide: function () {
    if (this.getValue() == this.getPlaceholderValue()) {
      this.el.value = "";
      this.el.removeClassName("temp");
    }
  },
  
  show: function () {
    if (this.getValue().empty()) {
      this.el.value = this.getPlaceholderValue();
      this.el.addClassName("temp");
    }
  }
});

document.observe("dom:loaded", function () {
  $$("input.temp").each(function (el) {
    new Placeholder(el);
  });
});
