/*
* Clear and repopulate form fields on focus and blur
* TODO: need to look at how we handle password fields with instruction text inside.
*/
(function($){
$.fn.tiClearInputs = function(options) {
    
    var defaults = {
	};
	
	options = $.extend(defaults, options);
	
	return this.each(function() {
		$(':input', this).each(function() {
			var overlayLabel;
			
			if(this.type === "password") {				
				
				overlayLabel = $(this).siblings('label', '.passwordOverlay');
				
				$(overlayLabel).click(function(event){
						var input = $(this).attr('for');
						$(this).css({'left' : '-9999em'});						 
						$('#' + input).focus();				
					});
				$(this).bind({
					'blur': function() {
								if(this.value === '') {
									$(overlayLabel).css({'left' : ''});
								}			
							},
					'focus': function() {
								$(overlayLabel).css({'left' : '-9999em'});
							}
					});
				
								
			} else if(this.type === "text" || this.type === "textarea") {
				
				$(this).focus(function(){
					if(this.value === this.defaultValue) {
						this.value = '';
					}
				});
				
				$(this).blur(function() {
					if(this.value === '') {
						this.value = this.defaultValue;
					}
				});
			}
		});
    });
};
})(jQuery);
