// JavaScript used to swap form label classes when using compact form with overlying labels

(function($)
{
	$.fn.hideLabel = function(testValue)
	{
		if(testValue == null)
		{
			testValue = false;	
		}
		
		return this.each(function(targetCounter)
		{
			var _$this = $(this);
			
			if(testValue)
			{
				var myValue = _$this.attr('value');
			
				if(myValue !== '')
				{
					//_$this.siblings('label.overlabel-apply').addClass('overlabel-hidden');
					//added due to contact7 plugin - which auto wraps input in a span element
					_$this.parent().siblings('label.overlabel-apply').addClass('overlabel-hidden');
				}
				else
				{
					//_$this.siblings('label.overlabel-apply').removeClass('overlabel-hidden');
					//added due to contact7 plugin - which auto wraps input in a span element
					_$this.parent().siblings('label.overlabel-apply').removeClass('overlabel-hidden');
				}
			}
			else
			{
				//_$this.siblings('label.overlabel-apply').addClass('overlabel-hidden');
				//added due to contact7 plugin - which auto wraps input in a span element
				_$this.parent().siblings('label.overlabel-apply').addClass('overlabel-hidden');
			}
		});
	};
	
	$.fn.overLabel = function()
	{
		return this.each(function(targetCounter)
		{
			var _$this = $(this);
			
			//add the class overlabel-apply to set css
			_$this.addClass('overlabel-apply');
			
			//var _$myInput = _$this.siblings('input');
			var _$myInput = _$this.siblings().find('input');
			
			//use hideLabel() to hide any labels of inputs with initial values
			_$myInput.hideLabel(true);
			
			//apply onFocus fcn
			_$myInput.focus(function()
			{
				_$myInput.hideLabel();
			});
			
			//apply onBlur fcn - need to test for value here
			_$myInput.blur(function()
			{
				_$myInput.hideLabel(true);
			});
			
			//apply click fcn
			_$this.click(function()
			{
				_$myInput.hideLabel();
			});
		});
	};
})(jQuery);

jQuery(document).ready(function($)
{
	$('label.overlabel').overLabel();
});
