// JavaScript Document
$(document).ready(function() {

	//if($.browser.msie && $.browser.version == '6.0') return false;

	var textboxes = $('form input.defaultText');
	
	textboxes.each(function(index) {
		
		var __textbox = $(this);
		var label = $(this).prev();
		
		// Used for autocomplete
		if (index == 0){  
			$(this).bind('blur', function() {						  
				textboxes.each(function(i) {
					if($(this).val()) {
						$(this).prev().addClass('hastext');
					}
				});
			});
		}
		
		
		/**
		 *
		 * @hack - IE7 wasn't bubbling from labels. So now labels are clickable, innit.
		 *
		 */
		label.bind('click', function(e) {
			
			if($(this).hasClass('focus')) {
				__textbox.trigger('blur');
			}
			else {
				__textbox.trigger('focus');	
			}
			
			return false;
			
		});

		// Fade the label back when a field gains focus		
		$(this).bind("focus", function() {
			 if(!$(this).val()) {
				label.addClass('focus'); 
			 }
		});
	
		// Check if a field is empty when the user switches out		
		$(this).bind("blur", function() {
			if(!$(this).val()) {
				label.removeClass('focus').removeClass('hastext');	
			}
		});
		
		// Fade the label back if a field has text		
		if($(this).val()) {
			label.addClass('hastext');	
		}
			
	 	// Fade the label back when the user starts to type		
		$(this).bind("keypress", function() {
			label.addClass('hastext');								   
		});
	  	
	});
						   
});
