﻿(function($) {
	$.fn.overlabel = function() {
		this.each(function() {
			
			// make clicking label focus element in safari
			if($.browser.safari){
				$(this).bind('click',function(){
					$('input.field',this).get(0).focus();
				});
			}
			if($(this).find('input.field').get(0).value == '' || $(this).find('input.field').get(0).value == null){
				$(this).addClass('show');
			}
			
			$(this).find('input.field').focus(function(){
				$(this).parents('label').removeClass('show');
			})
			.blur(function(){
				if(!$(this).val()){
					$(this).parents('label').addClass('show');
				}
			}).end();
		});
		return this;
	};
})(jQuery);


// Adds class of 'focus' when element is focussed 
// Adds class of 'changed' if non-empty
(function($) {
	$.fn.fieldfocus = function() {
		this.each(function() {
			// works on text fields and select
			var field = $('input.field,select',this);
			field.focus(function(){
				$(this).addClass('focus');
			})
			.blur(function(){
				$(this).removeClass('focus');
				if($(this).val())
					$(this).addClass('changed');
				else
					$(this).removeClass('changed');
			});
		});
		return this;
	};
})(jQuery);
