var total_points = 0; 
var dngr = 0;
var all_points = 95; // Max number of points
var num_ofQuestions = $("#questions li ul").length;
animatedcollapse.addDiv('question1', 'fade=1,speed=400')
animatedcollapse.init();

var response = new Array();
//1st param - part of JPG name
//2nd param - title of car style 
//3rd param - score symbol
response[0] = new Array('a','very safe','A');
response[1] = new Array('b', 'a little risk','B');
response[2] = new Array('c', 'average risk','C');
response[3] = new Array('d','risky','D');
response[4] = new Array('f', 'very dangerous', 'F');

function init() {
  for (i = 2; i < num_ofQuestions+1; i++) {
	  if ('question' + i) {
			animatedcollapse.addDiv('question' + i, 'fade=1,speed=300, hide=1');
		} else {
			break;
		}
  }	
}

function calcDangere(total_points){
	// the progress bar width: 590px; 
	// we calculate a percentage score
	var user_points = Math.round((total_points *100)/ all_points) ;	

	// then apply that score to the progress bar
	var dangere_score =(590 * user_points) / 100;
		if(dangere_score==0)dangere_score=5;
	return  dangere_score;
}

function transition(question_id,points) {
	var points;
	var score;
	animatedcollapse.hide('question' + question_id);
	//('question' + question_id).fadeOut("slow");
	total_points += points;
	dngr = calcDangere(total_points);
	// the progress bar needs to get wider as they earn more points
	// if they score a 100% the progress bar needs to be 590 pixels wide
	$('#progress').css("width", dngr+"px");
	if(question_id < num_ofQuestions){
		question_id++;
		if ('question' + question_id) {
			animatedcollapse.show('question' + question_id);
		} 
	}
	else {
		$("#results").css("display","block");
		$("#footer").css("display","block");
		if(total_points>=0 && total_points<21){
			// a
			r=0;
			
		}
		if(total_points>20  && total_points<41){
			// b
			r=1;
		}
		if(total_points>40  && total_points<61){
			// c
			r=2;
		}
		if(total_points>60  && total_points<81){
			// d
			r=3;
		}
		if(total_points>80  && total_points<101){
			// f
			r=4;
		}
	score = 100 - total_points;
	$("h2").html("You scored a "+score+"% ("+response[r][2]+")!  Your driving level is: <strong>"+response[r][1]+"</strong>");
	$("#image_block").html('<a href="http://www.thecarconnection.com/dangerous-quiz/"><img src="img/'+response[r][0]+'.jpg" alt="How dangerous of a driver are you?" /></a>');
	$("#htmlCode").val('<a href="http://www.thecarconnection.com/dangerous-quiz/index.html"><img src="http://www.thecarconnection.com/dangerous-quiz/img/'+response[r][0]+'.jpg" alt="How dangerous of a driver are you?" /></a><p style="margin: 5px 0;">Created by <a href="http://www.thecarconnection.com/">The Car Connection</a>');
	}
	
}
init();