
// When the DOM is ready...
$(function(){
	
	// Hide stuff with the JavaScript. If JS is disabled, the form will still be useable.
	$("#friends_name_wrap").hide();
		
	// Reset form elements back to default values
	$("#submit_button").attr("disabled",true);
	$("#step_2 input[type=radio]").each(function(){
		this.checked = false;
	});
	$("#privacy").each(function(){
		this.checked = false;
	});
	
	// Fade out steps 2 and 3 until ready
	$("#step_2").css({ opacity: 0.7 });
	$("#step_3").css({ opacity: 0.7 });
	
	
	$.stepOneComplete_one = "not complete";
	$.stepOneComplete_two = "not complete"; 
	$.stepTwoComplete_one = "not complete";
		
	
	function stepOneTest() {
		if (($.stepOneComplete_one == "complete") && ($.stepOneComplete_two == "complete")) {
			$("#step_1")
			.animate({
				paddingBottom: "120px"
			})
			.css({
				"background-image": "url(images/check.gif)",
				"background-position": "bottom center",
				"background-repeat": "no-repeat"
			});
			$("#step_2").css({
				opacity: 1.0
			});
			$("#step_2 legend").css({
				opacity: 1.0 // For dumb Internet Explorer
			});
		}
	};
	
	
	$("#name").blur(function(){
		if ($(this).val() != '' ) {
		$.stepOneComplete_one = "complete"; 
		}
		stepOneTest();
	});
	
		$("#email").blur(function(){
		if ($(this).val() != '' ) {
		$.stepOneComplete_two = "complete"; 
		}
		stepOneTest();
	});

	
	
	
	
	
	function stepTwoTest() {
		if (($.stepTwoComplete_one == "complete")) {
			$("#step_2")
			.animate({
				paddingBottom: "120px"
			})
			.css({
				"background-image": "url(images/check.gif)",
				"background-position": "bottom center",
				"background-repeat": "no-repeat"
			});
			$("#step_3").css({
				opacity: 1.0
			});
			$("#step_3 legend").css({
				opacity: 1.0 // For dumb Internet Explorer
			});
		}
	};
	
	$("#step_2 input[name=friends_toggle_group]").click(function(){
		$.stepTwoComplete_one = "complete"; 
		if ($("#friends_toggle_on:checked").val() == 'on') {
			$("#friends_name_wrap").slideDown();
		} else {
			$("#friends_name_wrap").slideUp();
		};
		stepTwoTest();
	});
	
	$("#privacy").click(function(){
		if (this.checked && $.stepOneComplete_one == 'complete' && $.stepOneComplete_two == 'complete'
		  	 && $.stepTwoComplete_one == 'complete') {
				$("#submit_button").attr("disabled",false);
			} else {
				$("#submit_button").attr("disabled",true);
		}
	});
	
});