var path = 'http://www.speurneus-webquest.be/';

$(document).ready(function() {
	$("#inloggen,#registratie").validate({
		errorLabelContainer: $("#errors")
	});
	
	$('#sprites_logo').sprite({fps: 7, no_of_frames: 3});
});

function doThumbs(what){
	$('#'+what).addClass(what);
}//doThumbs

function removeThumbs(what){
	$('#'+what).removeClass(what);
}//doThumbs

function doLoader(){
	$('#rechterzijde').html('<div id="loader">Even geduld...</div>');
}//doLoader

function writeStats(correct){
	$.ajax({
		type: "POST",
		url: path+'ajx/ajx.php',
		data: "action=writeStats&leerling="+$('#gebruiker').val()+"&week="+$('#week').val()+"&beurt="+getTurn()+"&truefalse="+correct,
		success: function(data){
		}
	});		
}//writeStats

function getTurn(){
	var beurten = $('#beurten').html();
	if(beurten==1) beurt = 3;
	if(beurten==2) beurt = 2;
	if(beurten==3) beurt = 1;
	return beurt;
}//getTurn

function lowerTurn(){
	var old = getTurn();
	var nieuwe_beurt = (parseInt($('#beurten').html())-1);
	$('#beurten').html(nieuwe_beurt);
	return old;
}//lowerTurn

function hideStartButton(){
	$('#start').fadeOut();
	$('#tobehidden').fadeOut();	
}//hideStartButton

function showStartButton(){
	$('#start').fadeIn();
}//hideStartButton

function startWeek1(){
	startTimer();
	hideStartButton();
	showQuestionWeek1('1');
}//startWeek1

function startWeek2(){
	startTimer();
	hideStartButton();
	showQuestionWeek2();	
}//startWeek2

function startWeek3(){
	startTimer();
	hideStartButton();
	showQuestionWeek3();	
}//startWeek2

function startWeek4(){
	startTimer();
	hideStartButton();
	showQuestionWeek4();	
}//startWeek2

function startTimer(){
	$("#interval").everyTime(1000,function(i) {
		$(this).html(i);
	});
}//startTimer

function resetTimer(){
	$("#interval").html('');
}//resetTimer

function addPoints(points){
	$('#score').val(parseInt($('#score').val())+parseInt(points));
}//addPoints

function showDialog(number){ 
	$('#who'+number).fadeIn();
}//showDialog

function hideDialog(number){ 
	$('#who'+number).fadeOut();
}//hideDialog

function checkBox(val){
	if(!$('#land'+val).attr('checked')) $('#land'+val).attr('checked','checked');
	else $('#land'+val).removeAttr('checked');
}//checkBox

function changeAvatar(variable){
	$('.borderimage').removeClass('activeimage'); 
	$('#foto'+variable).addClass('activeimage'); 
	$('#avatar').val('img_default/'+variable+'.jpg');
}//changeAvatar

function showMap(){
	window.open('http://www.speurneus-webquest.be/map.php','','width=466,height=589,status=no,toolbar=no,scrollbars=no,resizable=no,location=no');
}//showMap

function writeScore(msg){
	$('#interval').stopTime();			
	$.ajax({
		type: "POST",
		url: path+'ajx/ajx.php',
		data: 'action=writeScore&week='+$('#week').val()+'&score='+$('#score').val()+'&interval='+$('#interval').html()+'&beurt='+getTurn(),
		success: function(data){
			var score = data.split('|');
			var beurt = getTurn();
			$('#score'+beurt).html(score[0]);			
			lowerTurn();
			if(beurt!=3){
				var pogingen = '';
				if($('#beurten').html()==1) pogingen = 'poging';
				else pogingen = 'pogingen';
				boodschap = "<p>"+msg+" <b>"+score[0]+"</b> punten</p><p>Je hebt nog "+$('#beurten').html()+" resterende "+pogingen+".</p>";
			}else{
				boodschap = "<p>"+msg+"</p>";
				$('#content_tohide').css('display','none');
			}
			$.fancybox({
				'padding'		: 10,
				'content'		: boodschap,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic',
				'onClosed': function(){ 
					parent.location.reload(true); 
				}		
			});				
		}
	});		
}//writeScore

function showMessageAfterClick(msg){
	$('#load_txt').html(msg);
	$('#load_message').fadeIn('slow');
	setTimeout("hideMessageAfterClick()",2000);		
}//showMessageAfterClick

function hideMessageAfterClick(){
	$('#load_message').fadeOut('slow');
}//hideMessageAfterClick

function getMaximumScore(){
	var theScores=new Array();
	theScores[1]=parseInt($('#score1').html()) || 0;
	theScores[2]=parseInt($('#score2').html()) || 0;
	theScores[3]=parseInt($('#score3').html()) || 0;	
	return Array.max(theScores);
}//getMaximumScore
