(function(){
	/*
	 * jQuery PlaceHolder
	 * @author Lee Boonstra, <lee.boonstra@efocus.nl>
	 * @since 21 jan 2011
	 * @version 1.0
	 * @copyright eFocus
	 *
	 * @uses jQuery 1.2.6, <http://www.jquery.com> or higher
	 */
	$.fn.Placeholders = function(){
		var strSavedString = "";
		
		/*
		 * Does the browser support placeholder attribute?
		 * @return boolean
		 */
		function isBrowserSupport(){
			var i = document.createElement("input");
			return "placeholder" in i;
		}		
		return this.each(function(){	
			var e = $(this);
			var strPlaceHolderText = e.attr("placeholder");
			
			if(e.val().length == 0){
				e.val(strPlaceHolderText);	
			}
			
			/*
			 * On field focus remove placeholder if there is no written text in it.
			 * @return void
			 */
			e.focus(function(){
				strSavedString = e.val();
				if (strSavedString === strPlaceHolderText) {
					e.val("");	
				}
			});
			
			/*
			 * Save the written text in a variable
			 * @return void
			 */
			e.change(function(){
				strSavedString = e.val();
			});
			
			/*
			 * While leaving the focus of the field, put the placeholder back
			 * or the written text.
			 * @return void
			 */
			e.blur(function(){
				if(isBrowserSupport()===false){
					if(strSavedString !== strPlaceHolderText && strSavedString !== ""){
						e.val(strSavedString);		
					} else {
						e.val(strPlaceHolderText);
					}	
				}
			});

		});
			
	};
})(jQuery);
