// Author: Qasim Alyas
// Date: 13 Jan 2009
// Plugin name: Text placeholder
// Version: 0.1
// Dependencies: jQuery 1.2.6 + available from http://jquery.com


// ----------------------------------
// Instructions
// ----------------------------------


// 1. Add an attribute [title/rel or whatever] to the required field i.e. 
//		<input type="text" id="textfield" title="This text will show as default" />
// 2. Call the plugin like so: $('form').placeholder();
// 3. Done!


jQuery.fn.placeholder = function(settings){
	
	settings = jQuery.extend({
		addclass: 'text',
		attr: 'title'
	}, settings);
	
	return this.each(function(){

		var fields = $(this).find(":text, textarea")
			.addClass(settings.addclass);
		
		$(fields).each(function(){
		var formplaceHolder = $(this).attr(settings.attr);
			$(this).val(formplaceHolder)
				.focus(function(){
					if(this.value == formplaceHolder) {
						$(this).val("");
					};
				})
				.blur(function(){
					if (this.value == "") {
						$(this).val(formplaceHolder);
					};
				});
		});

	});
};