jQuery(document).ready(function($) {
    // $() will work as an alias for jQuery() inside of this function

/*
	This clears out the "hint" in the input fields and clears them out. Replaces with the original hint if no text is entered.
	Thanks to Jörn Zaefferer:
	http://bassistance.de/2007/01/23/unobtrusive-clear-searchfield-on-focus/
*/
	$.fn.clearField = function() {
		return this.addClass('hint-text').focus(function() {
			if( this.value == this.defaultValue ) {
				this.value = "";
	      $(this).removeClass('hint-text');
			}
		}).blur(function() {
			if( !this.value.length ) {
				this.value = this.defaultValue;
	      $(this).addClass('hint-text');
			}
		});
	};

/*
	Rollovers for the input type="image".
	Thanks to Atlanta Jones:
	http://www.atlantajones.com/2008/07/02/even-easier-jquery-rollovers/
*/
	$.fn.rollOver = function() {
		// Set the original src
		rollsrc = $(this).attr("src");
		if (rollsrc) {
			rollON = rollsrc.replace('off', 'on');
			newImg = new Image(); // create new image obj
			$(newImg).attr("src", rollON); // set new obj's src
		}
	
		this.mouseover(function() {
			imgsrc = $(this).attr("src");
			if (typeof(imgsrc) != 'undefined') {
			imgsrcON = imgsrc.replace('off', 'on');
			$(this).attr("src", imgsrcON);
			}
		});

		// Handle mouseout
		this.mouseout(function(){
			if (typeof(imgsrc) != 'undefined') {
			$(this).attr("src", imgsrc);
			}
		});
	};



/*
	Initialize
*/
	$(function() {
		$(".clear_field").clearField();
		$(".rollover").rollOver();
		
		$("#volunteer_submit").click(function(event) {
			event.preventDefault();
			
			$.ajax({
				type: "POST",
				url: "/send-form/",
				data: $("#volunteer_form").serialize(),
				success: function() {
					$('#volunteer_form_success').fadeIn();
				},
				error: function() {
					$('#volunteer_form_failure').fadeIn();
				}
			});
		});
	});

});