var nDuration = 1.5;
var nSync = 0.037; // Constante à ne pas changer

/**
 * Animation GlobalScore
 */
animateGlobalScore = function(bViewScore, nGlobalScore, nGlobalScoreView, nBarSize, nScaleBegin, nScaleEnd, strSymbol) {
	// Calculs pour l'animation
	var nScore     = (nScaleEnd - nScaleBegin) < 100 ? nGlobalScoreView : nGlobalScore;
	var nTimeSync  = (nDuration*nSync) - (nScore /(2*1000)); // Calcul du temps pour synchroniser l'incrémentation du Score et l'avancement de la Bar
	var cptGs      = nScaleBegin;
	var nIncrement = Math.ceil((nScaleEnd - nScaleBegin) / 100);
	
	// Incrémentation du Score (Si le Score est affiché)
	if(bViewScore) {
		var eltBar = (nGlobalScore >= 80) ? $('GraphScoreInter') : $('GraphScoreExter');

		new PeriodicalExecuter(function(pe) {
			if((cptGs+nIncrement)<=nGlobalScoreView) 
				cptGs = cptGs+nIncrement;
			else 
				cptGs = nGlobalScoreView;
			
			if(cptGs==nGlobalScoreView)
				pe.stop();
			
			if(strSymbol != '')
				eltBar.innerHTML = cptGs + strSymbol;
			else 
				eltBar.innerHTML = cptGs + '/' + nScaleEnd;
		}, nTimeSync);
	}

	// Effet Morphing sur la Bar
	$('GraphBar').setStyle({ 'width': '0%' });
	new Effect.Morph('GraphBar', {
 		style: 'width:'+nBarSize+'%',
		duration: nDuration,
		transition: Effect.Transitions.easeInOutQuad
	});
};

/**
 * Animation PartScore
 */
animatePartScore = function(idBar, bViewScore, nAxeScore, nAxeScoreWidth, nScaleBegin, nScaleEnd, strSymbol) {
	// Elements
	var eltScoreTop		= $('ScoreTop'+idBar);
	var eltBar		    = $('Bar'+idBar);
	var eltScoreBottom	= $('ScoreBottom'+idBar);

	// Calculs pour l'animation
	var nTimeSync  = (nDuration*nSync) - (nAxeScore/(2*1000)); // Calcul du temps pour synchroniser l'incrémentation du Score et l'avancement de la Bar
	var cptPs      = nScaleBegin;
	var nIncrement = Math.ceil((nScaleEnd - nScaleBegin) / 100);
	
	// Incrémentation du Score (Si le Score est affiché)
	if(bViewScore) {
		new PeriodicalExecuter(function(pe) {
			if((cptPs+nIncrement)<=nAxeScore) 
				cptPs = cptPs+nIncrement;
			else 
				cptPs = nAxeScore;
			
			if(cptPs==nAxeScore)
				pe.stop();
			
			if(strSymbol != '')
				eltScoreTop.innerHTML = cptPs + strSymbol;
			else 
				eltScoreTop.innerHTML = cptPs + "/" + nScaleEnd;
				
		}, nTimeSync);
	}
	
	// Effet Morphing sur la Bar
	eltBar.setStyle({ 'width': '0%' });
	new Effect.Morph('Bar'+idBar, {
 		style: 'width:'+nAxeScoreWidth+'%',
		duration: nDuration,
		transition: Effect.Transitions.easeInOutQuad
	});

	// Effet Morphing pour faire avancer le Score en même temps que la Bar
	eltScoreTop.setStyle({ 'width': '0%' });
	new Effect.Morph('ScoreTop'+idBar, {
 		style: 'width:'+nAxeScoreWidth+'%',
		duration: nDuration,
		transition: Effect.Transitions.easeInOutQuad
	});

	// Pas d'effet pour l'instant car pas de score affiché
	eltScoreBottom.setStyle({ 'width' : nAxeScoreWidth+'%' });
};

/**
 * Animation DetailedReport
 */
animateDetailedReport = function() {
	$("DetailedReportButton").setStyle({ 'position': 'relative',
										 'top':'-100px',
										 'opacity': '0' 
	});
	
	new Effect.Parallel([ 
	                      new Effect.Move("DetailedReportButton", { sync: true, x: 0, y: 100, mode: 'relative', transition: Effect.Transitions.easeOutBounce }), 
	                      new Effect.Opacity("DetailedReportButton", { sync: true, from: 0, to: 1 }) 
	                     ], { 
						  duration: nDuration,
						  delay: 0.5
						 }
	);
};

/**
 * Animation des contenus Texte
 */
animateContent = function (eltText) {
	eltText.fade({ duration: nDuration, from: 0, to: 1 });
};
