/*
	jQuery placeholder plugin
	--
	Adds placeholder text to input fields of type text and uses Modernizr to check for 
	placeholder availability if modernizr is included
	--
	Author  : Jesper Hauge
	Web     : blog.iqit.dk
	Version : 1.0
*/

(function ($) {
	$.fn.placeHolder = function (options) {
		// Handle settings
		var settings = {
			'textAttr': 'title',
			'offStyle': 'preFilled'
		};
		if (options) {
			$.extend(settings, options);
		}
		// Check for HTML5 placeholder with modernizr
		if (window.Modernizr != null) {
			if (Modernizr.input.placeholder) {
				return this.each(function () {
					var el = $(this);
					el.attr("placeholder", el.attr(settings.textAttr));
				});
			}
		}
		// Handle placeholder with code if not available
		return this.each(function () {
			var el = $(this);
			el.focus(function () {
				el.removeClass(settings.offStyle);
				if (el.val() == el.attr(settings.textAttr)) el.val("");
			})
			.focusout(function () {
				if (el.val() == "") {
					el.addClass(settings.offStyle)
						.val(el.attr(settings.textAttr));
				}
			});
			if (el.val() == "") {
				el.addClass(settings.offStyle)
					.val(el.attr(settings.textAttr));
			}
		});
	};
})(jQuery);

