(function(){
  var Placeholder = {
    settings: {
      'placeholder' : "#999"
    },

    initialize: function(){
      //this.inputs = $$(":text, :password");
      this.inputs = $$("input[placeholder]");
      this.setPlaceholders();
      this.bindEvents();
    },

    setPlaceholders: function(){
      this.inputs.each(function(input){
        var value = input.getValue();
        if(value !== "" && value != input.readAttribute("placeholder")){ return; }

        this.setPlaceholder(input);

      },this);
    },

    bindEvents: function(){
      this.inputs.each(function(input){
        if(!input.readAttribute("placeholder")){ return; }

        input.on("focus", this.inputFocus.bind(this));
        input.on("blur", this.inputBlur.bind(this));
      }, this);
    },

    inputFocus: function(event){
      var input = event.element();

      if(input.getValue() == input.readAttribute("placeholder")){
        input.value = "";
        this.removePlaceholder(input);
      }
    },

    inputBlur: function(event){
      var input = event.element(),
          value = input.getValue();

      if(value === ""){
        this.setPlaceholder(input);
      } else {
        this.removePlaceholder(input);
      }
    },

    setPlaceholder: function(input){
      input.setStyle({
        color: this.settings.placeholder
      });

      if(input.value === ""){
        input.value = input.readAttribute("placeholder");
      }
    },

    removePlaceholder: function(input){
      input.setStyle({
        color: ""
      });
    }
  };

//  document.observe("dom:loaded", function(){Placeholder.initialize();});
})();

