/*
* BOTFOCUS
* 	- When loaded the field value is set to the title (will just be blank if the title is not set)
*	- When the field gains focus, the value is cleared only if the value is equal to the title
*	- When the field loses focus, the value is reset to the title if the value is nothing
*	NOTES:
*	- Works well with the jquery validation class
* REQUIRES
* - mootools 1.2
* 
* Jay Richardson
* Werkbot Studios - www.werkbot.com
*/
var botfocus = new Class({
		
	initialize: function(options) {
		this.elements = $(document.body).getElements(".botfocus input[type=text]");
		this.elements.each(function(e){
			//SET THE VALUE OF THE INPUT FIELD TO THE TITLE
				if(e.get("title")){
					e.set("value", e.get("title"));
				}
			//DEFINE THE FOCUS FUNCTION - IF THE VALUE IS EQUAL TO THE TITLE OF THE FIELD WE SET THE VALUE TO EMPTY
				e.addEvent("focus", function(ee){
					if(this.get("value")==this.get("title")){
						this.set("value", "");
					}				
				});
			//DEFINE THE BLUR FUNCTION - IF THE VALUE IS EMPTY WE SET THE VALUE OF THE FIELD TO THE TITLE OF THE FIELD
				e.addEvent("blur", function(ee){
					if(this.get("value")==""){
						this.set("value", this.get("title"));
					}				
				});
		});
		//WHEN A FORM IS SUBMITTED WE CLEAR THE VALUE OF THE FIELD IF THE VALUE IS EQUAL TO THE TITLE OF THE FIELD
			$$(".botfocus").addEvent("submit", function(ee){
				var es = this.getElements("input[type=text]");
				es.each(function(e){
					if(e.get("value")==e.get("title")){
						e.set("value", "");
					}
				});
			});
	}
});
