jQuery(function($){

	/* sjs pseudoPlaceholder */
	/* todo: tidy up and make a plugin */
	var inputs = $('input[title]');
	
	inputs.each((function(){	
		//are HTML5 placeholders supported
		var placeholders = ('placeholder' in document.createElement('input'));
		
		//ensure pseudo placeholders aren't submitted
		if(!placeholders){
			$('form').bind('submit',function(){
				inputs.each(function(){
					if(this.pseudoPlaceholder){
						this.value = '';
					}
				});
			});
		}
		
		return function(){		
			//get our placeholder value from the title attribute
			var placeholder = this.title;
			
			//set title to nothing to avoid duplicate prompts
			this.title = '';
			
			if(placeholders){
				//set our placeholder
				this.placeholder = placeholder;
			} else {
				//no placeholder support, lets do it ourselves!
				//the form could be pre-populated e.g. pulling details back from a DB
				//don't wipe this value
				if(!this.value){
					this.value = placeholder;
					
					//set pseudoPlaceholder value flag
					this.pseudoPlaceholder = true;
				}
				
				$(this)
					.bind('focus',function(){
						if(this.value == placeholder){
							this.value = '';
						}
					})
					.bind('blur',function(){
						if(this.value == ''){
							this.value = placeholder;
							this.pseudoPlaceholder = true;
						} else {
							this.pseudoPlaceholder = false;
						}
					})
				;
			}
		}
	})());
});
