 $(document).ready(function(){
  	var quiz=1; //1;
	var  score=0;  //0;
      var arr = [["When your phone vibrates, you","Grab  it! It's a call from your stockbroker.","Have a look. Probably a friend texting from a bar.","Check Caller ID.  It's a creditor.","What phone? Your service was turned off weeks ago!"],
	  			 ["Your favorite sport is","Something healthy, like working out, hiking, or cycling.","Something that requires equipment, clothes, lessons, and trips to far away places so expensive you're still paying for last year's fun.","Juggling--the bills, that is.","Dangerous--and with any luck will kill you before that last check bounces."],
				 ["You usually eat","Organic, well-balanced, and tasty food.","At pricy restaurants where you frequently pick up the tab for your friends.","Fast food--no time, no money!","Whatever lunch you can steal from the people you work with."],
				 ["You sleep","Very well, thank you","About 5 hours a night--life's too short for sleep!","Whenever you can stop worrying.","At your desk, at red lights, in meetings--anywhere but in bed."],
				 ["You use credit cards","For points to upgrade to first class when you go to Brazil next winter for a well-earned vacation.","To live for today! Eventually your pay will catch up with your spending.","For groceries and gas until things look up","Your last card was closed by the bank because you're over limit, behind on your payment, and drowning in late fees."],
				 ["You drive","A comfortable car you own free and clear.","A fire-breathing monster that costs the earth to insure and is financed with a ten year note.","A car you can't afford to buy gas for.","A bicycle - the bank repossessed your car last week!"],
				 ["You live","In a safe neighborhood with good schools and nice people.","In an amazing showplace. With an amazing payment.","Somewhere you'd rather not be.","With whichever relative got the short straw this week"],
				 ["You vacation","Often, for memorable family affairs or meaningful romantic getaways.","In Monte Carlo with the hottie you met at the club last weekend. First class and room service all the way baby!","Exclusively at Disney World--but you live in Orlando.","Vacation? Maybe if you can pawn Grandma's broach...."],
				 ["Your debt consists of","A mortgage with a good rate and manageable payment and perhaps a small car loan.","A major house payment\, a couple of car loans\, financed \"toys,\" and lots of platinum cards\, department store cards, and student loans.","Credit cards, loans for furniture and electronics, gas cards, and a subprime mortgage.","Payday loans and consumer debt. And maybe the neighborhood loan shark."]
				];
	var result=["Congratulations! You are most likely living within your means and could safely weather a financial emergency. You enjoy life and have few worries. Those with money problems can eventually achieve this peace of mind with some lifestyle adjustments and budgeting techniques. Getting rid of expensive debt, building an emergency fund, learning to spend less, and making smart investments can wipe money stress right out of your life. You have the financial smarts and the discipline to keep on track with a budgeting worksheet",
				"You don't hold back when it comes to high living--and that's okay if you don't have to finance the good times, or if you have a generous trust fund. Living on the edge can be exciting, but one unexpected layoff or a major medical problem could cost you everything. You could go it alone with a budgeting worksheet if you have some financial smarts and the discipline to bite the spending bullet--otherwise some credit counseling and budgeting intervention might save you from yourself.",
				"Your money is stretched very thin and your credit is likely spotty. You probably pay higher rates than many people, so it's even tougher to make ends meet. Economic conditions add to your pain, and money may be your top worry. You'd really like some financial security but don't see how it will ever happen. Professional help is in order here. Credit counselors could negotiate lower rates and payments with your creditors, a debt management plan may get you on track, a debt consolidation loan could lower your payments to something manageable. Some or all of these measures could restore your financial health.",
				"You need serious help--debt management at least and perhaps even bankruptcy. A professional can help you avoid bankruptcy if possible, or otherwise determine if you pass the means test for Chapter 7 filing or if a Chapter 13 plan is more appropriate. But starting over won't be enough unless you acquire some new habits. Financial counseling can help you avoid repeating your mistakes and help you rebuild your life."];
	  
	var button=["Stay on Track","Get Credit Counseling","Consolidate Your Debt","Bankruptcy Options"];
	var completeFinal=1;
	var complete1=1;
	var complete2=1;
	var complete3=1;
	var complete4=1;
	var complete5=1;
	//document.write(arr[0][0]);

	  
        $('#op1,#op2,#op3,#op4,#radio1,#radio2,#radio3,#radio4').click(function () { 
		if(completeFinal==1){
			//alert($(this).attr("id")+score);
			completeFinal=0;
			complete1=0;
			complete2=0;
			complete3=0;
			complete4=0;
			complete5=0;
				if($(this).attr("id") != ''){
					switch ($(this).attr("id")){
					case 'op1':
					case 'radio1':
					score += 1; 
					break;
					
					case 'op2':
					case 'radio2':
					score += 2; 
					break;
					
					case 'op3':
					case 'radio3':
					score +=3; 
					break;
					
					case 'op4':
					case 'radio4':
					score += 4; 
					break;				
					}			
				}
				
				if(quiz > 8){
					$('#quizResult').css("display","block");
					$('#quiz').css("height","40px");
					$('#optionWrapper').css("height","0px");
					$('#formButton').css("display","block");
					$('#formIn').css("display","block");			
					$('div.quiz_container').css("background","url(/img/quiz/result_background.jpg) no-repeat");			
						if(score > 8 && score < 18){
						$('#quizResult').text(result[0]);
						$('#formIn').text(button[0]);
						$('#formHref').attr({href:'/budget-worksheet'});					
						}								
						if(score >17 && score < 27){
						$('#quizResult').text(result[1]);
						$('#formIn').text(button[1]);
						$('#formHref').attr({href:'/quote/?service=DEBTCON'});
						}								
						if(score > 26 && score < 36){
						$('#quizResult').text(result[2]);
						$('#formIn').text(button[2]);
						$('#formHref').attr({href:'/quote/?service=DEBTCON'});				
						}				
						if(score > 35){
						$('#quizResult').text(result[3]);
						$('#formIn').text(button[3]);
						$('#formHref').attr({href:'/quote/?service=DEBTCON'});				
						}			
				
				$('#quiz').text("Take the quiz again"); 
				$('#quiz').css("cursor","pointer");
				$('div.divbtn').css("display","none");			
				$('#radio1').css("display","none");
				$('#radio2').css("display","none");
				$('#radio3').css("display","none");
				$('#radio4').css("display","none");
				$('div.divRadiobtn').css("display","none");			
				}else{
					$('#quiz,#radio1,#radio2,#radio3,#radio4,#op1,#op2,#op3,#op4').css("cursor","wait");
					$('#quiz').text(arr[quiz][0]);
					$('#op1').text(arr[quiz][1]);
					$('#op2').text(arr[quiz][2]);
					$('#op3').text(arr[quiz][3]);
					$('#op4').text(arr[quiz][4]);
					
					$('#radio1').removeAttr("checked"); 
					$('#radio2').removeAttr("checked");
					$('#radio3').removeAttr("checked");
					$('#radio4').removeAttr("checked");
					  
					$('#quiz').jTypeWriter({onComplete:function(){complete1=1;checkFinal();}});
					$('#op1').jTypeWriter({onComplete:function(){complete2=1;checkFinal();}});
					$('#op2').jTypeWriter({onComplete:function(){complete3=1;checkFinal();}});
					$('#op3').jTypeWriter({onComplete:function(){complete4=1;checkFinal();}});
					$('#op4').jTypeWriter({onComplete:function(){complete5=1;checkFinal();}});			
					$('#currentQuiz').text(quiz+1);				
					quiz++;
					
				}
				//$('#point').text(score);
			}else{ // End of complete if 				
					$('#radio1').removeAttr("checked"); 
					$('#radio2').removeAttr("checked");
					$('#radio3').removeAttr("checked");
					$('#radio4').removeAttr("checked");			
			}
        });
		
		function checkFinal(){
			if(complete1==1&&complete2==1&&complete3==1&&complete4==1&&complete5==1){
				completeFinal=1;
				$('#quiz,#radio1,#radio2,#radio3,#radio4,#op1,#op2,#op3,#op4').css("cursor","pointer");
			}
		
		}
		$('div.divbtn').hover(
		  function () {
			$(this).css("color","#5D8ABD");
		  }, 
		  function () {
			$(this).css("color","#54544A");
		  }
		);

		 $('#quiz').click(function () { 
			if($(this).text()=='Take the quiz again'){
			$('#formHref').attr({href:'http://www.debthelp.com/'});				
			$('#quiz').css("height","105px");
			$('#optionWrapper').css("height","210px");
			$('#quizResult').css("display","none");
			$('#formButton').css("display","none");
			$('#formIn').css("display","none");
			$('div.quiz_container').css("background","url(/img/quiz/background.jpg) no-repeat");
			quiz=0;
		 	score=0;
		 	$('#quiz').css("cursor","default");
			$('div.divbtn').css("display","block");			
			$('div.divRadiobtn').css("display","block");
			$('#radio1').css("display","block");
			$('#radio2').css("display","block");
			$('#radio3').css("display","block");
			$('#radio4').css("display","block");			
			$('#quiz').text(arr[quiz][0]);
			$('#op1').text(arr[quiz][1]);
			$('#op2').text(arr[quiz][2]);
			$('#op3').text(arr[quiz][3]);
			$('#op4').text(arr[quiz][4]);
			
			$('#currentQuiz').text(quiz+1);
			//$('#point').text(score);
			$('#quiz,#radio1,#radio2,#radio3,#radio4,#op1,#op2,#op3,#op4').css("cursor","wait");
			$('#radio1').removeAttr("checked"); 
			$('#radio2').removeAttr("checked");
			$('#radio3').removeAttr("checked");
			$('#radio4').removeAttr("checked");			  
          
			$('#quiz').jTypeWriter({onComplete:function(){complete1=1;checkFinal();}});
			$('#op1').jTypeWriter({onComplete:function(){complete2=1;checkFinal();}});
			$('#op2').jTypeWriter({onComplete:function(){complete3=1;checkFinal();}});
			$('#op3').jTypeWriter({onComplete:function(){complete4=1;checkFinal();}});
			$('#op4').jTypeWriter({onComplete:function(){complete5=1;checkFinal();}});
					
			
			quiz++;
			}			
        });
		
	
	 });