var vragen = new Array();
vragen[0] = new Array(
	"What is the difference between peanuts and nuts?"
	, new Array(
		"Peanuts grow on a plant under the ground",
		"Nuts grow on trees",
		"Both answers are correct")
	, new Array(
		1, 0, 0)
	, "Peanuts are legumes. They grow on a plant under the ground, and not like nuts on a tree.");

vragen[1] = new Array(
	"What nutrients do peanuts and nuts contain?"
	, new Array(
		"Proteins and unsaturated fats",
		"Vitamins and minerals",
		"All these nutrients")
	, new Array(
		0, 0, 1)
	, "Although they seem small, peanuts and nuts are fully packed with healthy nutrients, such as vitamins and minerals, together with proteins and unsaturated fats.");

vragen[2] = new Array(
	"Which ‘good’ fats do peanuts and nuts contain?"
	, new Array(
		"Cholesterol",
		"Unsaturated fats",
		"Saturated fats")
	, new Array(
		0, 1, 0)
	, "The fat in peanuts and nuts is mainly unsaturated fat. This &lsquo;good&rsquo; fat can lower the cholesterol level in our blood. And that is good news for our blood vessels.");
		
vragen[3] = new Array(
	"Peanuts and nuts contain fibre.<br /> One handful of peanuts or nuts contains the same amount of fibre as:"
	, new Array(
		"2 good tablespoons of vegetables",
		"&frac12; tablespoon of vegetables",
		"1 tablespoon of vegetables")
	, new Array(
		1, 0, 0)
	, "Yes, it’s true. One handful of peanuts or nuts contains just as much fibre as 2 good tablespoons of vegetables. This is 3% of the amount of fibre you need every day.");
		
vragen[4] = new Array(
	"Which vitamins are mainly contained in peanuts and nuts?"
	, new Array(
		"Vitamin C",
		"Vitamin E",
		"No vitamins")
	, new Array(
		0, 1, 0)
	, "Peanuts and nuts are a good source of vitamin E. Especially hazelnuts and almonds contain a large amount of this vitamin.");

vragen[5] = new Array(
	"Peanuts and nuts are fully packed with energy.<br /> Which nutrient delivers this energy?"
	, new Array(
		"Unsaturated fats",
		"Carbohydrates",
		"Both")
	, new Array(
		0, 0, 1)
	, "Both carbohydrates and unsaturated fats are an important source of energy for our body.");
		
vragen[6] = new Array(
 	"Are peanuts actually nuts?"
 	, new Array(
 		"Yes, peanuts are nuts",
 		"No, peanuts are legumes",
 		"No, peanuts are vegetables")
 	, new Array(
 		0, 1, 0)
	, "Peanuts are legumes, as are peas, beans and lentils. Just like other legumes, they grow on a plant. Nuts grow on trees. However, peanuts are often thought to be nuts because their structure and nutritional value are very similar.");

vragen[7] = new Array(
 	"Where are almonds grown?"
 	, new Array(
 		"In the United States",
 		"In Spain and Italy",
 		"Both answers are correct")
 	, new Array(
 		0, 0, 1)
	, "Almonds are grown in the United States,Spain and Italy.");
	
vragen[8] = new Array(
 	"What is the almond’s nickname?"
 	, new Array(
 		"The queen of the rose family",
 		"The laughing nut",
 		"La Pacani&egrave;re")
 	, new Array(
 		1, 0, 0)
	, "Almonds belong to the rose family. Hence their nickname.");
	
vragen[9] = new Array(
 	"Cashew nuts from the tropics contain a large amount of selenium. Where does this come from?"
 	, new Array(
 		"From rainwater",
 		"From sunshine",
 		"From the soil")
 	, new Array(
 		0, 0, 1)
	, "The cashew nuts that grow in the tropics contain more selenium than European or North American cashew nuts, as the soil in which they grow contains more selenium.");

vragen[10] = new Array(
	"The hazelnut is a wellknown nut. Of what is the hazel the symbol?"
	, new Array(
		"Marriage, wealth and domestic happiness",
		"Disease and weakness",
		"Poverty and dissatisfaction")
	, new Array(
		1, 0, 0)
  	, "From time immemorial, the hazel has been the symbol of marriage, plenty, wealth and domestic happiness. It is also seen as the symbol of peace and health, and a source of strength.");	

vragen[11] = new Array(
 	"Hazelnuts are exceptionally rich in one vitamin. Which one?"
 	, new Array(
 		"Vitamin K",
 		"Vitamin C",
 		"Vitamin E")
 	, new Array(
 		0, 0, 1)
	, "Hazelnuts contain a very large amount of vitamin E. When you eat a handful of hazelnuts (30 g), this gives you no less than 78% of the amount of vitamin E that you need each day. And that is good, because vitamin E is a powerful antioxidant. Antioxidants can play an important role in the prevention of cardiovascular diseases and cancer.");

vragen[12] = new Array(
 	"Who discovered the macadamia tree?"
 	, new Array(
 		"Dr Einstein",
 		"Dr Macadam",
 		"Ms Nuts")
 	, new Array(
 		0, 1, 0)
	, "The macadamia tree was discovered in 1857 by Dr John Macadam in the rain forest on the east coast of Australia.");
	
vragen[13] = new Array(
 	"Of all nuts, the macadamia contains the highest content of unsaturated fats. What are these fats good for?"
 	, new Array(
 		"Lowering the cholesterol level",
 		"Lowering resistance",
 		"Increasing the chance of cardiovascular diseases")
 	, new Array(
 		1, 0, 0)
	, "Of all nuts, macadamias contain the highest content of unsaturated fats, that is to say 88%. Unsaturated fats lower the cholesterol level in the blood. The fatty acid content of macadamias is equal to that of olive oil.");

vragen[14] = new Array(
 	"What is the Brazil nut well known for?"
 	, new Array(
 		"Its shape",
 		"Its nutritional value",
 		"Its taste")
 	, new Array(
 		0, 1, 0)
	, "The Brazil nut became well known in Europe after a Spanish officer gave his starving troops Brazil nuts to eat. As a result of the Brazil nut’s high nutritional and energy value, the men recovered quickly.");
	
vragen[15] = new Array(
	"The tree on which the Brazil nut grows can reach a great height. How tall?"
	, new Array(
		"10 to 20 metres",
		"20 to 40 metres",
		"40 to 60 metres")
	, new Array(
		0, 0, 1)
   , "The Brazil nut is similar to the coconut, growing on a tree that is 40 to 60 metres tall with a diameter of approximately two metres. This remarkable tree grows in the Brazilian Amazon basin. It is an enormous tree that towers above all that surrounds it.");

vragen[16] = new Array(
 	"Where refers the name Brazil nut to?"
 	, new Array(
 		"Its shape",
 		"Its origin",
 		" Its taste")
 	, new Array(
 		0, 1, 0)
	, "The Brazil nut’s name refers to its origin. The tree grows in the Brazilian Amazon basin. An enormous tree that towers above all that surrounds it.");

vragen[17] = new Array(
 	"The Brazil nut is very rich in a particular mineral because it grows in the area around the Amazon. Which mineral?"
 	, new Array(
 		"Selenium",
 		"Iron",
 		"Dietary fibre")
 	, new Array(
 		1, 0, 0)
	, "The rich soil in the sun-drenched Amazon basin where the Brazil nut grows is the cause of its high content of the mineral selenium. A handful of Brazil nuts contains approximately 575% of the amount of selenium you need each day.");

vragen[18] = new Array(
 	"When is the pecan nut harvested?"
 	, new Array(
 		"From September to December",
 		"From November to February",
 		"From March tot August")
 	, new Array(
 		0, 1, 0)
	, "The pecan nut is harvested from November to February. Just as the other types of nuts, the pecan produces a large crop every other year.");

vragen[19] = new Array(
 	"Where did the peanut come from originally?"
 	, new Array(
 		"The Netherlands",
 		"Russia",
 		"South America")
 	, new Array(
 		0, 0, 1)
	, "The peanut originally came from South America. More than 3,500 years ago, the Incas gave peanuts to their dead as food for the hereafter. Spanish explorers took peanuts back to Spain with them, and from there they spread throughout Asia and Africa.");

vragen[20] = new Array(
	"Which antioxidant can be found in large amounts in peanuts?"
	, new Array(
		"Vitamin K",
		"Proteins",
		"Vitamin E")
	, new Array(
		0, 0, 1)
	, "Peanuts contain large amounts of vitamin E. When you eat one handful of peanuts this gives you 24% of the recommended daily intake. Vitamin E is a powerful antioxidant that can play an important role in the prevention of cardiovascular diseases and cancer.");

vragen[21] = new Array(
 	"What is the pistachio nut’s nickname?"
 	, new Array(
 		"The laughing nut",
 		"The hard nut",
 		"The round nut")
 	, new Array(
 		1, 0, 0)
	, "The pistachio nut’s nickname is the laughing nut. This is because of the shape of its shell, which bursts open when the nut is ripe.");

vragen[22] = new Array(
 	"What is the pistachio nut’s Latin name?"
 	, new Array(
 		"Macadamia integrifolia",
 		"Pistacea vera",
 		"Arachis hypogaea")
 	, new Array(
 		0, 1, 0)
	, "The Latin name for the pistachio nut is Pistacea vera. Macadamia integrifolia is the Latin name for the macadamia, and Arachis hypogaea for the peanut.");
	
vragen[23] = new Array(
 	"With the growth of which fruit is the growth of pistachio nuts comparable?"
 	, new Array(
 		"Oranges",
 		"Pineapples",
 		"Grapes")
 	, new Array(
 		0, 0, 1)
	, "The growth of pistachios nuts is comparable with that of grapes; they grow in bunches on a tree.");

vragen[24] = new Array(
 	"Which part of the human body does the shape of walnuts resemble?"
 	, new Array(
 		"Eye",
 		"Brain",
 		"Leg")
 	, new Array(
 		0, 1, 0)
	, "The walnut was called the kara (head) by the Greeks, as the shape of the nut bears a strong resemblance to the human brain.");

vragen[25] = new Array(
 	"Walnuts are well known for their high concentrations of a certain sort of fat.<br />What sort of fat is this?"
 	, new Array(
 		"Omega-3 fatty acids",
 		"Saturated fatty acids",
 		"Omega-6 fatty acids")
 	, new Array(
 		1, 0, 0)
	, "Walnuts are well known for their high concentration of omega-3 fatty acids. Omega-3 fatty acids are essential fatty acids. Therefore because our body cannot produce them itself we must obtain them via our food. Omega-3 fatty acids lower the level of cholesterol in the blood, preventing cardiovascular disease.");

vragen[26] = new Array(
 	"Just like meat, fish and beans, peanuts and nuts are a good source of protein. For what do we need proteins?"
 	, new Array(
 		"As building blocks",
 		"As a source of energy",
 		"Both answers are correct")
 	, new Array(
 		0, 0, 1)
	, "Proteins are important building blocks for our body. We need them to build our cells, muscles, organs, nervous system, bones and blood. Proteins also supply energy: 4 kcal per gram of protein. However, carbohydrates and fats are the most important sources of energy for our body.");

vragen[27] = new Array(
 	"Do peanuts and nuts naturally contain salt?"
 	, new Array(
 		"Yes, a lot",
 		"Yes, but very little",
 		"No, not at all")
 	, new Array(
 		0, 1, 0)
	, "Peanuts and nuts naturally contain very little salt: approximately 2 mg per 30 gm portion. Salted peanuts and nuts of course do contain salt: approximately 200 mg per 30 gm. That is roughly 6% of the amount of salt you may eat per day.");

vragen[28] = new Array(
 	"Peanuts and nuts contain antioxidants.What do antioxidants do?"
 	, new Array(
 		"Provide protection against free radicals",
 		"Provide protection against vitamins",
 		"Provide protection against fat")
 	, new Array(
 		1, 0, 0)
	, "Antioxidants are natural substances that protect our body against so-called free radicals. Free radicals are molecules that can damage the cells in our body, but fortunately for us our body is protected by antioxidants.");

vragen[29] = new Array(
 	"Peanuts and nuts are good substitutes for meat. Why?"
 	, new Array(
 		"They contain proteins and iron",
 		"They contain B-vitamins",
 		"Both answers are correct")
 	, new Array(
 		0, 0, 1)
	, "Because of their high content of proteins, minerals (including iron) and B-vitamins, peanuts and nuts are an excellent substitute for meat.");

var huidigeVraag = 0;
var aantalVragen = 7;
var score = 0;

var ivoSpeed = 300;

var voltooideVragen = new Array();

function startQuiz() {
	$('.optionA .button').click(function() {
		antwoordSelected(0);
	});
	$('.optionB .button').click(function() {
		antwoordSelected(1);
	});
	$('.optionC .button').click(function() {
		antwoordSelected(2);
	});
	$('div#nextQuestion a').click(function() {
		nextVraag();
	});
	$('div#antwoord, .goed, .fout, div#question').hide();
	
	nextVraag();
}

function nextVraag() {
	antwoordAnimating = false;
	huidigeVraag = Math.floor((Math.random() * vragen.length));
	for (i = 0; i < voltooideVragen.length; i++) {
		if (voltooideVragen[i] == vragen[huidigeVraag]) {
			nextVraag(); // stack overflow possible if less questions available then num questions asked!
			return;
		}
	}
	showVraag();
}

function showVraag() {
	$('#question').animate({marginLeft : '-600px', opacity : 'hide'}, ivoSpeed, function() {
		$('#question').css({marginLeft: '600px'});
		$('.checkboxImage').attr('src', 'images/answer_none.png');
		$('div#antwoord, p.goed, p.fout').hide();
		$('#vraagTekst').html(vragen[huidigeVraag][0]);
		$('.optionB .button').css({backgroundImage : "url('images/blue_button.png')"});
		$('.optionA .button .text').html(vragen[huidigeVraag][1][0]);
		$('.optionB .button .text').html(vragen[huidigeVraag][1][1]);
		$('.optionC .button .text').html(vragen[huidigeVraag][1][2]);
		$('.optionA .button').show();
		$('.optionB .button').show();
		$('.optionC .button').show();
		$('h1#vraagHeader').html('Question ' + (voltooideVragen.length + 1) + ' / 7').show();
		$('#question').animate({marginLeft : 0, opacity : 'show'}, ivoSpeed);
	});
}

function antwoordSelected(index) {
	window.status = 'selected';
	if (index == 0) {
		$('.optionB .button, .optionC .button').fadeOut(ivoSpeed, animateAntwoordA);
	} else if (index == 1) {
		$('.optionA .button, .optionC .button').fadeOut(ivoSpeed, animateAntwoordB);
	} else if (index == 2) {
		$('.optionB .button, .optionA .button').fadeOut(ivoSpeed, animateAntwoordC);
	}
}

var antwoordAnimating = false;

function animateAntwoordA() {
	if (antwoordAnimating) return;
	antwoordAnimating = true;
	if (vragen[huidigeVraag][2][0]) { // goed geantwoord
		nootjeGoed(voltooideVragen.length);
	} else { // fout
		nootjeFout(voltooideVragen.length)
	}
	voltooideVragen.push(vragen[huidigeVraag]);
	$('p#antwoordTekst').html(vragen[huidigeVraag][3]);
	checkIfQuizIsComplete();
	$('div#antwoord').fadeIn();
}

function animateAntwoordB() {
	if (antwoordAnimating) return;
	antwoordAnimating = true;
	
	$('.optionB .button').css('margin-top', '49px').animate({ marginTop : '0' }, ivoSpeed, 'linear', function() {
		if (vragen[huidigeVraag][2][1]) { // goed geantwoord
			nootjeGoed(voltooideVragen.length);
		} else { // fout
			nootjeFout(voltooideVragen.length);
		}
		voltooideVragen.push(vragen[huidigeVraag]);
		$('p#antwoordTekst').html(vragen[huidigeVraag][3]);
		checkIfQuizIsComplete();
		$('div#antwoord').fadeIn();
	});
}

function animateAntwoordC() {
	if (antwoordAnimating) return;
	antwoordAnimating = true;
	$('.optionC .button').css('margin-top', '98px').animate({ marginTop : '0' }, ivoSpeed, 'linear', function() {
		if (vragen[huidigeVraag][2][2]) { // goed geantwoord
			nootjeGoed(voltooideVragen.length);
		} else { // fout
			nootjeFout(voltooideVragen.length);
		}
		voltooideVragen.push(vragen[huidigeVraag]);
		$('p#antwoordTekst').html(vragen[huidigeVraag][3]);
		checkIfQuizIsComplete();
		$('div#antwoord').fadeIn();
	});
}

function checkIfQuizIsComplete() {
	if (voltooideVragen.length == 7) { // quiz complete yo!
		$('#nextQuestion').html('<a href="#finishQuiz" id="finishQuizButton"><img src="images/uitslag.png" width="149" height="26" alt="Volgende Vraag" /></a>'); // hier komt knop die functie aanroept showScore()
		$('#finishQuizButton').click(showScore);
	}
}

function validateNewsletterForm(form) {
	if (form.email.value.trim().value == '' || !form.email.value.isEmailAddress()) {
		alert('Please enter an e-mail address.');
		return false;
	}
	return true;
}

function showScore() {
	if (score <= 3) {
		$('#question').html('<div id="scenario3"><form method="post" action="http://webservices.schuttelaar.nl/about_nuts/subscribe.php" onsubmit="return validateNewsletterForm(this);"><p class="scenario">You collected ' + score + ' unbroken hazelnuts.<br /> You still have a lot to learn about peanuts and nuts. Search through the About Nuts website <a class="redLink" href="http://www.aboutnuts.com/index.aspx?Lang=English" target="_blank" >(www.aboutnuts.com)</a> and learn more about peanuts and nuts. When you play the game again, you&apos;re sure to get all seven ubroken nuts.</p><p class="news">Would you like to receive the About Nuts newsletter with health tips and delicious recipes? Just fill in the form!<br /><input type="text" class="newsSubscribe" name="email" /><input type="hidden" name="consumer_en" value="true" /><input type="image" src="images/inschrijven.png" value="Aanmelden" class="newsletterAanmeldenButton" /></p></form></div>');
	} else if (score <= 6) {
		$('#question').html('<div id="scenario2"><form method="post" action="http://webservices.schuttelaar.nl/about_nuts/subscribe.php" onsubmit="return validateNewsletterForm(this);"><p class="scenario">You collected ' + score + ' unbroken hazelnuts.<br />Well done, you’re almost an expert on nuts. Do you want to learn more about peanuts and nuts? Search through the About Nuts website <a class="redLink" href="http://www.aboutnuts.com/index.aspx?Lang=English" target="_blank" >(www.aboutnuts.com)</a>,then play the game again. You&apos;re sure to get all seven unbroken nuts.</p><p class="news">Would you like to receive the About Nuts newsletter with health tips and delicious recipes? Just fill in the form!<br /><input type="text" class="newsSubscribe" name="email" /><input type="hidden" name="consumer_en" value="true" /><input type="image" src="images/inschrijven.png" value="Aanmelden" class="newsletterAanmeldenButton" /></p></form></div>');		
	} else {
		$('#question').html('<div id="scenario1"><form method="post" action="http://webservices.schuttelaar.nl/about_nuts/subscribe.php" onsubmit="return validateNewsletterForm(this);"><p class="scenario">Congratulations, all your hazelnuts are unbroken.<br />You really are an expert on peanuts and nuts!<br /> Would you like to find out more about peanuts and nuts? Search through the About Nuts	website <a class="redLink" href="http://www.aboutnuts.com/index.aspx?Lang=English" target="_blank" >(www.aboutnuts.com)</a>,then play the game again.Bet you get all seven unbroken nuts in row again!.</p><p class="news">Would you like to receive the About Nuts newsletter with health tips and delicious recipes? Just fill in the form!<br /><input type="text" class="newsSubscribe" name="email" /><input type="hidden" name="consumer_en" value="true" /><input type="image" src="images/inschrijven.png" value="Aanmelden" class="newsletterAanmeldenButton"/></p></form></div>');
	}
}

function nootjeGoed(index) {
	score++;
	$('p.goed').show();
	$('.nootje' + index).attr('src', 'images/nut_true.png');
	$('.checkboxImage').fadeOut(100, function() {
		$(this).attr('src', 'images/answer_true.png').fadeIn(ivoSpeed / 2);
	});
}

function nootjeFout(index) {
	$('p.fout').show();
	$('.nootje' + index).attr('src', 'images/nut_false.png');
	$('.checkboxImage').fadeOut(100, function() {
		$(this).attr('src', 'images/answer_false.png').fadeIn(ivoSpeed / 2);
	});
}

String.prototype.trim = function () {
    return this.replace(/^s*/,'')
                     .replace(/s*$/,'');
};

String.prototype.isEmailAddress = function() {
	var emailTestRegex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
	return this.match(emailTestRegex);
}