/*------------------------------------------------------------------
[ Evident jQuery Library ]

Plug-in name:	inputLabel
Purpose:		moves a label value inside an input element
Usage:			optionally provide the classname of the input box
Version:		1.4
Last change:	21/08/08 (mb) [if present, use value of inputfield, otherwise use value of label]
Assigned to:	Marc Bruisten (mb)

--------------------------------------------------------------------*/

(function($){
	$.fn.inputLabel = function() {
		var selection = this.filter('[type=text]:input');
		return selection.each(function(){
				var label = $(this).prev()[0];	
				if (($(label)[0].tagName == "LABEL") && (this.id == $(label).attr('for'))) 
				{
					if ($(this).attr('value'))
						var targetvalue = $(this).attr('value');
					else
						var targetvalue = $(label).text();
					$(label).css('display','none');
					$(this).val(targetvalue);
					$(this).bind("focus", {lblValue: targetvalue}, inputfocus);
					$(this).bind("blur", {lblValue: targetvalue}, inputblur);
				}
		});
		function inputfocus(event) {
			if (this.value == event.data.lblValue) {
				this.value='';
				$(this).toggleClass("typing");
			}
		};
		function inputblur(event) {
			if (this.value=='') {
				this.value=event.data.lblValue;
				$(this).toggleClass("typing");
			}
		};
	};
})(jQuery);
