// http://web.enavu.com/design/advanced-jquery-placeholder-plugin-cross-browser-support/

Array.implement({
	
	placeholder: function(){
		var css_class = 'placeholder';
		
		this.each(function(el){
			var phvalue = el.getProperty('placeholder');
			if(phvalue){
				if(phvalue == el.value){
					el.addClass(css_class);
				}
				if(el.value == ''){
					el.addClass(css_class);
					el.value = phvalue;
				}
				el.addEvent('focus', function(el){
					var ph = this.getProperty('placeholder');
					if(ph == this.value){
						this.value = '';
						this.removeClass(css_class);
					}
				});
				el.addEvent('blur', function(el){
					if(this.value == ''){
						var ph = this.getProperty('placeholder');
						this.value = ph;
						this.addClass(css_class);
					}
				});
			}
		});
	}
});

function hasPlaceholderSupport() {
	var input = document.createElement('input');
	return ('placeholder' in input);
}

window.addEvent('load', function(){
	if(!hasPlaceholderSupport()){
		$$("input[type=text]").placeholder();
		$$("textarea").placeholder();
		$$("form").addEvent( 'submit', function(e){
			this.getElements("*[placeholder]").each(function(el){
				if(el.value == el.getProperty('placeholder')){
					el.value = '';
				}
			});
		});

	}
});
