$(document).ready(function() {

	// Hide Response Containers
	$("#right-here").hide();		
	$("#health").hide();	
	$("#future").hide();	
	$("#quiz-thankyou").hide();	

	// Result Hover
	$("#right-here").hover(function() 
		{
		$(this).css({'backgroundColor' : '#EFFFEF'});																	
		}, function() 
		{
		$(this).css({'backgroundColor' : '#FFFFFF'});	
		});
	
	$("#health").hover(function() 
		{
		$(this).css({'backgroundColor' : '#EFFFEF'});																	
		}, function() 
		{
		$(this).css({'backgroundColor' : '#FFFFFF'});	
		});
	$("#future").hover(function() 
		{
		$(this).css({'backgroundColor' : '#EFFFEF'});																	
		}, function() 
		{
		$(this).css({'backgroundColor' : '#FFFFFF'});	
		});
	


	// Submit Form Data
	$("#quiz-submit").click(function() {	
	
		// Get all the questions
		var quiz_submit = 'submit';						
		var question1 = $('input[name=question1]:checked').val(); 
		var question2 = $('input[name=question2]:checked').val();
		var question3 = $('input[name=question3]:checked').val();
		var question4 = $('input[name=question4]:checked').val();
		var question5 = $('input[name=question5]:checked').val();
		var question6 = $('input[name=question6]:checked').val();
		var question7 = $('input[name=question7]:checked').val();
		var question8 = $('input[name=question8]:checked').val();
		var question9 = $('input[name=question9]:checked').val();
		var question10 = $('input[name=question10]:checked').val();
		var question11 = $('input[name=question11]:checked').val();
		var question12 = $('input[name=question12]:checked').val();
		var question13 = $('input[name=question13]:checked').val();
		var question14 = $('input[name=question14]:checked').val();
		var question15 = $('input[name=question15]:checked').val();
		var question16 = $('input[name=question16]:checked').val();
		var question17 = $('input[name=question17]:checked').val();
		var question18 = $('input[name=question18]:checked').val();
		var question19 = $('input[name=question19]:checked').val();
		var question20 = $('input[name=question20]:checked').val();
		var question21 = $('input[name=question21]:checked').val();
		var question22 = $('input[name=question22]:checked').val();
		var question23 = $('input[name=question23]:checked').val();
		var question24 = $('input[name=question24]:checked').val();	
		var question25 = $('input[name=question25]:checked').val();	
		
		// Function Quiz
		function processQuiz(data) {
			var status = data.status;
			var status_message = data.status_message;			
			
			// If form is not complete
			if(status == 0) {
			alert(status_message);
			}
			
			if(status == 1) {
			var group1_score = data.group1_score;
			var group2_score = data.group2_score;
			var group3_score = data.group3_score;
			var percent_score = data.percent_score;
										
				
			$("#column2 p").hide();
			$("#quiz-box").slideUp(1500);
			$.scrollTo('#content-wrapper', 1000);
			
			// Find the score and load the proper content
			
			// Group 1
			if(group1_score <= 12) {
				var group1_content = "#right-here div.poor";
				}
			else if(group1_score >= 17) {
				var group1_content = "#right-here div.good";
				}
			else {
				var group1_content = "#right-here div.fair";
				}
				
			// Group2
			if(group2_score <= 8) {
				var group2_content = "#health div.poor";
				}
			else if(group2_score >= 10) {
				var group2_content = "#health div.good";
				}
			else {
				var group2_content = "#health div.fair";
				}
				
			// Group3
			if(group3_score <= 14) {
				var group3_content = "#future div.poor";
				}
			else if(group3_score >= 18) {
				var group3_content = "#future div.good";
				}
			else {
				var group3_content = "#future div.fair";
				}	
			
			$("#quiz-explanation").show();
			$("#right-here").show();		
			$("#health").show();	
			$("#future").show();	
			$("#quiz-thankyou").show();	
			$("#quiz-explanation").load("quiz-answers.htm #quiz-explanation")
			$("#right-here").load("quiz-answers.htm " +group1_content);
			$("#health").load("quiz-answers.htm " +group2_content);
			$("#future").load("quiz-answers.htm " +group3_content);
			$("#quiz-thankyou").load("quiz-answers.htm #quiz-thankyou")
			}
		}
		
		// Send the Post
		$.post("financial-quiz.php",
		{quiz_submit: quiz_submit, question1: question1, question2: question2, question3: question3, question4: question4, question5: question5, question6: question6,
		question7: question7, question8: question8, question9: question9, question10: question10, question11: question11, question12: question12, 
		question13: question13, question14: question14, question15: question15, question16: question16, question17: question17, question18: question18,
		question19: question19, question20: question20, question21: question21, question22: question22, question23: question23, question24: question24, question25: question25},
		function(data){
			processQuiz(data);						
		}, 'json');

		
		// Return False
		return false;
			
		});				
										
});