
	var fx1,fx2,fx3,fx4,fx5,fx6,fx7,fx8;
	var phase = 0;
	var contenutele = '';
	var fautscier, pausescie, posStart, reprisesciage;
	window.addEvent('domready', function(){

		fautscier = function(){
			//va chercher le reccord et affecte le résultat à var_reccord
			// pour comparer avec nbrplanches à la sortie
			new Request.HTML({
				url: 'recplanches.php',
				method: 'get',
				onSuccess: function(html, text, mesgenoux) {
					var_reccord = mesgenoux.toInt();
				}
			}).send();
			$('sciage').setStyle('display', 'block');
			var leftplot = (sz.x / 2) - (370 + 336 + 30);
			if(leftplot > 0) $('plot').setStyle('left', 0);
			else $('plot').setStyle('left', leftplot);
			posStart = $('lame').getCoordinates().left;
			$('contgrume').setStyle('left', posStart-700-50);
			$('tele').setStyle('background-image', 'url(images/tele22.jpg)');
			contenutele = $('msgtele1').get('html');
			$('msgtele1').set('html', '<br><br><br>Lancement de la turbine ...');
			lance();
		}
		///////////////////////////////
		var lance = function(){
			(function(){ 
				$('lame').removeClass('lameStop').addClass('lameScie');
	 			approche.delay(2000);
				(function(){ $('msgtele1').set('html', contenutele) }).delay(4000);
			}).delay(2000);
		}
		////////////////////////////////
		var approche = function(){
			phase = 1;
			fx1 = new Fx.Tween($('contgrume'), {
				duration: 4000,
				onComplete: function(){
					scie1();
				}
			}).start('left', posStart-700)
		}
		////////////////////////////////
		var scie1 = function(){
			$('sciurex').setStyles({
				'left': posStart-30,
				'top': 15,
				'visibility': 'visible'
			});
			$('coupe').setStyles({
				'width': 0,
				'top': 32,
				'visibility': 'visible'
			});
			phase = 2;
			fx2 = new Fx.Elements([$('contgrume'), $('coupe')], {
				duration: 15000,
				onComplete: function(){
					nbrplanches ++;
					(function(){ 
						$('plot').setStyle('height', $('plot').getStyle('height').toInt() + 17);
						testrecord(); 
					}).delay(3000);
					if(nbrplanches == 1) $('dosses').innerHTML = nbrplanches +" planche";
					else $('dosses').innerHTML = nbrplanches +" planches";
					$('sciurex').setStyle('visibility', 'hidden');
					$('dessous1').setStyle('visibility', 'hidden');
					$('coupe').setStyle('visibility', 'hidden');
					$('result1').setStyle('visibility', 'visible');
					degage();
				}
			}).start({
				'0': {
					'left': posStart
				},
				'1': {
					'width': 700
				}
			});
		}
		////////////////////////////////
		var degage = function(){
			phase = 3;
			fx3 = new Fx.Tween($('contgrume'), {
				duration: 4000,
				onComplete: function(){
					recule();
				}
			}).start('left', posStart+50);
		}
		////////////////////////////////
		var recule = function(){
			phase = 4;
			fx4 = new Fx.Tween($('contgrume'), {
				duration: 4000,
				onComplete: function(){
					$('result1').setStyle('visibility', 'hidden');
					$('dessus2').setStyle('visibility', 'visible');
					$('dessous2').setStyle('visibility', 'visible');
					approche2();
				}
			}).start('left', posStart-700-50)
		}
		////////////////////////////////
		var approche2 = function(){
			phase = 5;
			fx5 = new Fx.Tween($('contgrume'), {
				duration: 4000,
				onComplete: function(){
					scie2();
				}
			}).start('left', posStart-700)
		}
		////////////////////////////////
		var scie2 = function(){
			$('sciurex').setStyles({
				'top': 6,
				'visibility': 'visible'
			});
			$('coupe').setStyles({
				'width': 0,
				'top': 19,
				'visibility': 'visible'
			});
			phase = 6;
			fx6 = new Fx.Elements([$('contgrume'), $('coupe')], {
				duration: 15000,
				onComplete: function(){
					nbrplanches ++;
					(function(){ 
						$('plot').setStyle('height', $('plot').getStyle('height').toInt() + 17);
						testrecord(); 
					}).delay(3000);
					$('dosses').innerHTML = nbrplanches +" planches";
					$('sciurex').setStyle('visibility', 'hidden');
					$('dessous2').setStyle('visibility', 'hidden');
					$('coupe').setStyle('visibility', 'hidden');
					$('result2').setStyle('visibility', 'visible');
					degage2();
				}
			}).start({
				'0': {
					'left': posStart
				},
				'1': {
					'width': 700
				}
			});
		}
		////////////////////////////////
		var degage2 = function(){
			phase = 7;
			fx7 = new Fx.Tween($('contgrume'), {
				duration: 4000,
				onComplete: function(){
					recule2();
				}
			}).start('left', posStart+50);
		}
		////////////////////////////////
		var recule2 = function(){
			phase = 8;
			fx8 = new Fx.Tween($('contgrume'), {
				duration: 4000,
				onComplete: function(){
					$('result2').setStyle('visibility', 'hidden');
					$('dessus1').setStyle('visibility', 'visible');
					$('dessous1').setStyle('visibility', 'visible');
					approche();
				}
			}).start('left', posStart-700-50)
		}
		/////////////////////////////////
		pausescie = function(){
			for(i=1; i<=8; i++){
				if(phase == i){
					eval("fx"+i+".pause()");
					$('sciurex').setStyle('visibility', 'hidden');
					$('lame').removeClass('lameScie').addClass('lameStop');
					return;
				}
			}
		}
		/////////////////////////////////
		reprisesciage = function(){
			for(i=1; i<=8; i++){
				if(phase == i){
					eval("fx"+i+".resume()");
					if(i == 2 || i == 6) $('sciurex').setStyle('visibility', 'visible');
					$('lame').removeClass('lameStop').addClass('lameScie');
					return;
				}
			}
		}
		/////////////////////////////////
		var testrecord = function(){
			if(nbrplanches > var_reccord){
				$('recordbattu').setStyle('visibility', 'visible');
				$('recordbattu').addEvent('click', function(){
					new Request.HTML({
						url: 'sortie.php?planches='+nbrplanches,	
						method: 'get',
						onSuccess: function(html) {
							$('xpage').set('text', '');	
							$('xpage').adopt(html);
							new Fx.Scroll(document.body, {offset: {'x': 0,'y': 0}}).toTop();
						}
					}).send();
				});
			}
		}
		/////////////////////////////////


	///////////////////////////////////////////////////////////////////
	});

