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>Hai buone nozioni sulla bellezza al naturale!<br />Per migliorare la tua conoscenza, scopri le principali procedure di bellezza di Demak'up nelle altre rubriche.</p>");
				else if(quizzScore<4) $('#resultat').append("<p>Hai una buona conoscenza delle procedure di bellezza al naturale<br />Per diventare una vera esperta e scoprire i consigli per abbellire la pelle, collegati alla sezione \"Primi passi per una bella pelle\"  sul sito della marca Demak'up.</p>");
				else $('#resultat').append("<p>Formidabile! Sei una vera donna Demak'up.<br />I passi fondamentali per la bellezza non hanno segreti per te. Continua ad arricchire la tua conoscenza e vai alla sezione \"Segreti per avere una pelle bella in giro per il mondo\"</p>");
				
				$('#resultat').slideDown(500);
			});
		}else{
			$('#question'+quizzQuest).slideUp(500, function(){
				quizzQuest++
				$('#question'+quizzQuest).slideDown(500);
				quizzChooseRep = true;
			});
		}
		
		return false;
	});
}