var ie4 = (document.all && !document.getElementById);
var ie5 = (document.all && document.getElementById);
var ns6 = (!document.all && document.getElementById);
var t_min=t_max=0;		// animations init
var roule=false;		// velo arrete
var vit_courante=1;		// vitesse minimum
var roue_libre=false;	// velo arrete
var position_selle=0;	// selle en haut
var transparence=1;	// transparence textes nulle
var menu=false;		// menu fermé
var intro_lancee=false;		// intro non lancée

var chrono_present;



function element(id)
{
	if(ie4)	// Explorer 4
		return document.all[id];
	else	// Explorer 5+ Netscape 6+ and Mozilla and Firefox
		return document.getElementById(id);
}

function initTurnTool()
{
	var tntInstalled = isTurnToolInstalled();
	if (tntInstalled==false)
	{
		element('InstallTag').innerHTML = '<CENTER><INPUT TYPE=button VALUE="Install TurnTool Viewer" onClick="installTurnTool();"></CENTER>';
		checkRefresh();
	}
	else
	{
		if (!(ie4||ie5))
		{
			element('TurnTool').innerHTML = '<embed id="TNTCtrl" width="640" height="480" src="vtt_scott_chaine_suite_animations_test_reactor.TNT" transparent="1" ctrl_color="#FFFFFF" pluginspage="http://www.turntool.com/download/" type="application/tntfile"></embed>';
		}
	}	
}

function isTurnToolInstalled()
{
	var tntInstalled = false;
	if (ie4||ie5)
	{
		try
		{
			var xObj = new ActiveXObject("TNT.TNTCtrl");
			if (xObj)
			{
				tntInstalled = true;
			}
		}
		catch (e)
		{
		}
	}
	else
	{
		if(navigator.plugins.namedItem("TurnTool XPCOM Plugin"))
		{
			tntInstalled = true;
		}
	}
	return tntInstalled;
}

function installTurnTool() 
{
	if (ie4||ie5)
	{
		window.location.href = "http://www.turntool.com/ViewerInstall.exe";
	}
	else
	{
		var xpi = {'TurnTool Viewer Installation':'http://www.turntool.com/ViewerInstall.xpi'};
		InstallTrigger.install(xpi,installFinish);
	}
}

function installFinish(url, result)
{
	window.location.href = window.location;
}

var checkCounter = 0;
function checkRefresh()
{
	var tntInstalled = isTurnToolInstalled();
	if(tntInstalled==false)
	{
		checkCounter++;
		if (checkCounter>20)
		{
			checkCounter=0;
			installTurnTool();
		}
		setTimeout('checkRefresh()',500);
	}
	else
	{
		window.location.href = window.location;
	}
}

function TNTDoCommand(string)
{
	var control = element("TNTCtrl");
	if(control && control.ready)
		return control.TNTDoCommand(string);
	return "";
}

function doCommand()
{
	var retval = TNTDoCommand( element("doCommandEdit").value );
	if(retval)
		element("returnval").innerHTML = 'Return Value = "' + retval + '"';
	else
		element("returnval").innerHTML = "";
}

function onDoCommandKeypress()
{
	if(window.event.keyCode==13) // if return key was pressed
		doCommand();
}

function OnReady()
{
	TNTDoCommand('SceneGraph.Bitmap("texte_intro.png").Load("textures/texte_intro.png")');
	
	TNTDoCommand('SceneGraph.Objects("omni07").SetEnable(false)');
	TNTDoCommand('SceneGraph.Objects("omni08").SetEnable(false)');
	
	TNTDoCommand('SceneGraph.Objects("plan_3dv03").SetEnable(false)');
	
	TNTDoCommand('SceneGraph.Objects("plan_3dv_present03").SetEnable(false)');
	
	TNTDoCommand('SceneGraph.Objects("plan_dialogue_texte03").SetEnable(false)');
	
	
	TNTDoCommand('SceneGraph.Objects("plan_3dv02").SetEnable(false)');
	
	TNTDoCommand('SceneGraph.Objects("plan_3dv_present02").SetEnable(false)');
	
	TNTDoCommand('SceneGraph.Objects("plan_dialogue_texte02").SetEnable(false)');



	element("TNTCtrl").focus();
	// load textures marked as external with their default textures
	var texcnt = 0;
	texcnt = TNTDoCommand('SceneGraph.GetBitmapCount()');
	var bExternal = 64;
	var bHasAlpha = 32;
	for( var i=0; i<texcnt; i++ )
	{
		var props = 0;
		props = TNTDoCommand('SceneGraph.Bitmap(' + i + ').GetProperties()');
		if(props & bExternal)
		{
			var name = TNTDoCommand('SceneGraph.Bitmap(' + i + ').GetName()');
			if(props & bHasAlpha)
			{
				name += '.png'; // alpha textures are exported as png
			}
			else
			{
				name += '.jpg'; // non-alpha textures are exported as jpg
			}
			TNTDoCommand('SceneGraph.Bitmap(' + i + ').Load("' + name + '")');
		}
	}
	window.status = "Turnspad By 3DVisit";	
	anim_texte();
		
}



function presentation()
{
	if(menu)			// inversé car test réalisé dans le onclick
	{
	
		if(!intro_lancee)
		{


			position_pedalier=TNTDoCommand('Objects(a_pedalier).GetFrame()');
			TNTDoCommand('Objects(a_pedalier*).PlayAnimation('+position_pedalier+',0,false)');	//repositionnement pédalier
	
			
			if (roule) frein('*');
		
			menu=true;
			
			// active la future camera utilisée
			
				
			TNTDoCommand('SceneGraph.Objects("omni07").SetEnable(true)');
			
			TNTDoCommand('SceneGraph.Objects("plan_3dv02").SetEnable(true)');
			
			TNTDoCommand('SceneGraph.Objects("plan_3dv_present02").SetEnable(true)');
			
			TNTDoCommand('SceneGraph.Objects("plan_dialogue_texte02").SetEnable(true)');
			
			
			
		
			TNTDoCommand('Objects(Camera07).PlayAnimation(100,0,true,15)');	
			TNTDoCommand('CameraCtrl.SetCurrent("Camera07")');					//tourne autour du vtt
			
			
			//desactive les plans caméra 01 et la lumière associée
			
			TNTDoCommand('SceneGraph.Objects("plan_3dv").SetEnable(false)');
			
			TNTDoCommand('SceneGraph.Objects("plan_3dv_present").SetEnable(false)');
			
			TNTDoCommand('SceneGraph.Objects("plan_dialogue_texte").SetEnable(false)');
			
			TNTDoCommand('SceneGraph.Objects("omni02").SetEnable(false)');
			
			
			chrono_present=setTimeout('presentation_1()',7000);
			
		}
	}
	
	else
	{
		
		TNTDoCommand('SceneGraph.Objects("omni02").SetEnable(true)');
		TNTDoCommand('SceneGraph.Objects("omni07").SetEnable(false)');
		TNTDoCommand('SceneGraph.Objects("omni08").SetEnable(false)');
		
		
		TNTDoCommand('SceneGraph.Objects("plan_3dv").SetEnable(true)');
		
		TNTDoCommand('SceneGraph.Objects("plan_3dv_present").SetEnable(true)');
		
		TNTDoCommand('SceneGraph.Objects("plan_dialogue_texte").SetEnable(true)');
		
		
		
		TNTDoCommand('SceneGraph.Objects("plan_3dv03").SetEnable(false)');
		
		TNTDoCommand('SceneGraph.Objects("plan_3dv_present03").SetEnable(false)');
		
		TNTDoCommand('SceneGraph.Objects("plan_dialogue_texte03").SetEnable(false)');
		
		
		TNTDoCommand('SceneGraph.Objects("plan_3dv02").SetEnable(false)');
		
		TNTDoCommand('SceneGraph.Objects("plan_3dv_present02").SetEnable(false)');
		
		TNTDoCommand('SceneGraph.Objects("plan_dialogue_texte02").SetEnable(false)');
	
	
		TNTDoCommand('CameraCtrl.Match("Camera01",2000)');
		
		setTimeout('fin_presentation()',2000);
		
		
	
	}

}

function fin_presentation()
{

	TNTDoCommand('CameraCtrl.SetCurrent("Camera01")');
	TNTDoCommand('SceneGraph.Bitmap("texte_intro.png").Load("textures/texte_intro.png")');
	
	
	
	frein_anim('*');		 // réinitialisation des animations
	
	retour_fourche=TNTDoCommand('SceneGraph.Objects("a_fourche").GetFrame()');
		
	if (retour_fourche>21)	tourner_droite();
	else if ((retour_fourche<21)&&(retour_fourche>0)) tourner_gauche();
	
	
	intro();

}


function presentation_1()
{


	TNTDoCommand('SceneGraph.Bitmap("texte_intro.png").Load("textures/texte_1.png")');
	TNTDoCommand('CameraCtrl.Match("Camera08",2000)');			// plan pedalier
		
	chrono_present=setTimeout('presentation_2()',3500);


}

function presentation_2()
{

	// desactive ancienne camera et lumiere associée

	TNTDoCommand('SceneGraph.Objects("omni07").SetEnable(false)');
	
	TNTDoCommand('SceneGraph.Objects("plan_3dv02").SetEnable(false)');
	TNTDoCommand('SceneGraph.Objects("plan_3dv_present02").SetEnable(false)');
	TNTDoCommand('SceneGraph.Objects("plan_dialogue_texte02").SetEnable(false)');
	
	//active camera et lumiere associee
	
	TNTDoCommand('SceneGraph.Objects("omni08").SetEnable(true)');
	
	TNTDoCommand('SceneGraph.Objects("plan_3dv03").SetEnable(true)');
	TNTDoCommand('SceneGraph.Objects("plan_3dv_present03").SetEnable(true)');
	TNTDoCommand('SceneGraph.Objects("plan_dialogue_texte03").SetEnable(true)');
	
	TNTDoCommand('CameraCtrl.SetCurrent("Camera08")');			// camera pedalier
	
	TNTDoCommand('Objects(Camera08).PlayAnimation(0,30,false)');		// anim vers cassette
		
	chrono_present=setTimeout('presentation_3()',1500);


}

function presentation_3()
{

	TNTDoCommand('Objects(Camera08).PlayAnimation(30,50,,10)');		// anim vers bas dérailleur
		
	chrono_present=setTimeout('presentation_4()',1200);


}

function presentation_4()
{

	TNTDoCommand('Objects(Camera08).PlayAnimation(50,80,,20)');		// anim retour pédalier
		
	chrono_present=setTimeout('presentation_5()',2500);


}


function presentation_5()
{

	
	TNTDoCommand('SceneGraph.Bitmap("texte_intro.png").Load("textures/texte_2.png")');		// texte vtt roule
	TNTDoCommand('CameraCtrl.Match("Camera09",1000)');					// caméra pédale
	
	
	chrono_present=setTimeout('presentation_6()',2500);


}


function presentation_6()
{

	pedalier();					// depart pédallage	
	
	
	chrono_present=chrono_present=setTimeout('presentation_7()',1000);


}


function presentation_7()
{
	
	// active camera qui tourne et lumiere associee
	
	TNTDoCommand('SceneGraph.Objects("omni07").SetEnable(true)');

	TNTDoCommand('SceneGraph.Objects("plan_3dv02").SetEnable(true)');
	TNTDoCommand('SceneGraph.Objects("plan_3dv_present02").SetEnable(true)');
	TNTDoCommand('SceneGraph.Objects("plan_dialogue_texte02").SetEnable(true)');
	
	// desactive camera precedante et lumiere
	
	TNTDoCommand('SceneGraph.Objects("omni08").SetEnable(false)');
	
	TNTDoCommand('SceneGraph.Objects("plan_3dv03").SetEnable(false)');
	TNTDoCommand('SceneGraph.Objects("plan_3dv_present03").SetEnable(false)');
	TNTDoCommand('SceneGraph.Objects("plan_dialogue_texte03").SetEnable(false)');
	
	
	
	TNTDoCommand('CameraCtrl.SetCurrent("Camera07")');
	
	TNTDoCommand('Objects(Camera07).PlayAnimation(100,0,true,15)');		// retour caméra rotation
	
	
	chrono_present=setTimeout('presentation_8()',4000);


}


function presentation_8()
{

	TNTDoCommand('SceneGraph.Bitmap("texte_intro.png").Load("textures/texte_3.png")');		// texte derailleur

	TNTDoCommand('CameraCtrl.Match("Camera10",1000)');						// camera derailleur
		
	chrono_present=setTimeout('presentation_9b()',2000);


}

function presentation_9b()
{
	TNTDoCommand('Objects(poignee_derailleur_d).PlayAnimation(0,5,false)');		// tourner poignée dérailleur
	chrono_present=setTimeout('presentation_9()',500);


}

function presentation_9()
{
	

	monter_vitesse_present();				// passage des 9 vitesses
	
	chrono_present=setTimeout('presentation_10()',4000);


}



function presentation_10()
{
	TNTDoCommand('Objects(poignee_derailleur_d).PlayAnimation(5,0,false)');			// retour à 0 de la poignée de derailleur
	
	vit_courante=2;							// retour à 0 de la chaine
		
	descendre_vit('raz');
	

	TNTDoCommand('SceneGraph.Bitmap("texte_intro.png").Load("textures/texte_4.png")');		// texte freins

	TNTDoCommand('CameraCtrl.Match("Camera06",1000)');				// camera des freins
	
	chrono_present=setTimeout('presentation_11()',2500);			


}


function presentation_11()
{

	frein('*');				// actionnement des freins
	
	chrono_present=setTimeout('presentation_12()',2500);

}


function presentation_12()
{

	TNTDoCommand('CameraCtrl.Match("Camera03",1000)');			// retour camera eloignée
	
	chrono_present=setTimeout('presentation_13()',2000);


}


function presentation_13()
{

	TNTDoCommand('SceneGraph.Bitmap("texte_intro.png").Load("textures/texte_5.png")');		// texte ceintre

	TNTDoCommand('CameraCtrl.Match("Camera11",1000)');		// camera ceintre
	
	
	
	chrono_present=setTimeout('presentation_14()',3000);


}


function presentation_14()
{

	tourner_droite();			// tourner la roue à droite
	
	
	
	chrono_present=setTimeout('presentation_15()',1500);


}


function presentation_15()
{

	tourner_gauche();		// tourner roue gauche
	
	
	
	chrono_present=setTimeout('presentation_16()',1500);


}

function presentation_16()
{

	tourner_gauche();		// tourner_roue_gauche
	
	
	
	chrono_present=setTimeout('presentation_17()',1500);


}

function presentation_17()
{

	tourner_droite();
	
	TNTDoCommand('SceneGraph.Bitmap("texte_intro.png").Load("textures/texte_6.png")');		// texte selle
	
	TNTDoCommand('CameraCtrl.Match("Camera05",1000)');
	
	
	
	chrono_present=setTimeout('presentation_18()',2500);


}


function presentation_18()
{

	
	
	deplacement_selle();
	
	
	
	chrono_present=setTimeout('presentation_19()',2000);


}


function presentation_19()
{

	if (position_selle!=0) deplacement_selle();
	
	
	TNTDoCommand('SceneGraph.Bitmap("texte_intro.png").Load("textures/texte_7.png")');		// texte final
	
	TNTDoCommand('CameraCtrl.Match("Camera12",50)');
	
	
	
	chrono_present=setTimeout('presentation_20()',2000);


}

function presentation_20()
{

	
	TNTDoCommand('CameraCtrl.Match("Camera13",50)');
	
	
	
	chrono_present=setTimeout('presentation_21()',2000);


}

function presentation_21()
{

	
	TNTDoCommand('CameraCtrl.Match("Camera14",50)');
	
	
	
	chrono_present=setTimeout('presentation_22()',2000);


}


function presentation_22()
{

	
	TNTDoCommand('CameraCtrl.Match("Camera15",50)');
	
	
	
	chrono_present=setTimeout('presentation_23()',2000);


}


function presentation_23()
{

	
	TNTDoCommand('CameraCtrl.Match("Camera16",50)');
	
	
	
	chrono_present=setTimeout('presentation_24()',2000);


}


function presentation_24()
{

	
	TNTDoCommand('CameraCtrl.Match("Camera17",50)');
	
	chrono_present=setTimeout('stop_present()',4000);	

}

function stop_present()
{

	menu=false;
				
	ouvre_menu();
	presentation();
}


function monter_vitesse_present()
{
	if (vit_courante<9)
	{
		monter_vitesse();
		setTimeout('monter_vitesse_present()',250);
	}
		
}

function efface_turnspad()
{
	TNTDoCommand('Objects(plan_turnspad).PlayAnimation(30,0,false)');
	
}


function anim_texte()
{
	TNTDoCommand('Objects(plan_3dv_present).PlayAnimation(0,20,true,,3)');
}


function intro()
{


	intro_lancee=true;		// bloquer les autres anims
	
	TNTDoCommand('Objects(plan_3dv_present).PlayAnimation(0,35,false)');
	TNTDoCommand('SceneGraph.Objects(plan_3dv_present).SetEnable(false)');
	
	TNTDoCommand('Objects(plan_turnspad).PlayAnimation(0,30,false)');
	
	
	
	TNTDoCommand('CameraCtrl.Match("Camera04",1200)');
	
	TNTDoCommand('Objects(Camera01).PlayAnimation(0,100,false)');
	TNTDoCommand('Objects(a_roue_av*).PlayAnimation(0,4,true)');
	TNTDoCommand('Objects(a_cassette*).PlayAnimation(0,3,true)');
	TNTDoCommand('Objects(a_roue_ar*).PlayAnimation(0,3,true)');		// passer en roue libre
		
	element('interface').TGotoFrame('_level0.chaine',2);			// son flash
		
	roule=true;
	roue_libre=true;
	
	
	setTimeout('intro_2()',700);
	
	
}

function intro_2()
{
	TNTDoCommand('CameraCtrl.Match("Camera03",3500)');		//zoom
	
	tourner_gauche();
	setTimeout('intro_3()',2000);
	
}

function intro_3()
{
	
	tourner_droite();
	setTimeout('intro_4()',1500);
	
	
	
}

function intro_4()
{
	
	TNTDoCommand('SceneGraph.Objects(a_cassette*).StopAnimation()');
	TNTDoCommand('SceneGraph.Objects(a_roue_av*).StopAnimation()');
	TNTDoCommand('SceneGraph.Objects(a_roue_ar*).StopAnimation()');
		
	element('interface').TGotoFrame('_level0.frein',3);
	roule=false;
	roue_libre=false;
	
	TNTDoCommand('Objects(plan_turnspad).PlayAnimation(30,0,false)');
	
	intro_lancee=false;
	
}



function deplacement_selle()
{
	test=TNTDoCommand('Objects(a_tige_selle).GetFrame()');
	TNTDoCommand('CameraCtrl.Match("Camera05",250)');		
	
	if (test>15)
	{
		t_min=test;
		t_max=0;
	}
	else
	{
		t_min=test;
		t_max=30;
	}

		TNTDoCommand('Objects(a_tige_selle*).PlayAnimation('+t_min+','+t_max+',false)');
		position_selle=t_max;			

}

function monter_selle()
{
			
	if (position_selle>=10)
	{
		TNTDoCommand('CameraCtrl.Match("Camera05",250)');
		TNTDoCommand('Objects(a_tige_selle*).PlayAnimation('+position_selle+','+(position_selle-10)+',false)');
		position_selle-=10;
		
	}
}

function descendre_selle()
{
	
	if (position_selle<=20)
	{
		TNTDoCommand('CameraCtrl.Match("Camera05",250)');
		TNTDoCommand('Objects(a_tige_selle*).PlayAnimation('+position_selle+','+(position_selle+10)+',false)');
		position_selle+=10;
	}
}

function pedalier()
{

	if (!roule)
	{

		t_min=4*(vit_courante-1);
		t_max=t_min+3;
	
		TNTDoCommand('Objects(a_pedalier*).PlayAnimation(0,40,true)');
		TNTDoCommand('Objects(a_cassette*).PlayAnimation(0,3,true)');
		TNTDoCommand('Objects(a_roue_ar*).PlayAnimation(0,3,true)');
		TNTDoCommand('Objects(a_der*).PlayAnimation('+t_min+','+t_max+',true)');
		TNTDoCommand('Objects(a_roue_av*).PlayAnimation(0,3,true)');
		TNTDoCommand('Objects(a_maillon*).PlayAnimation('+t_min+','+t_max+',true)');
		
		element('interface').TGotoFrame('_level0.chaine',1);
		
		roule=true;
		
	}
	else		
	{
		if(!roue_libre)
		{
			TNTDoCommand('SceneGraph.Objects(a_pedalier*).StopAnimation()');
			TNTDoCommand('SceneGraph.Objects(a_maillon*).StopAnimation()');
			TNTDoCommand('SceneGraph.Objects(a_der*).StopAnimation()');
			TNTDoCommand('Objects(a_cassette*).StopAnimation()');
			
			
			roue_libre=true;
				
			element('interface').TGotoFrame('_level0.chaine',2);
		}
		else
		{
			TNTDoCommand('Objects(a_pedalier*).PlayAnimation(0,40,true)');
			TNTDoCommand('Objects(a_cassette*).PlayAnimation(0,3,true)');
			t_min=4*(vit_courante-1);
			t_max=t_min+3;
			TNTDoCommand('Objects(a_maillon*).PlayAnimation('+t_min+','+t_max+',true)');
			TNTDoCommand('Objects(a_der*).PlayAnimation('+t_min+','+t_max+',true)');
			roue_libre=false;
			
			element('interface').TGotoFrame('_level0.chaine',1);
			
		}		
			
			
			
	}
}


function frein(cote)
{
	TNTDoCommand('CameraCtrl.Match("Camera06",250)');
	var chaine_envoi="frein_anim("+cote+")";
	
	
	setTimeout("frein_anim('"+cote+"')",800);
			
		
}



function frein_anim(cote)
{

	TNTDoCommand('Objects(a_levier_frein_'+cote+').PlayAnimation(0,9,false)');
	
	
		if (roule)
		{
			TNTDoCommand('SceneGraph.Objects(a_pedalier*).StopAnimation()');
			TNTDoCommand('SceneGraph.Objects(a_cassette*).StopAnimation()');
			TNTDoCommand('SceneGraph.Objects(a_roue_av*).StopAnimation()');
			TNTDoCommand('SceneGraph.Objects(a_maillon*).StopAnimation()');
			TNTDoCommand('SceneGraph.Objects(a_roue_ar*).StopAnimation()');
			TNTDoCommand('SceneGraph.Objects(a_der*).StopAnimation()');
			
			if(!roue_libre) 
			{
				element('interface').TGotoFrame('_level0.frein',2);			
			}
			else 
			{
				element('interface').TGotoFrame('_level0.frein',3);
				roue_libre=false;
			}
			roule=false;
			
		
		}
		else element('interface').TGotoFrame('_level0.frein',1);
}


function monter_vitesse()
{

	if (roule)
	{


		if (vit_courante<9)
		{
			
			TNTDoCommand('CameraCtrl.Match("Camera02",250)');
			setTimeout('monter_vit()',250);
			
			
		}


	}
}

function monter_vit()
{
	t_min=4*vit_courante;
	t_max=t_min+3;
	TNTDoCommand('Objects(a_der*).PlayAnimation('+t_min+','+t_max+',true)');
	TNTDoCommand('Objects(a_maillon*).PlayAnimation('+t_min+','+t_max+',true)');
	element('interface').TGotoFrame('_level0.vitesse',1);
	vit_courante++;

}

function descendre_vitesse()
{

	if (roule)
	{


		if (vit_courante>1)
		{
			TNTDoCommand('CameraCtrl.Match("Camera02",250)');
			setTimeout('descendre_vit()',250);
			
			
		}
		
	}
}



function descendre_vit(etat)
{

	t_min=4*(vit_courante-2);
	t_max=t_min+3;
	TNTDoCommand('Objects(a_der*).PlayAnimation('+t_min+','+t_max+',true)');
	TNTDoCommand('Objects(a_maillon*).PlayAnimation('+t_min+','+t_max+',true)');
	
	if(etat!='raz') element('interface').TGotoFrame('_level0.vitesse',2);
	
	vit_courante--;
}





function tourner_gauche()
{
	var anim=true;			//test utilisé pour controler si on est en bout de course
	
	test=TNTDoCommand('Objects(a_fourche).GetFrame()');
			
		if ((test!=0)&&(test!=21))
		{
			if (test<21)
			{	
				t_min=20;
				t_max=0;
			}	
			else
			{
				anim=false;
			}	
			
						
		}
		else
			if (test<41)
			{
				t_min=21;
				t_max=41;
			}
		
		if (anim)
		{
					
			TNTDoCommand('Objects(a_fourche*).PlayAnimation('+t_min+','+t_max+',false)');
			TNTDoCommand('Objects(a_gaine*).PlayAnimation('+t_min+','+t_max+',false)');
			TNTDoCommand('Objects(a_ombre).PlayAnimation('+t_min+','+t_max+',false)');
			TNTDoCommand('Objects(a_axe*).PlayAnimation('+t_min+','+t_max+',false)');
		}
	
}


function tourner_droite()
{

	var anim=true;			//test utilisé pour controler si on est en bout de course

	test=TNTDoCommand('Objects(a_fourche).GetFrame()');
		
	if ((test!=0)&&(test!=21))
	{
		if (test>21)
		{	
			t_min=41;
			t_max=21;
								
		}
		else
		{
			anim=false;										
		}
					
	}
	else
		
		{
			t_min=0;
			t_max=20;
			
		}
				
	
	if (anim) 
	{
		TNTDoCommand('Objects(a_fourche).PlayAnimation('+t_min+','+t_max+',false)');
		TNTDoCommand('Objects(a_gaine*).PlayAnimation('+t_min+','+t_max+',false)');
		TNTDoCommand('Objects(a_ombre).PlayAnimation('+t_min+','+t_max+',false)');
		TNTDoCommand('Objects(a_axe*).PlayAnimation('+t_min+','+t_max+',false)');
		
	}
}


function monter_transparence()
{

	if (transparence<1) 
	{
		transparence+=0.1;
		TNTDoCommand('SceneGraph.Objects("plan_dialogue*").SetTransparency('+transparence+')');
	}


}

function descendre_transparence()
{

	if (transparence>0.4) 
	{
		transparence-=0.1;
		TNTDoCommand('SceneGraph.Objects("plan_dialogue*").SetTransparency('+transparence+')');
	}


}



function ouvre_menu()

{

	if (menu)			// inversé car test sur menu dans le onclick
	{
		TNTDoCommand('SceneGraph.Objects("plan_dialogue*").PlayAnimation(0,20)');
		menu=true;
	}
	else
	{
		TNTDoCommand('SceneGraph.Objects("plan_dialogue*").PlayAnimation(20,0)');
		menu=false;
	
	}

}


function OnClick( obj )
{
		
	var anim=true;
	
	switch(obj)
	{
		case "a_tige_selle" :
				
			deplacement_selle();
								
		break;
		
		case "selle" :
				
			deplacement_selle();
								
		break;
		
		case "grip_g":
		
			tourner_gauche();
						
		break;
		
		case "grip_d":
		
			tourner_droite();			
			
		break;
			
		case "a_pedalier":
			
			pedalier();
			
		break;
			
		case "a_levier_frein_d" :
			
			frein('d');
		break;
			
		case "a_levier_frein_g" :
			
			frein('g');
			
		break;
			
		case "poignee_derailleur_d" :
	
			monter_vitesse();
			
		break;	
				
		
		case "plan_3dv" :
			
			window.open("http://3dvisit.free.fr/","_blank");
			
		break;
		
		case "plan_3dv_present" :
		
			intro();
		break;
		
		case "plan_bouton_menu" :
		
			if(!menu) 
			{
				menu=true;
				presentation();
				
			}
			else 
			{
					clearTimeout(chrono_present);
				menu=false;
					presentation();
				
			}
			
			ouvre_menu();
			
		
			
		break;
		case "plan_bouton_menu02" :
		
		
			if(!menu) 
			{
				menu=true;
				presentation();
			
			}
			else 
			{
					clearTimeout(chrono_present);
				menu=false;
					presentation();
			}
			
			ouvre_menu();
			
		
			
		break;
		case "plan_bouton_menu03" :
		
		
			if(!menu) 
			{
				menu=true;
				presentation();
				
			}
			else 
			{
					clearTimeout(chrono_present);
				menu=false;
					presentation();
			}
			
			ouvre_menu();
			
			
		break;
		
		case "plan_bouton_transpm" :
		
			descendre_transparence();
		
			
		break;
		
			case "plan_bouton_transpm02" :
		
			descendre_transparence();
		
			
		break;
			case "plan_bouton_transpm03" :
		
			descendre_transparence();
		
			
		break;
		
		case "plan_bouton_transpp" :
		
			monter_transparence();
		
			
		break;
		case "plan_bouton_transpp02" :
		
			monter_transparence();
		
			
		break;
		
		case "plan_bouton_transpp03" :
		
			monter_transparence();
		
			
		break;
		
		
	
	
	}		
	
	
}

function OnMouseEnter( obj )
{
	TNTDoCommand('Objects(' + obj + ').SetDiffuseColor(#FF0000)');
	
}

function OnMouseExit( obj )
{
	TNTDoCommand('Objects(' + obj + ').ResetMaterial()');

}

function OnZoneEnter( zone, physics )
{
	element("TNTCtrl").focus();
	
}

function OnZoneExit( zone, physics )
{
	element("TNTCtrl").focus();

}

function OnKeyPress( keyCode, ascii )
{

}

function OnKeyRelease( keyCode, ascii )
{

}

function Restart()
{
	TNTDoCommand('SceneGraph.Physics.Reset()');
	TNTDoCommand('Objects(*).StopAnimation()');
	TNTDoCommand('Objects(*).SetFrame(0)');
	cameraName = TNTDoCommand('SceneGraph.Camera(0).GetName()');
	TNTDoCommand('CameraCtrl.SetCurrent("'+ cameraName+'")');
}


