function Strip0(date)
{
				var date;
				if (date < 10) return '0' +date;
				else return date;
				
}

function CompteARebours()
{
    var date_actuelle = new Date(); // On déclare la date d'aujourd'hui
	var annee = date_actuelle.getFullYear(); // On déclare aussi l'année actuelle
	
	var noel = new Date(annee, 0, 10, 19,54, 15); // On déclare la date de Noël
	
if (noel.getTime() < date_actuelle.getTime())
	noel = new Date(++annee, 0, 10, 19, 54, 15);
					
	var tps_restant = noel.getTime() - date_actuelle.getTime(); // Temps restant en millisecondes
	
	//============ CONVERSIONS
	
	var ds_restants = tps_restant / 100; // Dixièmes de secondes
	var s_restantes = tps_restant / 1000;
	var i_restantes = s_restantes / 60;
	var H_restantes = i_restantes / 60;
	var d_restants = H_restantes / 24;
	
	
					ds_restants = Math.floor(ds_restants % 10); // Secondes près
	s_restantes = Math.floor(s_restantes % 60); // Secondes près
					i_restantes = Math.floor(i_restantes % 60); // Minutes près
					H_restantes = Math.floor(H_restantes % 24); // Heures près
					d_restants = Math.floor(d_restants); // Jour près
	//==================
	
	/*var mois_fr = new Array('Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre');
	
	var texte = "Nous sommes le <strong>" +date_actuelle.getDate()+ " " +mois_fr[date_actuelle.getMonth()]+ " " +date_actuelle.getFullYear()+ "</strong>," +
								"	et il est <strong>" +Strip0(date_actuelle.getHours())+ "h" +Strip0(date_actuelle.getMinutes())+ "</strong>.<br />";
	
	texte += "Il reste exactement <strong>" +d_restants+ " jours</strong>, <strong>" +H_restantes+ " heures</strong>," +
									" <strong>" +i_restantes+ " minutes</strong> et <strong>" +s_restantes+ "." +ds_restants+ "s</strong> avant d'ouvrir les cadeaux <:o).";
	
	
	document.getElementById("affichage").innerHTML = texte;*/
	
	$("#c_jours").html(d_restants);
	$("#c_heures").html(H_restantes);
	$("#c_min").html(i_restantes);
	$("#c_sec").html(s_restantes);
}

function initVoting()
{
		
	$("#ratingBox a").click(function(){
			
		//$("#ratingBox a").addClass("hasVoted");	
		
		_player = $(this).parent().attr("class");
		
		//// POST vote
		$.post("_php/vote.php", { player: _player},
		function(data){
			
		 $('#resultsBox #'+_player).children('.count').html(data);//.hide().fadeIn("normal");;
		 //$('#ratingDialog').html("Merci d'avoir voté").hide().fadeIn("normal");
		 
		});			
		
		$("#ratingBox").fadeOut(0);
		$("#resultsBox").fadeIn(400,function(){ updateVote(_player); });		
		
		
		return false;
	});
}

function updateVote(_player)
{
	if(_player=="iniesta") iniesta_r++;
	else if(_player=="iniesta") messi_r ++;
	else if(_player=="xavi") xavi_r ++;
	
	totalRating = iniesta_r + messi_r + xavi_r;
	
	iniesta_p = (iniesta_r/totalRating*100).toFixed(1);
	messi_p = (messi_r/totalRating*100).toFixed(1);
	xavi_p = (xavi_r/totalRating*100).toFixed(1);	
	
	iniesta_pos = (130*iniesta_p)/100 + "px";
	messi_pos = (130*messi_p)/100 + "px";
	xavi_pos = (130*xavi_p)/100 + "px";
	
	$("#iniesta .count").stop().animate({backgroundPosition:iniesta_pos},{duration:1500});
	$("#messi .count").stop().animate({backgroundPosition:messi_pos},{duration:1500});
	$("#xavi .count").stop().animate({backgroundPosition:xavi_pos},{duration:1500});
	
	$("#iniesta .pourc").html(iniesta_p+"%");
	$("#messi .pourc").html(messi_p+"%");
	$("#xavi .pourc").html(xavi_p+"%");
	
	$("#totalRating").html(totalRating).hide().fadeIn("normal");
}



