quizzChooseRep = true;
quizzQuest = 1;
quizzScore = 0;
quizzNbQuest = 1;

$(window).load(function () {
	$('#slideContent').animate({'margin':'0px'}, 1000).slideDown(1000);
});

$(document).ready(function(){
	$('#slideContent').hide();
	if($('.prehomeList')[0]) initPrehomeMenu();
	if($('#visuElems')[0]) initPrehomeElems();
	if($('.pageBeautyQuizz')[0]) initQuizz();
	
	// Empecher "coller" dans form
	$('#insEmailConf').bind('paste', function(){return false;});
	$('#insDate').focus(function(){
		if($(this).attr('value') == this.defaultValue) $(this).attr('value', '');
	}).blur(function(){
		if($.trim(this.value) == '') this.value = (this.defaultValue ? this.defaultValue : '');
	});
	
	// Choix pays
	$('#choixPays').change(function(){
		document.location.href = $(this).find(':selected').attr('value');
	});
});

function initPrehomeMenu(){
	$('.prehomeList li a').hover(function(){
		$(this).animate({'paddingLeft':'12px'}, 100);
	}, function(){
		$(this).animate({'paddingLeft':'8px'}, 100);
	});
}

function initPrehomeElems(){
	$('.prehomeList li').mouseover(function(){
		var classe = $(this).find('a').attr('class');
		var id = classe.substr(4, classe.length);
		
		$('#visuElems img').each(function(i, el){
			if(i == id-1)
				$(el).fadeIn(200);
			else
				$(el).fadeOut(200);
		});
	});
}

function initQuizz(){
	// Nb Questions
	quizzNbQuest = $('#quizzScratch h3').length;
	
	$('#slideContent #quizzScratch h3').each(function(i, el){
		var question = $('<div>').attr('class', 'question').attr('id', 'question'+(i+1)).append($(this), $(this).next());
		$('#questions').append(question);
		if(!i) question.show();
	});
	
	$('#questions ul li:last-child').css('margin', 0);
	
	$('#questions li').hover(function(){
		$(this).animate({'paddingLeft':'12px'}, 100).css({'backgroundColor':'#4d1940', 'color':'#fff'});
	}, function(){
		$(this).animate({'paddingLeft':'8px'}, 100).css({'backgroundColor':'#e9dfe5', 'color':'#5c1f5e'});
	}).click(function(){
		if(quizzChooseRep){
			// Si la réponse est bonne
			if($(this).children('strong')[0]){
				$('#reponses p').hide();
				$('#reponses').attr('class', 'repOK').slideDown();
				quizzScore++;
			}else{
				$('#reponses p').show();
				$('#reponses p span').text($('#question'+quizzQuest+' li strong').text());
				$('#reponses').attr('class', 'repNO').slideDown();
			}
			
			quizzChooseRep = false;
		}
		
		if(quizzQuest == quizzNbQuest){
			$('#nextQuest').text($('#nextQuest span').text());
		}
	});
	
	// Next question
	$('#nextQuest').click(function(){
		$('#reponses').hide();
		
		if(quizzQuest == quizzNbQuest){
			$('#nextQuest').text($('#nextQuest span').text());
			$('#question'+quizzQuest).slideUp(500, function(){
				$('#resultat h3 span').text(quizzScore);
				
				// Message selon le score
				if(quizzScore<3) $('#resultat').append("<p>Je hebt goede noties van schoonheid op een natuurlijke manier!<br />Ontdek de essentiële schoonheidsgebaren volgens Demak’Up in de andere rubrieken om je kennis te verdiepen.</p>");
				else if(quizzScore<4) $('#resultat').append("<p>Je hebt een goede kennis van natuurlijke schoonheidsgebaren.<br />Om een echte expert te worden en andere tips voor een mooiere huid te ontdekken, ga naar de rubriek ‘De eerste stap naar een mooie huid’op de website van het merk Demak’Up.</p>");
				else $('#resultat').append("<p>Bravo! Je bent een echte Demak’Up vrouw.<br />De essentiële schoonheidsgebaren hebben geen geheimen voor jou. Blijf je kennis verrijken en ontdek de rubriek ‘Geheimen voor een mooie huid over de hele wereld’.</p>");
				
				$('#resultat').slideDown(500);
			});
		}else{
			$('#question'+quizzQuest).slideUp(500, function(){
				quizzQuest++
				$('#question'+quizzQuest).slideDown(500);
				quizzChooseRep = true;
			});
		}
		
		return false;
	});
}
