// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// >>> File: 			functions.js
// >>> Version: 		1.6b
// >>> Original Author: Xi Cheng 
// >>> Description:		This file contains the logic for the Life of Iron Game.
// >>>
// >>> Modified By: 	Geoff Coope (geoff.coope@true2life.co.uk) 
// >>> Last Modified: 	10th August 2009
// >>>
// >>> Version history:	1.0
// >>> 					Original file creation for Life of Iron game.
// >>> Version history:	1.1 (4th Dec 2007)
// >>>					Added cookie based saving and loading when a level is completed.
// >>> Version history: 1.2 (4th Dec 2007) 
// >>> 					Changed paths from steelworks_v5/ to loi/ 
// >>> Version history	1.3 - 1.4 (4th Dec 2007)
// >>>      			UpdatePanel() was missing in previous version, added it back in.
// >>>					Animations were not starting in certain zones.
// >>> Version history	1.5 - 10th July 2009
// >>>					Started Simplified Chinese language support.
// >>> Version history	1.6 - 10th August 2009
// >>>                  Test Phase.
// >>> Version history	1.6b - 13th August 2009
// >>>					Fixed missing gfx
// >>>
// >>> Copyright(c) 2007, True2Life Ltd. all rights reserved. (http://www.true2life.co.uk)
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


// >>> Global Vars
var CurrentT2L = "";			// Holds the currently loaded 3D file
var TTOnReady = 0;				// Used to handle OnReady_Listener() event 
var TTZoneEnter = 0;			 
var IntroLoopMode = 0;         	
var IntroLoopTimer;
var FreshStart = 1;
var NextArea = 1;
var steelplanttimer2;

var IntroTimer1;
var IntroTimer2;
var IntroTimer3;
var IntroTimer3b;
var IntroTimer4;
var IntroTimer5;
var IntroTimerx;
var IntroTimer6;
var IntroTimer7;

var camera_name = "";

var AnimationTimer1;
var AnimationTimer2;
var AnimationTimer3;
var AnimationTimer4;
var AnimationTimer5;
var AnimationTimer6;
var AnimationTimer7;
var AnimationTimer8;
var AnimationTimer9;
var AnimationTimer10;
var AnimationTimer11;
var AnimationTimer12;
var AnimationTimer13;

var srcPosX = 0.0;
var srcPosY = 0.0;
var srcPosZ = 0.0;
var srcRotZ = 0.0;

var level;				// 2 = hard
var Zone_Name = "";

var infornum = 0; // The amount of items found within a zone
var informax = 5; // how many items you need to collect before gate key appears.
var spann ;
var spannzone ;
var popup ;
var door;
var wall;
var key;
var keyzone;
var num;

// flash map related vars
var Frame=0; 
var MapDisplacementVar = 0;
var MapDisplacementVar_phys = 0;

var MapTimer;
var srcPosX;
var srcPosY;
var srcRotZ;
var srcRotZ1;
var srcPosXC;
var srcPosYC;
var srcRotZC;
var srcRotZ1C;

var desPosY;
var desPosX;
var desPosYC;
var desPosXC;

var MapYConstant = 0.032016908258984915055090223935334;
var MapXConstant = 0.029573934837092731829573934837093;

var IntMapYConstant = 0.61;
var IntMapXConstant = 0.59;
var IntMapObject = "";
var IntMapRotObject = "";

var MillMapYConstant = 0.011267605633802816901408450704225;
var MillMapXConstant = 0.011256931608133086876155268022181;
var MillMapObject = "";
var MillMapRotObject = "";

var gameLoaded = false;          	// Check to see if a game is loaded, if it is then dont offer to load again in OnReady event.
var levelDone = 0;  				// The level or zone that the user has completed (relates to graphics shown in top panel)
var items = 0;      				// The amount of items collected in the zone
var itemsArray = "";          		// Store items collected, this is not used anymore.
var timeOfLastLoad =new Date();		// Date var used to stop saving a game (caused by zone event) if loading is in progress.
var loadUpStairs = false;			// When in Interior zone the save point is upstairs, check to see if it should be triggered.
var loading = false;               // Used as a secondary catch to stop Saving a game if a load is in progress
var LeavingZone5 = false;			// Used so that the OnReady_Listener can move the user to zone 5 when exiting zone 5 building.
var LeavingZone6 = false;   		// Used so that the OnReady_Listener can move the user to zone 7 when exiting zone 6 building.




// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// >>> Save camera position to cookie when user enters or leaves a zone keysz object >>>
// >>> This can include: Items, Gates, Doors, Stairs, Lifts                          >>>
// >>> Some areas do not have zone keys so must check differently           		 >>>
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
function Save(zone)
{
// If in the middle of loading a game, dont try and save if landing on a zone key.
var curTime = new Date();
var elapsed = (curTime.getSeconds() - timeOfLastLoad.getSeconds());

if(!elapsed ==0) {
 var combined;
 var seperator = '|';
 var PosX;
 var PosY;
 var PosZ;
 var RotZ;
 var CamX;
 var curCamera;
 var curSphereIdx;
 var curSphere;
 var loading = false; // used to stop the OnReady Listener from performing a GotoArea() if we are loading a saved position.
 
 
// Get name of current Camera
   curCamera = TNTDoCommand('CameraCtrl.GetCurrent()');
// Get name of current physical Sphere
   curSphereIdx = TNTDoCommand('Objects('+curCamera+').GetParentNodeIndex()');	
   curSphere = TNTDoCommand('Object('+curSphereIdx+').GetName()');
// The Zone that the user has completed is stored in 'levelDone' and NextArea is the gate top open.
   levelDone = parseInt( zone.substr(0,2) );
   NextArea = parseInt( levelDone ) + 1;
// Physical Sphere coordinates
   PosX = TNTDoCommand('Objects('+curSphere+').GetPositionLocalX()');
   PosY = TNTDoCommand('Objects('+curSphere+').GetPositionLocalY()');
   PosZ = TNTDoCommand('Objects('+curSphere+').GetPositionLocalZ()');
   RotZ = TNTDoCommand('Objects('+curSphere+').GetRotationLocalZ()');
// Camera's Y coordinate
   CamX = TNTDoCommand('Objects('+curCamera+').GetRotationLocalX()');
// Combine all vars into single string for cookie save.
    combined =  curCamera + seperator;    	// 0
	combined += curSphere + seperator;		// 1
	combined += levelDone + seperator;		// 2
	combined += informax + seperator;	    // 3   // not used
	combined += PosX + seperator;			// 4
	combined += PosY + seperator;			// 5
	combined += PosZ + seperator;			// 6
	combined += RotZ + seperator;			// 7
	combined += CamX + seperator;			// 8
	combined += CurrentT2L + seperator; 	// 9
	combined += spannzone + seperator;		// 10
	combined += 'empty' + seperator	 	    // 11  // not used
    combined += zone + seperator;           // 12
    combined += NextArea;			        // 13
	createCookie('LoISavedGame', combined, 360);
} // if(!loadingGame)
} // func



// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// >>> loadLastGame()
// >>> This function reads a save cookie and reloads the correct zone, sets up animations to play,
// >>> unlocks gates, closes gates, hides collected items and their zones, updates flash map, updates panel, sets GUI
// >>> and sets up vars so that the game can continue from a new point.
// >>> The function also relies on the OnReady and OnReady_Listener events to process information after a load.
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
function loadLastGame()
{
 TTOnReady =0;  							// dont allow OnReady_listener() to kick in yet
 gameLoaded = true; 						// used to test for load game dialog when refreshing tnt's         
 updatepanel('01');	
 var savedGame = loadCookie('LoISavedGame');  
 FreshStart = 0;
 ClearOutsideAnimations();
 LoopingAnimations();


if (undefined != savedGame)  				// Cookie exists.
 {
    var answer = confirm ("Previous saved game found. Click OK to load your progress or Cancel to start from the beginning.");
        if (answer) 
		   {
		     loading = true; 				// Used to stop the onReady_Listener from performing a GotoArea()
             var savedGameArray = savedGame.split('|');
			 NextArea = parseInt(savedGameArray[13]);	 

             // Hide already collected items and disable the item zones
			 for(j = 1; j < NextArea; j++){  
			   for(i = 1; i <= 5; i++){ 
				   itemObj = '0' + j + '0' + i;   
				   hideit( (itemObj+'spann') );
				   disable( (itemObj+'infor') );
                 }
			 }

              infornum = informax; 											// Always assume max items collected in save as it saves when you complete a zone
              var characterImage = parseInt(savedGameArray[2]);
              spannzone = savedGameArray[10];
              Zone_Name = savedGameArray[12];	   
			  
	          timeOfLastLoad = new Date();			  						// add to top and bottom of func in case OnReady fires.
			  
              switch (NextArea) {
				case 2:
                  // Update GUI with loaded data 
                  updatepic('character',characterImage, false);     		// change item to collect picture for next zone
                  updatepic('zones', savedGameArray[2], false);         	// update zone bucket graphic 
   			      updatepic('numbers', informax, false);                	// update items collected
				  updatepanel('02');	
				  LoopingAnimations();
                  // Store Load Time.  Used to avoid multiple saves when camera lands on keyszzone.
			      timeOfLastLoad = new Date();
                  // Move saved Physics Sphere to saved position
				  moveCamera(savedGameArray[0], savedGameArray[1], savedGameArray[4], savedGameArray[5], savedGameArray[6], savedGameArray[7], savedGameArray[8]) 
               if(infornum>informax)  // dont allow more than max items;
			      infornum=informax;
				  break;
				case 3:
                   // Update GUI with loaded data 
                      updatepic('character',characterImage, false);     	// change item to collect picture for next zone
                      updatepic('zones', savedGameArray[2], false);     	// update zone bucket graphic 
   			          updatepic('numbers', informax, false);             	// update items collected			   
					  updatepanel('03');						  
					  LoopingAnimations();
                      // Store Load Time.  Used to avoid multiple saves when camera lands on keyszzone.
					  moveCamera(savedGameArray[0], savedGameArray[1], savedGameArray[4], savedGameArray[5], savedGameArray[6], savedGameArray[7], savedGameArray[8]) 				  
				   break;
				case 4:
                      var characterImage = parseInt(savedGameArray[2]);
                      updatepic('character',characterImage, false);    	
                      updatepic('zones', savedGameArray[2], false);       	
   			          updatepic('numbers', informax, false);              	
					  updatepanel('04');
					  LoopingAnimations();
					  moveCamera(savedGameArray[0], savedGameArray[1], savedGameArray[4], savedGameArray[5], savedGameArray[6], savedGameArray[7], savedGameArray[8]) 					  
				   break;
				case 5: 
                      var characterImage = parseInt(savedGameArray[2]);
                      updatepic('character',characterImage, false);     	
                      updatepic('zones', savedGameArray[2], false);        
   			          updatepic('numbers', informax, false);     
					  updatepanel('05');
					  LoopingAnimations();
					  moveCamera(savedGameArray[0], savedGameArray[1], savedGameArray[4], savedGameArray[5], savedGameArray[6], savedGameArray[7], savedGameArray[8]) 
				   break;
				case 6: 
				   if(savedGameArray[9] == 'steelworks_interior.t2l') {
                       var characterImage = parseInt(savedGameArray[2]);
                       updatepic('character',characterImage, false);    
                       updatepic('zones', savedGameArray[2], false);    
   			           updatepic('numbers', infornum, false);           				  					   
					   moveCamera(savedGameArray[0], savedGameArray[1], savedGameArray[4], savedGameArray[5], savedGameArray[6], savedGameArray[7], savedGameArray[8]) 						  
				   } 
					  
					if( (savedGameArray[9] == 'steelworks.t2l')) { 
                       var characterImage = parseInt(savedGameArray[2]);
                       updatepic('character',characterImage, false);     
                       updatepic('zones', savedGameArray[2], false);     
   			           updatepic('numbers', infornum, false);            
  					   moveCamera(savedGameArray[0], savedGameArray[1], savedGameArray[4], savedGameArray[5], savedGameArray[6], savedGameArray[7], savedGameArray[8]) 
					   // Start animations
					   LoopingAnimations();
					   // Hide all collected objects so far
					   setexterior(5);	
					   // Set the amount of items collected to max
					   infornum = informax;
					   // Trigger key pickup
					   num  = '0501';
					   zone = '0501keysz';
					   door = num.slice(0,2)+'doors';
					   wall = num.slice(0,2)+'walls';
						if(CurrentT2L != 'steelworks.t2l'||(zone != '0501keysz' && zone != '0601keysz'))
							disable('Sphere01');
						var next = num.slice(1,2);
							updatepic('zones', next); 
						if (next == 8 && CurrentT2L == 'steelworks.t2l')
							endmovie();
						if(next == 6 && CurrentT2L == 'steelworks.t2l')
							updatepic('zones', 7);
							next++;
							next = '0'+ next;
							nextdoors = next + 'doors';
							nextwalls = next + 'walls';
							//num++;
							hideit(door);
							hideit(nextdoors);
							disable(wall);
							disable(nextwalls);
							hideit(key);
							disable(zone);  
					}
					
					if (savedGameArray[9] == 'steelworks.t2l' && !savedGameArray[10] == '0504infor') {
                       var characterImage = parseInt(savedGameArray[2]);
                       updatepic('character',characterImage, false);         // change item to collect picture for next zone
                       updatepic('zones', savedGameArray[2], false);         // update zone bucket graphic 
   			           updatepic('numbers', infornum, false);                // update items collected
					   LoopingAnimations();
   					  moveCamera(savedGameArray[0], savedGameArray[1], savedGameArray[4], savedGameArray[5], savedGameArray[6], savedGameArray[7], savedGameArray[8]) 	
					}
				   updatepanel('06');			  
				   break;
				case 7:// This is the second half of steel_making zone (springs), this is handled below
				   updatepanel('07');
				   break;
				case 8:
				   createFlash(158,401,"flash_hotmill.swf","myFlashmap");
				   infornum=0;  // set items to 0
	               hidei('menu');
	               hidei('Processes');
	               hidei('Sponsors');
	               hidei('click_menu');
	               hidei('menu');
	               showi(mapname);              
	               createTurnTool(600,374,"steelworks_hotmill.t2l", "#000000", 0, false);
	               updatepic('character',8, false); 
			       updatepic('zones', 7, false);    
   			       updatepic('numbers', infornum, false);
				   updatepanel('08');
				   break;
				default:
			 }
			 

                // Check to see if save is from zone at top of stairs in steelworks_internal
				if(savedGameArray[9] == 'steelworks_interior.t2l')
				 { 
                    IntroLoopMode = 0;
			        hidei('loop');
			        clearTimeout(IntroLoopTimer);
	                cleartime();
			        clearTimeout(IntroTimer1);
			        clearTimeout(IntroTimer2);
			        clearTimeout(IntroTimer3);
			        clearTimeout(IntroTimer3b);
			        clearTimeout(IntroTimer4);
			        clearTimeout(IntroTimer5);
			        clearTimeout(IntroTimer6);
			        clearTimeout(IntroTimer7);
			        clearTimeout(IntroTimerx);
			        TNTDoCommand('Objects(Pop_finish).SetVisible(false)');
			        IntMapObject="Camera01";
			        IntMapRotObject="Sphere01";
			        TNTDoCommand('Objects(Pop_start).SetVisible(false)');
			        TNTDoCommand('Objects(Sphere01).SetEnable(true)');
			        TNTDoCommand('CameraCtrl.SetCurrent("Camera01")');					 
 			        FreshStart=1;


				   if(savedGameArray[12] == '0601keysz')   // is this 0601keyz within steelworks_interior.tnt
				   {
					   
					clearTimeout(AnimationTimer5);
					clearTimeout(MapTimer);
					createFlash(158,420,"flash_int_1.swf","myFlashmap");
					hidei('menu');
					hidei('Processes');
					hidei('Sponsors');
					hidei('click_menu');
					hidei('menu');
					showi(mapname);                
                    createTurnTool(600,374,"steelworks_interior.t2l", "#000000", 0, false);
					NextArea = 7;
					updatepic('zones', 6, false);
					loadUpStairs = true; 						// this allows the OnReady() Event to move the camera when the TNT has loaded else you start at the beginning of the zone.
					FreshStart=1;  
	                updatepic('character',6, false);           // change item to collect picture for next zone
			        updatepic('zones', 6, false);              // update zone graphic
   			        updatepic('numbers', informax, false);     // update items collected
					
					UpdateMapInt();

                  } else
				  	loadUpStairs = false;
				 }

		      if(NextArea == 7){
				  hideit('08doors');
				  disable('08walls');
			   }
	 
			 // Check to see if Gate Key needs displaying 
			 if(infornum==informax)
			 {
			   showit(Zone_Name);
			   enable(Zone_Name);
		       TTZoneEnter = 1;
               updatepic('character',characterImage, false);     // Still in an old zone, show previous graphic
               OnZoneEnter(savedGameArray[12], savedGameArray[1]);
			 }

	   } else // user opted to click cancel button
		      {
			   eraseCookie('LoISavedGame');
			  }
			  
			 // finally, start animations if outside
		  	if(CurrentT2L == 'steelworks.t2l') {
			   ClearOutsideAnimations();
               LoopingAnimations();
			}


}

 timeOfLastLoad = new Date();   						// Used to avoid Save() via events if just loaded a zone
}



// >>> This function can be called with the cookie saved camera/sphere cordinates to reposition it.
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
function moveCamera(a0, a1, a4, a5, a6, a7, a8) {
 TNTDoCommand('Objects('+a1+').SetPositionLocal('+parseFloat(a4)+','+parseFloat(a5)+','+parseFloat(a6)+')'); 
 TNTDoCommand('Objects('+a1+').SetRotationLocal(0,0,'+parseFloat(a7)+')');
 // Set saved camera as active camera and load angle back in
 TNTDoCommand('CameraCtrl.SetCurrent('+a0+')');
 TNTDoCommand('Objects('+a0+').SetRotationLocal('+parseFloat(a8)+',0,0)');
}

// Added as outside animations stop playing when game loads.
function ClearOutsideAnimations(){
	IntroLoopMode = 0;
	hidei('loop');
	cleartime();
	clearTimeout(AnimationTimer1);
	clearTimeout(AnimationTimer2);
	clearTimeout(AnimationTimer3);
	clearTimeout(AnimationTimer4);
	clearTimeout(AnimationTimer5);
	clearTimeout(AnimationTimer6);
	clearTimeout(AnimationTimer7);
	clearTimeout(AnimationTimer8);
	clearTimeout(AnimationTimer9);
	clearTimeout(AnimationTimer10);
	clearTimeout(AnimationTimer11);
	clearTimeout(AnimationTimer12);
	clearTimeout(AnimationTimer13);
}

// >>> called from OnReady() - this function is called on a timeout to move camera after a tnt has loaded
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
function jumpUpStairs(){
   	 // Set saved camera as active camera and load angle back in
        TNTDoCommand('CameraCtrl.SetCurrent("Camera01")');		
  	    TNTDoCommand('Objects("Camera01").SetRotationLocal(80,0,0)');

     // Move saved Physics Sphere to saved position
        TNTDoCommand('Objects(Sphere01).SetPositionLocal(-40,-14,18'); 
        TNTDoCommand('Objects(Sphere01).SetRotationLocal(0,0,122.88639)');
			
		loadUpStairs = false;
		
// Enable doors, setup GUI
        hideit("06doors");
		hideit("07doors");
		disable("06walls");
		disable("07walls");
		hideit("0601keysz");
		disable("0601keysz");
		Zone_Name = "0601keysz";
        updatepic('character',7);     // change item to collect picture for next zone
   		updatepic('numbers', 0, false);            // update items collected
        clearTimeout(AnimationTimer5);
	    clearTimeout(MapTimer);
	    createFlash(158,420,"flash_int_1.swf","myFlashmap");
	    hidei('menu');
	    hidei('Processes');
	    hidei('Sponsors');
	    hidei('click_menu');
	    hidei('menu');
	    showi(mapname); 
        disable("0601infor");
		disable("0602infor");
		disable("0603infor");
		disable("0604infor");
		disable("0605infor");
		hideit("0601spann");
  		hideit("0602spann");
		hideit("0603spann");
        hideit("0604spann");
		hideit("0605spann");
}


// >>> Creates a cookie on the users PC - used for saving and loading the game
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

// >>> Reads a cookie from the users PC - used for saving and loading the game
function loadCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

// Allows the deletion of our cookies from the users machine
function eraseCookie(name) {
	createCookie(name,"",-1);
}



function MM_reloadPage(init) 
{  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
function MM_swapImgRestore() 
{ //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() 
{ //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) 
{ //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

		var ie4 = (document.all && !document.getElementById);
		var ie5 = (document.all && document.getElementById);
		var ns6 = (!document.all && document.getElementById);
		
		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 tntWidth 			= 600; //606; //640;
			var tntHeight 			= 374; //455;  //480;
			var tntFilename 		= "steelworks.t2l";
			var tntColor 			= "#000000";
			var tntTransparent 		= 0;
			
			var tntInstalled 		= isTurnToolInstalled();
			if (tntInstalled==false)
			{
				createTurnTool(tntWidth,tntHeight,tntFilename,tntColor,tntTransparent,true);
				checkRefresh();
			}
			else
			{
				createTurnTool(tntWidth,tntHeight,tntFilename,tntColor,tntTransparent,false);
			}
			createFlash(158,420,"flash_1.swf","myFlashmap");
		}

		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.true2life.co.uk/OfflineInstall.exe";
			else
			{
				var xpi = {'True2life Viewer Installation':'http://www.true2life.co.uk/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==120)
				{
					//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 setFocus()
		{
			var control = element("TNTCtrl");
			if(control && control.ready)
			{
			if (!ns6)
				element("TNTCtrl").focus();
			}
		}
		
		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 saveImage()
{
	alert('A screenshot will now be saved on the desktop entitled ScreenShot.bmp')
	TNTDoCommand('Renderer.SaveImage("ScreenShot.bmp",0)')
}

function cleartime()
{	
	clearTimeout(IntroTimer1);
	clearTimeout(IntroTimer2);
	clearTimeout(IntroTimer3);
	clearTimeout(IntroTimer3b);
	clearTimeout(IntroTimer4);
	clearTimeout(IntroTimer5);
	clearTimeout(IntroTimer6);
	clearTimeout(IntroTimer7);
	clearTimeout(IntroTimerx);
	
	clearTimeout(AnimationTimer1);
	clearTimeout(AnimationTimer2);
	clearTimeout(AnimationTimer3);
	clearTimeout(AnimationTimer4);
	clearTimeout(AnimationTimer5);
	clearTimeout(AnimationTimer6);
	clearTimeout(AnimationTimer7);
	clearTimeout(AnimationTimer8);
	clearTimeout(AnimationTimer9);
	clearTimeout(AnimationTimer10);
	clearTimeout(AnimationTimer11);
	clearTimeout(AnimationTimer12);
	clearTimeout(AnimationTimer13);
	clearTimeout(IntroLoopTimer);
	
	clearTimeout(loadhardtimer);

	clearTimeout(showtimer1);
	clearTimeout(showtimer2);
	clearTimeout(showtimer3);

}

function StartHotmillAnimationSequence()
{
    TNTDoCommand('Objects("Sphere01").SetEnable(false)');
	cleartime();
	clearTimeout(IntroTimer1);
	clearTimeout(IntroTimer2);
	clearTimeout(IntroTimer3);
	clearTimeout(IntroTimer3b);
	clearTimeout(IntroTimer4);
	clearTimeout(IntroTimer5);
	clearTimeout(IntroTimer6);
	clearTimeout(IntroTimer7);
	clearTimeout(IntroTimerx);
	
	TNTDoCommand('Objects(Pop_start).SetVisible(true)');
	TNTDoCommand('Objects(Popup_0).SetVisible(true)');
	TNTDoCommand('Objects(Popup_9).SetVisible(false)');
	IntroTimer1 = setTimeout("TNTDoCommand('Objects(Pop_start).SetVisible(false)');",5000);
	IntroTimerx = setTimeout("TNTDoCommand('Objects(Popup_0).SetVisible(false)');",10000);
	IntroTimer2 = setTimeout("TNTDoCommand('Objects(CameraClip01).PlayAnimation(0,500,false,15)'); TNTDoCommand('CameraCtrl.SetCurrent(\"CameraClip01\")');MillMapObject=\"CameraClip01\";MillMapRotObject=\"CameraClip01\";",4);
	IntroTimer3 = setTimeout("TNTDoCommand('Objects(CameraClip02).PlayAnimation(500,1030,false,15)'); TNTDoCommand('CameraCtrl.SetCurrent(\"CameraClip02\")');MillMapObject=\"CameraClip02\";MillMapRotObject=\"CameraClip02\";",33332);
	IntroTimer4 = setTimeout("TNTDoCommand('Objects(CameraClip03).PlayAnimation(1030,2259,false,15)'); TNTDoCommand('CameraCtrl.SetCurrent(\"CameraClip03\")');MillMapObject=\"CameraClip03\";MillMapRotObject=\"CameraClip03\";",68666);	
	IntroTimer5 = setTimeout("TNTDoCommand('Objects(CameraClip04).PlayAnimation(2100,2768,false,15)'); TNTDoCommand('CameraCtrl.SetCurrent(\"CameraClip04\")');MillMapObject=\"CameraClip04\";MillMapRotObject=\"CameraClip04\";",140200);
	IntroTimer6 = setTimeout("TNTDoCommand('Objects(CameraClip05).PlayAnimation(2790,3680,false,15)'); TNTDoCommand('CameraCtrl.SetCurrent(\"CameraClip05\")');MillMapObject=\"CameraClip05\";MillMapRotObject=\"CameraClip05\";",186666);
	IntroTimer7 = setTimeout("TNTDoCommand('Objects(CameraClip06).PlayAnimation(3680,5500,false,15)'); TNTDoCommand('CameraCtrl.SetCurrent(\"CameraClip06\")');MillMapObject=\"CameraClip06\";MillMapRotObject=\"CameraClip06\";",246666);
	IntroTimer3b = setTimeout("Walk();",180000);
}

function StartInteriorAnimationSequence()
{
	cleartime();
	clearTimeout(IntroTimer1);
	clearTimeout(IntroTimer2);
	clearTimeout(IntroTimer3);
	clearTimeout(IntroTimer3b);
	clearTimeout(IntroTimer4);
	clearTimeout(IntroTimer5);
	clearTimeout(IntroTimer6);
	clearTimeout(IntroTimer7);
	clearTimeout(IntroTimerx);

	IntroTimer1 = setTimeout("TNTDoCommand('CameraCtrl.SetCurrent(\"intro_cam_2\")');IntMapObject=\"intro_cam_2\";IntMapRotObject=\"intro_cam_2\";",13000);  //camera2
	IntroTimer2 = setTimeout("TNTDoCommand('CameraCtrl.SetCurrent(\"intro_cam_3\")');IntMapObject=\"intro_cam_3\";IntMapRotObject=\"intro_cam_3\";",18000);  //camera3
	IntroTimer3 = setTimeout("TNTDoCommand('CameraCtrl.SetCurrent(\"intro_cam_4\")');IntMapObject=\"intro_cam_4\";IntMapRotObject=\"intro_cam_4\";",41000);  //camera4
	IntroTimer3b = setTimeout("TNTDoCommand('CameraCtrl.SetCurrent(\"intro_cam_3\")');IntMapObject=\"intro_cam_3\";IntMapRotObject=\"intro_cam_3\";",51200);  //camera3
	IntroTimer4 = setTimeout("TNTDoCommand('CameraCtrl.SetCurrent(\"intro_cam_5\")');IntMapObject=\"intro_cam_5\";IntMapRotObject=\"intro_cam_5\";",62000);  //camera5
	IntroTimerx = setTimeout("TNTDoCommand('CameraCtrl.SetCurrent(\"intro_cam_x\")');IntMapObject=\"intro_cam_x\";IntMapRotObject=\"intro_cam_x\";",83600);  //camerax
	IntroTimer5 = setTimeout("TNTDoCommand('CameraCtrl.SetCurrent(\"intro_cam_6\")');IntMapObject=\"intro_cam_6\";IntMapRotObject=\"intro_cam_6\";",107000);  //camera6
	IntroTimer6 = setTimeout("TNTDoCommand('CameraCtrl.SetCurrent(\"intro_cam_7\")');IntMapObject=\"intro_cam_7\";IntMapRotObject=\"intro_cam_7\";",115000);  //camera7
	IntroTimer7 = setTimeout("HoldFinalSign()",2000);
}

function HoldFinalSign()
{
    TNTDoCommand('Objects(Pop_finish).StopAnimation()');
}

function SteelPlantRepeatAnimation()
{
	if(TNTDoCommand('Objects(*).GetStopFrame()')!=750)
	{
		TNTDoCommand('Objects(*).PlayAnimation(0,750,false,30)');
	}
	else
	{
		TNTDoCommand('Objects(*).PlayAnimation(750,0,false,30)');
	}
	TNTDoCommand('CameraCtrl.SetCurrent("Camera04",2000)');
	TNTDoCommand('Objects(*).SetFrame(0)');
	
}




function StartAnimationSequence()
{
	TNTDoCommand('Objects(Sphere01).SetEnable(false)');
	TNTDoCommand('CameraCtrl.SetCurrent("Camera02")');
	
	TNTDoCommand('Objects(Box01_boat).PlayAnimation(0,399,false,30)');//boat
	TNTDoCommand('Objects(Camera02).PlayAnimation(0,3612,false,30)');
	TNTDoCommand('Objects(Pop_start).PlayAnimation(0,152,false,30)');
	TNTDoCommand('Objects(Popup1_*).PlayAnimation(0,3612,false,30)');

// Global looping animations

	LoopingAnimations();
	 
// Timed animations	
	cleartime();
	clearTimeout(AnimationTimer1);
	clearTimeout(AnimationTimer2);
	clearTimeout(AnimationTimer3);
	clearTimeout(AnimationTimer4);
	clearTimeout(AnimationTimer5);
	clearTimeout(AnimationTimer6);
	clearTimeout(AnimationTimer7);
	clearTimeout(AnimationTimer8);
	clearTimeout(AnimationTimer9);
	clearTimeout(AnimationTimer10);
	clearTimeout(AnimationTimer11);
	clearTimeout(AnimationTimer12);
	clearTimeout(AnimationTimer13);

	AnimationTimer5 = setTimeout("Walk();",120000);
}

function LoopingAnimations()
{

// Global looping animations

	//non-looping but required
	TNTDoCommand('Objects(Box01_boat).PlayAnimation(0,399,false,30)');//boat
	
	//labels
	TNTDoCommand('Objects(walk_inside*).PlayAnimation(0,200,true,300)');
	//crane
	TNTDoCommand('SceneGraph.ObjectTree([Crane]).PlayAnimation(0,3499,true,30)');
	TNTDoCommand('Objects(Iron_anim09).PlayAnimation(0,3499,true,30)');
    TNTDoCommand('SceneGraph.ObjectTree([TrainA02]).PlayAnimation(0,3499,true,30)');
	TNTDoCommand('Objects(outdoor01).PlayAnimation(0,3499,true,30)');
	//reclaimers
	TNTDoCommand('Objects(Cylinder1234543661).PlayAnimation(0,99,true,30)');
	TNTDoCommand('Objects(Cylinder1234543662).PlayAnimation(0,99,true,30)');
	TNTDoCommand('Objects(Cylinder1234543658).PlayAnimation(0,99,true,30)');
	TNTDoCommand('Objects(Object1123391).PlayAnimation(0,99,true,30)');
	TNTDoCommand('Objects(Object1123399).PlayAnimation(0,99,true,30)'); 
	//blast
	TNTDoCommand('Objects(Object31).PlayAnimation(0,3499,true,30)');
	TNTDoCommand('Objects(outdoor02).PlayAnimation(0,3499,true,30)');
	TNTDoCommand('Objects(Box28).PlayAnimation(0,3499,true,30)');
	TNTDoCommand('Objects(Box1623424529).PlayAnimation(0,3499,true,30)');
	TNTDoCommand('Objects(Box04).PlayAnimation(0,3499,true,30)');
	TNTDoCommand('Objects(CO_Fontdoor).PlayAnimation(0,3499,true,30)');
	TNTDoCommand('Objects(St*).PlayAnimation(0,3499,true,30)');
	TNTDoCommand('Objects(CO_Backdoor).PlayAnimation(0,3499,true,30)'); 
	TNTDoCommand('Objects(Object67).PlayAnimation(0,3499,true,30)');
	TNTDoCommand('Objects(Object32).PlayAnimation(0,3499,true,30)');
	TNTDoCommand('Objects(Coal_door).PlayAnimation(0,3499,true,30)');
	//reclaimers iron
	TNTDoCommand('Objects(Cylinder1234543596).PlayAnimation(0,99,true,30)');
	TNTDoCommand('Objects(Iron_anim01).PlayAnimation(0,61,true,30)');
	TNTDoCommand('Objects(Iron_anim02).PlayAnimation(0,61,true,30)');
	TNTDoCommand('Objects(Iron_anim03).PlayAnimation(0,61,true,30)');
	TNTDoCommand('Objects(Iron_anim04).PlayAnimation(0,61,true,30)');
	TNTDoCommand('Objects(Iron_anim05).PlayAnimation(0,61,true,30)');
	TNTDoCommand('Objects(Iron_anim06).PlayAnimation(0,61,true,30)');
	TNTDoCommand('Objects(Iron_anim07).PlayAnimation(0,61,true,30)');
	TNTDoCommand('Objects(Iron_anim08).PlayAnimation(0,61,true,30)');
	TNTDoCommand('Objects(Cylinder12343253).PlayAnimation(0,99,true,30)');
	TNTDoCommand('Objects(Cylinder1234543652).PlayAnimation(0,99,true,30)');
	TNTDoCommand('Objects(Object1123333).PlayAnimation(0,99,true,30)');	
	TNTDoCommand('Objects(Object1123386).PlayAnimation(0,99,true,30)');
	TNTDoCommand('Objects(Cylinder1234543654).PlayAnimation(0,99,true,30)'); 
	//sinter
	TNTDoCommand('SceneGraph.ObjectTree([Group13]).PlayAnimation(0,84,true,30)');
	TNTDoCommand('Objects(Plane197).PlayAnimation(0,498,true,30)');
	TNTDoCommand('Objects(Plane198).PlayAnimation(0,498,true,30)');
	TNTDoCommand('Objects(Plane199).PlayAnimation(0,498,true,30)');
	TNTDoCommand('Objects(Plane200).PlayAnimation(0,498,true,30)');
	TNTDoCommand('Objects(Plane201).PlayAnimation(0,498,true,30)');
	TNTDoCommand('Objects(Plane203).PlayAnimation(0,498,true,30)');
	//hotmill
	TNTDoCommand('Objects(talonANI*).PlayAnimation(0,1550,true,25)'); 
	TNTDoCommand('Objects(ANI_MovTab1).PlayAnimation(0,40,true,25)'); 

	
}

function WebCam(cam_num)
{
	
	cleartime();
	if(CurrentT2L=="steelworks.t2l")
	{
		TNTDoCommand('Objects("Pop_start").StopAnimation()');
		TNTDoCommand('Objects("Camera02").StopAnimation()');
		TNTDoCommand('Objects(Sphere01).SetEnable(false)');
	}
	else if(CurrentT2L=="steelworks_hotmill.t2l")
	{
		MillMapObject = "View_Cam_0" + cam_num;
		MillMapRotObject = "View_Cam_0" + cam_num;
		TNTDoCommand('Objects(Sphere01).SetEnable(false)');
	}
	
	TNTDoCommand('CameraCtrl.SetCurrent(\"View_Cam_0' + cam_num + '\")');
}

function Walk()
{
	
	IntroLoopMode = 0;
	hidei('loop');
	cleartime();
	if(CurrentT2L=="steelworks.t2l")
	{
		clearTimeout(AnimationTimer1);
		clearTimeout(AnimationTimer2);
		clearTimeout(AnimationTimer3);
		clearTimeout(AnimationTimer4);
		clearTimeout(AnimationTimer5);
		clearTimeout(AnimationTimer6);
		clearTimeout(AnimationTimer7);
		clearTimeout(AnimationTimer8);
		clearTimeout(AnimationTimer9);
		clearTimeout(AnimationTimer10);
		clearTimeout(AnimationTimer11);
		clearTimeout(AnimationTimer12);
		clearTimeout(AnimationTimer13);
		MapDisplacementVar = 100000;
		MapDisplacementVar_phys = 0;
		TNTDoCommand('Objects("Pop_start").StopAnimation()');
		TNTDoCommand('Objects("Camera02").StopAnimation()');
		TNTDoCommand('Objects("Pop_start").SetFrame(152)');
		TNTDoCommand('CameraCtrl.SetCurrent("PhysicsCamera01")');
		TNTDoCommand('Objects("Sphere01").SetEnable(true)');
	}
	else if (CurrentT2L=="steelworks_hotmill.t2l")
		{
			clearTimeout(IntroTimer1);
			clearTimeout(IntroTimer2);
			clearTimeout(IntroTimer3);
			clearTimeout(IntroTimer3b);
			clearTimeout(IntroTimer4);
			clearTimeout(IntroTimer5);
			clearTimeout(IntroTimer6);
			clearTimeout(IntroTimer7);
			clearTimeout(IntroTimerx);
			MapDisplacementVar_phys = 0;
			MillMapObject="Sphere01";
			MillMapRotObject="Sphere01";
			
			TNTDoCommand('Objects(Sphere01).SetEnable(true)');
			TNTDoCommand('CameraCtrl.SetCurrent("Camera01")');
	
		}
		
	if (CurrentT2L=="steelworks_interior.t2l")
		{
			MapDisplacementVar_phys = 0;
			MillMapObject="Sphere01";
			MillMapRotObject="Sphere01";
			
			TNTDoCommand('Objects(Sphere01).SetEnable(true)');
			TNTDoCommand('CameraCtrl.SetCurrent("Camera01")');
	
		}
	
	setFocus();
}

function Walk_beginning()
{
	cleartime();
	GotoArea(1);
}


function GotoArea(areanum)
{
    IntroLoopMode = 0;
	hidei('loop');
	cleartime();
	clearTimeout(AnimationTimer1);
	clearTimeout(AnimationTimer2);
	clearTimeout(AnimationTimer3);
	clearTimeout(AnimationTimer4);
	clearTimeout(AnimationTimer5);
	clearTimeout(AnimationTimer6);
	clearTimeout(AnimationTimer7);
	clearTimeout(AnimationTimer8);
	clearTimeout(AnimationTimer9);
	clearTimeout(AnimationTimer10);
	clearTimeout(AnimationTimer11);
	clearTimeout(AnimationTimer12);
	clearTimeout(AnimationTimer13);
	
	MapDisplacementVar = 100000;
	MapDisplacementVar_phys = 0;
	
	TNTDoCommand('Objects("Popup_*").SetVisible(false)');
	TNTDoCommand('Objects("Popup_' + areanum + '").SetVisible(true)');
		
	TNTDoCommand('Objects(Camera02).StopAnimation()');
	TNTDoCommand('Objects("Popup_' + areanum + '").PlayAnimation(0,100,false,25)');
	
	srcPosX = parseFloat(TNTDoCommand('Objects(' + "GotoSphere" + areanum + ').GetPositionLocalX()'));
	srcPosY = parseFloat(TNTDoCommand('Objects(' + "GotoSphere" + areanum + ').GetPositionLocalY()'));
	srcPosZ = parseFloat(TNTDoCommand('Objects(' + "GotoSphere" + areanum + ').GetPositionLocalZ()'));
	srcRotZ = parseFloat(TNTDoCommand('Objects(' + "GotoSphere" + areanum + ').GetRotationLocalZ()'));
	
	TNTDoCommand('Objects(Sphere01).SetPositionLocal('+srcPosX+','+srcPosY+','+srcPosZ+')');
	TNTDoCommand('Objects(Sphere01).SetRotationLocal(0,0,'+srcRotZ+')');
	TNTDoCommand('Objects(Sphere01).SetEnable(true)');
	TNTDoCommand('CameraCtrl.SetCurrent("PhysicsCamera01")');

	setFocus();
}

function GotoIntArea(areanum)
{
	IntroLoopMode = 0;
	hidei('loop');
	cleartime();
	Frame=areanum-1;
	IntMapObject="Camera01";
	IntMapRotObject="Sphere01";
	TNTDoCommand('Objects(Pop_finish).SetVisible(false)');
	clearTimeout(IntroTimer1);
	clearTimeout(IntroTimer2);
	clearTimeout(IntroTimer3);
	clearTimeout(IntroTimer3b);
	clearTimeout(IntroTimer4);
	clearTimeout(IntroTimer5);
	clearTimeout(IntroTimer6);
	clearTimeout(IntroTimer7);
	clearTimeout(IntroTimerx);
	
	srcPosX = parseFloat(TNTDoCommand('Objects(' + "GotoSphere" + areanum + ').GetPositionLocalX()'));
	srcPosY = parseFloat(TNTDoCommand('Objects(' + "GotoSphere" + areanum + ').GetPositionLocalY()'));
	srcPosZ = parseFloat(TNTDoCommand('Objects(' + "GotoSphere" + areanum + ').GetPositionLocalZ()'));
	srcRotZ = parseFloat(TNTDoCommand('Objects(' + "GotoSphere" + areanum + ').GetRotationLocalZ()'));
	
	TNTDoCommand('Objects(Sphere01).SetPositionLocal('+srcPosX+','+srcPosY+','+srcPosZ+')');
	TNTDoCommand('Objects(Sphere01).SetRotationLocal(0,0,'+srcRotZ+')');
	TNTDoCommand('Objects(Pop_start).SetVisible(false)');
	TNTDoCommand('Objects(Sphere01).SetEnable(true)');
	TNTDoCommand('CameraCtrl.SetCurrent("Camera01")');

	setFocus();
}

function GotoHotmillArea(areanum)
{
	
	IntroLoopMode = 0;
	hidei('loop');
	cleartime();
	MillMapObject="Sphere01";
	MillMapRotObject="Sphere01";
	
	clearTimeout(IntroTimer1);
	clearTimeout(IntroTimer2);
	clearTimeout(IntroTimer3);
	clearTimeout(IntroTimer3b);
	clearTimeout(IntroTimer4);
	clearTimeout(IntroTimer5);
	clearTimeout(IntroTimer6);
	clearTimeout(IntroTimer7);
	clearTimeout(IntroTimerx);
	srcPosX = parseFloat(TNTDoCommand('Objects(' + "GotoSphere" + areanum + ').GetPositionLocalX()'));
	srcPosY = parseFloat(TNTDoCommand('Objects(' + "GotoSphere" + areanum + ').GetPositionLocalY()'));
	srcPosZ = parseFloat(TNTDoCommand('Objects(' + "GotoSphere" + areanum + ').GetPositionLocalZ()'));
	srcRotZ = parseFloat(TNTDoCommand('Objects(' + "GotoSphere" + areanum + ').GetRotationLocalZ()'));
	
	TNTDoCommand('Objects(Sphere01).SetPositionLocal('+srcPosX+','+srcPosY+','+srcPosZ+')');
	TNTDoCommand('Objects(Sphere01).SetRotationLocal(0,0,'+srcRotZ+')');
	TNTDoCommand('Objects(Pop_start).SetVisible(false)');
	TNTDoCommand('Objects(Sphere01).SetEnable(true)');
	TNTDoCommand('CameraCtrl.SetCurrent("Camera01")');

	setFocus();

}

function SinterCam()
{
	TNTDoCommand('Objects(Sphere01).SetEnable(false)');
	TNTDoCommand('Objects(Sphere02).SetEnable(true)');
	TNTDoCommand('CameraCtrl.SetCurrent("PhysicsCamera02")');
	setFocus();
}


function OnReady()
{
	switchLang(getLang());
	
    TNTDoCommand('Core.SetKeyboardEvents(1)');
	setFocus();
	window.status = "True2Life Resource Ready";	
	clearTimeout(MapTimer);
	disable('close');
	disable('yes');
	disable('no');
	hideit('close');

	//if (level == 2) // now taken care of in switchLang
      //  loadhard();
	
    // When a new TNT is loaded the OnReady function is called again, this next part stops the 
	// dialog opening asking to load when entering internal areas (new 3d files)
	  if (!gameLoaded) 
        loadLastGame();

   // If steel mill internal has been loaded then the save point is upstairs, move camera to save point in a few seconds after the TNT has loaded.
   if(loadUpStairs)
       setTimeout("jumpUpStairs(),5000");

	
	TTOnReady = 1;	   // Allow Listener to kick in
  

} // func


function switchLang( lang ) {

	if(lang == '') 
		lang = 'eng';
		
	var pathToImages = '../' + lang + '/loitags/';		
	
	if(lang == 'chi') {
			for(var i =1; i<=8;i++){
				for(var j =1; j<=5;j++){
					if(level == 2) // Load Hard Images
						TNTDoCommand('SceneGraph.Bitmap("E0'+i+'Q0'+ j+'").Load("'+pathToImages+'H0'+i+'Q0'+ j+'_CHI.jpg")');										
					if(level != 2) // Load normal images
						TNTDoCommand('SceneGraph.Bitmap("E0'+i+'Q0'+ j+'").Load("'+pathToImages+'E0'+i+'Q0'+ j+'_CHI.jpg")');
				} // for
			} // for
			
		// Load other CHI images
			TNTDoCommand('SceneGraph.Bitmap("exit").Load("'+pathToImages+'exit_CHI.jpg")');
			TNTDoCommand('SceneGraph.Bitmap("lift_SIGN").Load("'+pathToImages+'lift_SIGN_CHI.jpg")');
			TNTDoCommand('SceneGraph.Bitmap("Q_Hotmill_Hint1").Load("'+pathToImages+'Q_Hotmill_Hint1_CHI.jpg")');
			TNTDoCommand('SceneGraph.Bitmap("Q_Hotmill_Hint2").Load("'+pathToImages+'Q_Hotmill_Hint2_CHI.jpg")');
			
			TNTDoCommand('SceneGraph.Bitmap("ironore").Load("'+pathToImages+'ironore_CHI.jpg")');
			TNTDoCommand('SceneGraph.Bitmap("Q_IO_HINT").Load("'+pathToImages+'Q_IO_HINT_CHI.jpg")');			
			TNTDoCommand('SceneGraph.Bitmap("walkinside").Load("'+pathToImages+'walkinside_CHI.jpg")');
			TNTDoCommand('SceneGraph.Bitmap("coalblending").Load("'+pathToImages+'coalblending_CHI.jpg")');
			TNTDoCommand('SceneGraph.Bitmap("Q_Coal_Hint").Load("'+pathToImages+'Q_Coal_Hint_CHI.jpg")');			
			TNTDoCommand('SceneGraph.Bitmap("cokeovens").Load("'+pathToImages+'cokeovens_CHI.jpg")');
			TNTDoCommand('SceneGraph.Bitmap("Q_CO_Hint").Load("'+pathToImages+'Q_CO_Hint_Chi.jpg")');
			TNTDoCommand('SceneGraph.Bitmap("sinter").Load("'+pathToImages+'sinter_CHI.jpg")');
			TNTDoCommand('SceneGraph.Bitmap("Q_Sinter_Hint").Load("'+pathToImages+'Q_Sinter_Hint_CHI.jpg")');
			TNTDoCommand('SceneGraph.Bitmap("blastfurnace_single").Load("'+pathToImages+'Blast_Furnace_CHI.jpg")');
			TNTDoCommand('SceneGraph.Bitmap("blastfurnace").Load("'+pathToImages+'Blast_Furnace_CHI.jpg")');
			TNTDoCommand('SceneGraph.Bitmap("Q_Blast_Hint").Load("'+pathToImages+'Q_Blast_Hint_CHI.jpg")');			
			TNTDoCommand('SceneGraph.Bitmap("Primary1").Load("'+pathToImages+'Primary1_CHI.jpg")');	
			TNTDoCommand('SceneGraph.Bitmap("Q_Primary_Hint").Load("'+pathToImages+'Q_Primary_Hint_CHI.jpg")');			
			TNTDoCommand('SceneGraph.Bitmap("secmaking").Load("'+pathToImages+'secmaking_CHI.jpg")');	
			TNTDoCommand('SceneGraph.Bitmap("primary").Load("'+pathToImages+'primary_CHI.jpg")');	
			TNTDoCommand('SceneGraph.Bitmap("Q_SSM_Hint").Load("'+pathToImages+'Q_SSM_Hint_CHI.jpg")');
			TNTDoCommand('SceneGraph.Bitmap("hotmill").Load("'+pathToImages+'hotmill_CHI.jpg")');		
			TNTDoCommand('SceneGraph.Bitmap("Q_Hotmill_Hint").Load("'+pathToImages+'Q_Hotmill_Hint_CHI.jpg")');			
	} // If Lang 


}

function getLang(){
	// read url
	var currentURL = window.location;
	var path = currentURL.pathname;
	// look for Language ID by searching for '/html/'  when found read the next 3 characters for lang id
	var idPos = (path.indexOf("html") + 5);
						   
	return path.substring(idPos, idPos+3);
	//return 'chi';  //override language and force chinese while testing.
}

var loadhardtimer;
function loadhard()
{
	   
		for(var i =1; i<=8;i++)
		{
			for(var j =1; j<=5;j++)
			{
			   TNTDoCommand('SceneGraph.Bitmap("E0'+i+'Q0'+ j+'").Load("../../../loi/images/ENG/H0'+i+'Q0'+ j+'.png")');			
			}
			
		}
	
}


function OnReady_Listener()
{
	if (TTOnReady == 1)
	{
      TTOnReady=0;
	  

     // Added this twice, once in OnReady and here as IE has been known to skip the OnReady() even for various reasons.
     if(loadUpStairs) {
       setTimeout("jumpUpStairs(),6000");   
	 }


       if (CurrentT2L=="steelworks.t2l")
		{
		   showi(mapname);
			hidei('Sponsors');
			hidei('Processes');
			hidei('menu');
			
			UpdateMap();
			
			if (FreshStart==1)
			{
				MapDisplacementVar = 0;
				MapDisplacementVar_phys = 100000;
				LoopingAnimations();	
				updatepanel('01');
                GotoArea(1);
			}
			
			if(LeavingZone5) {   // User has left the building (BlastZone), move them to Zone 5 gate and save.
               LeavingZone5=false;
               FreshStart=1;
			   
			   // Start animations
			   LoopingAnimations();
			   // This will move view  to outside zone 5
			   GotoArea(NextArea);	   
               // Hide all collected objects so far
               setexterior(5);	 
			   // Set number of items to 0 else it will trigger several zone completions
			   infornum = informax;
			   // Trigger key pickup
			   num  = '0501';
			   zone = '0501keysz';
			   
			    door = num.slice(0,2)+'doors';
				wall = num.slice(0,2)+'walls';
				if(CurrentT2L != 'steelworks.t2l'||(zone != '0501keysz' && zone != '0601keysz'))
					disable('Sphere01');
				if(num == '0601' && CurrentT2L == 'steelworks_interior.t2l')
				  infornum=0;
				var next = num.slice(1,2);
				    updatepic('zones', next); 
				if (next == 8 && CurrentT2L == 'steelworks.t2l')
					endmovie();
				if(next == 6 && CurrentT2L == 'steelworks.t2l')
					updatepic('zones', 7);
				next++;
				next = '0'+ next;
				nextdoors = next + 'doors';
				nextwalls = next + 'walls';
				hideit(door);
				hideit(nextdoors);
				disable(wall);
				disable(nextwalls);
				hideit(key);
				disable(zone);  
			    updatepanel('05');		   

				Save('05');
			}
			
			
			// when playing normal game leaving this building leaves you outside without being able to get through gate.
            if(LeavingZone6){
               LeavingZone6=false;
               FreshStart=1;
			   
			   // Start animations
			   LoopingAnimations();
			   // This will move view  to outside zone 6
			   GotoArea(6);	 
               // Hide all collected objects so far
               setexterior(6);	 
			   // Set number of items to 0 else it will trigger several zone completions
			   infornum = informax;
			   // Trigger key pickup
			   num  = '0601';
			   zone = '0601keysz';
			   // opening next gate
			    showit('06doors');
                enable('06walls');
                disable('0701keysz');
			   
			    door = num.slice(0,2)+'doors';
				wall = num.slice(0,2)+'walls';
				if(CurrentT2L != 'steelworks.t2l'||(zone != '0501keysz' && zone != '0601keysz'))
					disable('Sphere01');
				if(num == '0601' && CurrentT2L == 'steelworks_interior.t2l')
				  infornum=0;
				var next = num.slice(1,2);
				    updatepic('zones', next); 
				if (next == 8 && CurrentT2L == 'steelworks.t2l')
					endmovie();
				if(next == 6 && CurrentT2L == 'steelworks.t2l')
					updatepic('zones', 7);
					
				next++;
				next = '0'+ next;
				nextdoors = next + 'doors';
				nextwalls = next + 'walls';
				//num++;
				hideit(door);
				hideit(nextdoors);
				disable(wall);
				disable(nextwalls);
				hideit(key);
				disable(zone);  
			    updatepanel('06');		   
					
				Save('0701keysz');
				
				// Open Gate for zone 8				
				hideit("08doors");
				disable("08walls");
				
			}
			
				
				if( (NextArea == 6) && (!gameLoaded) )
				{
					if (infornum >= informax)
					{
						OnZoneEnter('0601keysz');
						hideit('08doors');
						disable('08walls');
						updatepanel('07');
						setexterior(7);
					}

				}
				
				if (NextArea == 7)
				{
					if (infornum >= informax)
					{
						updatepanel('08');
						setexterior(8);
						updatepic('zones', 8, false);
						enable('0801keysz')
					}

				}		
			
			}
			
			if (IntroLoopMode==1)
			    IntroLoopTimer = setTimeout("OnZoneEnter('Zone_primary')",118500);
			
		if (CurrentT2L=="steelworks_interior.t2l")
		{
				updatepanel('06');
				
				if (NextArea >= 6)
				{
						setexterior(7);
						//infornum = 5;
				}
			TNTDoCommand('Objects(Sphere01).SetEnable(false)');
			IntMapObject = "intro_cam_1";
			IntMapRotObject = "intro_cam_1";
			UpdateMapInt();
			TNTDoCommand('Objects(*).PlayAnimation(0,4000,true,30)');
			OnKeyPress(1167)

			if (IntroLoopMode==1)
			{
				IntroLoopTimer = setTimeout("OnZoneEnter('Zone_Exit01')",123000);

			}
		}
		if (CurrentT2L=="steelworks_hotmill.t2l")
		{
				updatepanel('08');
				
				if (NextArea >= 7)
				{
						setexterior(8);
						//infornum = 5;
				}
			TNTDoCommand('Objects(Sphere01).SetPhysicsGripThreshold(999)');
			hidei('menu');
			hidei('Processes');
			hidei('Sponsors');
			hidei('click_menu');
			hide('menu');
			showi(mapname);                //if not already showing
			TNTDoCommand('Objects(*).PlayAnimation(0,5500,true,30)');
			OnKeyPress(1167)
			MillMapObject = "Sphere01";
			MillMapRotObject = "Sphere01";
			UpdateMapHotmill();
		}
		if (CurrentT2L=="blastfurnace.t2l")
		{
			updatepanel('05');
			
			if(NextArea >= 5)
			{
				setexterior(5);
			}
		}
	}
	setTimeout ("OnReady_Listener()",500);
}


function OnClick( obj )
{
			switch (obj) {
				case 'close':
				hideit(popup);
				disable('close');
				enable('Sphere01');
				recamera();
				break;
				case 'yes':
				hideit(popup);
				disable('yes');
				enable('Sphere01');
				recamera();
				parent.location = 'http://www.steeluniversity.org/content/html/eng/default.asp?catid=189&pageid= 2081272173';
				break;
				case 'no':
				hideit(popup);
				disable('no');
				enable('Sphere01');
				recamera();
				parent.location = 'index.html';
				break;
				default:
				break;
			}
			
			if(popup == '05intro')
			{
				createFlash(158,420,"flash_1.swf","myFlashmap");
				showi(mapname);
				FreshStart=0;
				NextArea=5;
				showi('click_menu');	
				createTurnTool(600,374,"steelworks.t2l", "#000000", 0, false);
			}
			
			if(popup == '07intro')
			{
				cleartime();
				createFlash(158,420,"flash_1.swf","myFlashmap");
				showi(mapname);
				showi('click_menu');
				clearTimeout(IntroTimer1);
				clearTimeout(IntroTimer2);
				clearTimeout(IntroTimer3);
				clearTimeout(IntroTimer3b);
				clearTimeout(IntroTimer4);
				clearTimeout(IntroTimer5);
				clearTimeout(IntroTimer6);
				clearTimeout(IntroTimer7);
				clearTimeout(IntroTimerx);
	
				if (IntroLoopMode==0)
				{
					FreshStart=0;
				}
				NextArea=6;
				
				createTurnTool(600,374,"steelworks.t2l", "#000000", 0, false);

			}
			if(popup == '08intro')
			{
				createFlash(158,420,"flash_1.swf","myFlashmap");
				showi(mapname);
				FreshStart=0;
				NextArea=7;
				showi('click_menu');	
				createTurnTool(600,374,"steelworks.t2l", "#000000", 0, false);
			}
			
			if(popup == '08intro02')
			{
				endmovie();
			}

	if(TNTDoCommand('Objects(' + obj + ').GetStopFrame()')!=100)
		TNTDoCommand('Objects(' + obj + ').PlayAnimation(,100)');
	else
		TNTDoCommand('Objects(' + obj + ').PlayAnimation(,0)');
	window.status = "Object clicked: " + obj;	
}

function OnMouseEnter( obj )
{
	TNTDoCommand('Objects(' + obj + ').SetDiffuseColor(#FF0000)');
	window.status = "Mouse Entered: " + obj;	
}

function OnMouseExit( obj )
{
	TNTDoCommand('Objects(' + obj + ').ResetMaterial()');
	window.status = "Mouse Exited: " + obj;	
}


		function showit(obj)
		{
			 TNTDoCommand('Objects("'+obj+'").SetVisible(1)');
		}
		function hideit(obj)
		{
			 TNTDoCommand('Objects("'+obj+'").SetVisible(0)');
		}
		
		function enable(obj)
		{
			TNTDoCommand('Objects("'+obj+'").SetEnable(true)');
		}
		function disable(obj)
		{
			TNTDoCommand('Objects("'+obj+'").SetEnable(false)');
		}

function OnZoneEnter( zone, physics )
{
    var obj = zone.slice(zone.length-5,zone.length);
	num = zone.slice(0,zone.length-5);
    updatepanel(num.slice(0,2));	
	
if (zone == '0701keysz') // top of stairs.
 {
 showit('06doors');
 enable('06walls');
 disable('0701keysz');
 infornum = 0;
 }
 
		
		switch (obj) {
				case 'infor':
 				 disable('Sphere01');
				 fixcamera(); 
				 spann = num+'spann';
				 spannzone = num+'infor';
				 popup = num+'intro';
				 hideit(spann);
				 disable(spannzone);		
				 showit(popup);
				 enable('close');
				 infornum++;
				 updatepic('numbers', infornum, true);

                 if (undefined != num) {
             	 if(itemsArray.indexOf(num) ==-1){
             	    itemsArray += num + '*';      } 
                                        }
				if (infornum >= informax)
				{
                    key = num.slice(0,2)+'01keyss';
					keyzone = num.slice(0,2)+'01keysz';
					showit(key);
					enable(keyzone);				
				}
				break;
				case 'keysz':
                door = num.slice(0,2)+'doors';
				wall = num.slice(0,2)+'walls';
				if (infornum >= informax)
				{
                    Save(zone);
 					if(CurrentT2L != 'steelworks.t2l'||(zone != '0501keysz' && zone != '0601keysz'))
						disable('Sphere01');
					if(num == '0601' && CurrentT2L == 'steelworks_interior.t2l')
						infornum=0;
					var next = num.slice(1,2);
					updatepic('zones', next); 
					if (next == 8 && CurrentT2L == 'steelworks.t2l')
						endmovie();
					if(next == 6 && CurrentT2L == 'steelworks.t2l')
						updatepic('zones', 7);
					next++;
					next = '0'+ next;
					nextdoors = next + 'doors';
					nextwalls = next + 'walls';
					//num++;
					hideit(door);
					hideit(nextdoors);
					disable(wall);
					disable(nextwalls);
					hideit(key);
					disable(zone);
					if(CurrentT2L != 'steelworks.t2l'||(zone != '0501keysz' && zone != '0601keysz'))
					{
					 disable('Sphere01');
					 fixcamera(); 
					 popup = num.slice(0,2)+'intro';
					 showit(popup);
					 enable('close');
					}
				}
				else
				{
				    updatepanel(num.slice(0,2));
				    updatepic('numbers', infornum, true);
				    updatepic('character', num.slice(1,2), true);
				    showit(door);
				    enable(wall);
				}
				break;
				case 'outer': 
                if (infornum >= informax)
				{			
                    infornum=0;
					var lastdoor = num.slice(0,2) + 'doors';
					var lastwall = num.slice(0,2) + 'walls';
					showit(lastdoor);
					enable(lastwall);
				}
				break;
				default:
       	          TTZoneEnter = 1;  		// Set Listener On to check for status.
				  Zone_Name = zone;
                   if (Zone_Name=="Zone_Exit01")      //exit interior - back to exterior
  	                   ZoneExit01();
                   if (Zone_Name=="Zone_Exit02")
                       ZoneExit02();
                   if (Zone_Name=="Zone_Exit03")
                       ZoneExit03();
                   if (Zone_Name=="Zone_Exit04")
                       ZoneExit04();
                   if (Zone_Name=="Zone_Exit05")
                       ZoneExit05();
                   if (Zone_Name=="Zone_blast")
                       ZoneBlast01();
                   if (Zone_Name=="Zone_blast01")
                       ZoneBlast02();
                   if (Zone_Name=="Zone_primary")     // enter primary steelmaking building
                       ZonePrimary();
                   if (Zone_Name=="Zone_sinter")
                       GotoArea(9);
                   if (Zone_Name=="shoot_top")
                       ShootTop();
                   if (Zone_Name=="shoot_bottom")
                       ShootBottom();
                   if (Zone_Name.slice(0,10)=="bshoot_top")
	                   bsShootTop();
                   if (Zone_Name.slice(0,13)=="bshoot_bottom")
                       bsShootBottom();
                   if (Zone_Name=="#Zone_Stairs1")
                       ZoneStairs1();
                   if (Zone_Name=="#Zone_Stairs2")
                       ZoneStairs2();  
                   if (Zone_Name.slice(0,9)=="speedzone") 
  	                   TNTDoCommand('Objects(Sphere01).SetPhysicsMoveSpeed(2688)');
				break;
			}


	Zone_Name = String(zone);
}

// Updates number or zone graphics to panel - save in here
function updatepic(obj, nums)
{
if(obj == 'numbers')  // update vars for save
   items = nums;

if(obj == 'zones')
	levelDone = nums;
	
    var imgsrc = element(obj).src;
	if(nums<=10)
	element(obj).src = imgsrc.slice(0,imgsrc.length-5)+nums+'.gif';
	else
	element(obj).src = imgsrc.slice(0,imgsrc.length-6)+nums+'.gif';
}

// Update the lower panels with information as game progresses.
//
function updatepanel(nums)
{
	var obj = new Array ("leftic","middleic","rightic");
	var flash_wid;
	var obj_flash = new Array ("leftimg","left","rightimg","right");

		hidei('in');
		hidei('out');
		for(var i=1;i<=8;i++)
		{
			hidei('leftimg0'+i);
			hidei('rightimg0'+i);
		}

	switch (nums){
		case '01':
		showi('in');
		showi('out');
		showT('leftimg01');
		showT('rightimg01');
		break;
		case '02':
		hidei('in');
		hidei('out');
		hidei('leftimg02');
		hidei('rightimg02');
		break;
		case '03':
		hidei('in');
		hidei('out');
		hidei('leftimg03');
		hidei('rightimg03');
		break;
		case '04':
		showi('in');
		showi('out');
		showT('leftimg04');
		showT('rightimg04');
		break;
		case '05':
		showi('in');
		showi('out');
		showT('leftimg05');
		showT('rightimg05');
		break;
		case '06':
		showi('in');
		showi('out');
		showT('leftimg06');
		showT('rightimg06');
		break;
		case '07':
		showi('in');
		showi('out');
		showT('leftimg07');
		showT('rightimg07');
		break;
		case '08':
		showi('in');
		showi('out');
		showT('leftimg08');
		showT('rightimg08');
		break;
		default:
		break;
	}
}

function setexterior(zone)
{

if(CurrentT2L=="steelworks.t2l")  // dont hide items if in internal zones.
{  
	for (var i= 1;i<=zone; i++)
	{
		var doors = '0'+i+'doors';
		var walls = '0'+i+'walls';
		var keys = '0'+i+'01keysz';
		disable(keys);
		for (var j=1; j<=5; j++)
		{
			 var spanns = '0'+i+'0'+j+'spann';
			 var spannzones = '0'+i+'0'+j+'infor';
			 hideit(spanns);
			 disable(spannzones);
		}
				
	}
	doors = '0'+zone+'doors';
	walls = '0'+zone+'walls';
	  hideit(doors);
	  disable(walls);
} //if
}

function ZoneExit01() {
 if (infornum >= informax){
 	 disable('Sphere01');
	 fixcamera(); 
	 popup = '07intro';
	 hideit(key);
	 showit(popup);
	 enable('close');
	 LeavingZone6 = true;
	}
}

function ZoneExit02(){
     createFlash(158,420,"flash_1.swf","myFlashmap");
	 FreshStart=0;
	 NextArea=6;
	 createTurnTool(600,374,"steelworks.t2l", "#000000", 0, false);	
}

function ZoneExit03(){
 if (infornum >= informax){
 	 disable('Sphere01');
	 fixcamera(); 
	 popup = '05intro';
	 hideit(key);
	 showit(popup);
	 enable('close');		
	 LeavingZone5 = true;  // used so that the OnReady Listener can redirect the user rather than puting them into Zone 1
     }
 }

function ZoneExit04(){
	 createFlash(158,420,"flash_1.swf","myFlashmap");
	 showi(mapname);
	 FreshStart=0;
	 NextArea=5;
	 showi('click_menu');
	 createTurnTool(600,374,"steelworks.t2l", "#000000", 0, false);
}

function ZoneExit05(){
 if (infornum >= informax){
	disable('Sphere01');
	fixcamera(); 
	popup = '08intro'+movie;
	hideit(key);
	showit(popup);
	if(movie == '01'){
	   enable('yes');
	   enable('no');
	} else {
	   enable('close');
	}
 }
}

function ZoneBlast01(){
	if(infornum < informax) { // Dont allow user to re-enter building if all keys collected.
		hidemap();
		hidei('menu');
		hidei('Processes');
		hidei('Sponsors');
		hidei('click_menu');
		createTurnTool(600,374,"blastfurnace.t2l", "#000000", 0, false);
	}
}

function ZoneBlast02(){  
	createFlash(158,401,"flash_hotmill.swf","myFlashmap");
	hidei('menu');
	hidei('Processes');
	hidei('Sponsors');
	hidei('click_menu');
	hidei('menu');
	showi(mapname);                //if not already showing
	createTurnTool(600,374,"steelworks_hotmill.t2l", "#000000", 0, false);

    //setTimeout("Save('8')", 5000);
	
}

function ZonePrimary(){
	if(infornum < informax) {  // If user has collected all keys then dont let them back in
	clearTimeout(AnimationTimer5);
	clearTimeout(MapTimer);
	createFlash(158,420,"flash_int_1.swf","myFlashmap");
	hidei('menu');
	hidei('Processes');
	hidei('Sponsors');
	hidei('click_menu');
	hidei('menu');
	showi(mapname);                //if not already showing
	createTurnTool(600,374,"steelworks_interior.t2l", "#000000", 0, false);
	}
}

function ShootTop(){
	Frame=0;
	if (CurrentT2L=="steelworks_interior.t2l")
		parent.document.myFlashmap_int.GotoFrame(2);
	TNTDoCommand('Objects(shoot_bottom).SetEnable(false)');
	setTimeout("TNTDoCommand('Objects(shoot_bottom).SetEnable(true)');",5000);   //enable bottom zone in 5 sec
	srcPosX = parseFloat(TNTDoCommand('Objects(shoot_bottom).GetPositionWorldX()'));
	srcPosY = parseFloat(TNTDoCommand('Objects(shoot_bottom).GetPositionWorldY()'));
	srcPosZ = parseFloat(TNTDoCommand('Objects(shoot_bottom).GetPositionWorldZ()'));
	srcRotZ = parseFloat(TNTDoCommand('Objects(shoot_bottom).GetRotationWorldZ()'));
	TNTDoCommand('Objects(Sphere01).SetPositionWorld('+srcPosX+','+srcPosY+','+srcPosZ+')');
	TNTDoCommand('Objects(Sphere01).SetRotationWorld(0,0,'+srcRotZ+')');
}

function ShootBottom(){
	Frame=2;
	if (CurrentT2L=="steelworks_interior.t2l")
		parent.document.myFlashmap_int.GotoFrame(2);
	TNTDoCommand('Objects(shoot_top).SetEnable(false)');
	setTimeout("TNTDoCommand('Objects(shoot_top).SetEnable(true)');",5000);   //enable top zone in 5 sec
	srcPosX = parseFloat(TNTDoCommand('Objects(shoot_top).GetPositionWorldX()'));
	srcPosY = parseFloat(TNTDoCommand('Objects(shoot_top).GetPositionWorldY()'));
	srcPosZ = parseFloat(TNTDoCommand('Objects(shoot_top).GetPositionWorldZ()'));
	srcRotZ = parseFloat(TNTDoCommand('Objects(shoot_top).GetRotationWorldZ()'));
	TNTDoCommand('Objects(Sphere01).SetPositionWorld('+srcPosX+','+srcPosY+','+srcPosZ+')');
	TNTDoCommand('Objects(Sphere01).SetRotationWorld(0,0,'+srcRotZ+')');
}

function bsShootTop(){
	var TempZonNum = Zone_Name.slice(11,12);
	TNTDoCommand('Objects(bshoot_bottom_' + TempZonNum + ').SetEnable(false)');
    setTimeout("TNTDoCommand('Objects(bshoot_bottom_" + TempZonNum + ").SetEnable(true)');",5000); 
	srcPosX = parseFloat(TNTDoCommand('Objects(bshoot_bottom_' + TempZonNum + ').GetPositionWorldX()'));
	srcPosY = parseFloat(TNTDoCommand('Objects(bshoot_bottom_' + TempZonNum + ').GetPositionWorldY()'));
	srcPosZ = parseFloat(TNTDoCommand('Objects(bshoot_bottom_' + TempZonNum + ').GetPositionWorldZ()'));
	srcRotZ = parseFloat(TNTDoCommand('Objects(bshoot_bottom_' + TempZonNum + ').GetRotationWorldZ()'));
	TNTDoCommand('Objects(Sphere01).SetPositionWorld('+srcPosX+','+srcPosY+','+srcPosZ+')');
	TNTDoCommand('Objects(Sphere01).SetRotationWorld(0,0,'+srcRotZ+')');
}	

function bsShootBottom(){
	var TempZonNum = Zone_Name.slice(14,15);
	TNTDoCommand('Objects(bshoot_top_' + TempZonNum + ').SetEnable(false)');
	setTimeout("TNTDoCommand('Objects(bshoot_top_" + TempZonNum + ").SetEnable(true)');",5000);   //enable top zone in 5 sec
	srcPosX = parseFloat(TNTDoCommand('Objects(bshoot_top_' + TempZonNum + ').GetPositionWorldX()'));
	srcPosY = parseFloat(TNTDoCommand('Objects(bshoot_top_' + TempZonNum + ').GetPositionWorldY()'));
	srcPosZ = parseFloat(TNTDoCommand('Objects(bshoot_top_' + TempZonNum + ').GetPositionWorldZ()'));
	srcRotZ = parseFloat(TNTDoCommand('Objects(bshoot_top_' + TempZonNum + ').GetRotationWorldZ()'));
	TNTDoCommand('Objects(Sphere01).SetPositionWorld('+srcPosX+','+srcPosY+','+srcPosZ+')');
	TNTDoCommand('Objects(Sphere01).SetRotationWorld(0,0,'+srcRotZ+')');
}

function ZoneStairs1(){
   if (Frame==0){
	  Frame=1;
	  parent.document.myFlashmap_int.GotoFrame(1);
	} else {
  	  Frame=0;
	  parent.document.myFlashmap_int.GotoFrame(0);	
	}
}

function ZoneStairs2(){
	if (Frame==1){
 	   Frame=2;
	   parent.document.myFlashmap_int.GotoFrame(2);
	} else {
	   Frame=1;
	   parent.document.myFlashmap_int.GotoFrame(1);	
	}
}

// >>> Rather than use the listener, each function has been seperated out and called instantly, this 
// >>> was required for the cookie load/save functionality to work.
// >>> functions now get called from OnZoneEnter()
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

function OnZoneEnter_Listener() {
	// removed and replaced with direct calls (see onZoneEnter func)
}

function Go_Int()
{
 	       
			clearTimeout(MapTimer);
			createFlash(158,420,"flash_int_1.swf","myFlashmap");
			hidei('menu');
			hidei('Processes');
			hidei('Sponsors');
			hidei('click_menu');
			hidei('menu');
			showi(mapname);                //if not already showing		
			createTurnTool(600,374,"steelworks_interior.t2l", "#000000", 0, false);
}

function Go_Blast()
{
			hidemap();
			hidei('menu');
			hidei('Processes');
			hidei('Sponsors');
			hidei('click_menu');			
			createTurnTool(600,374,"blastfurnace.t2l", "#000000", 0, false);
}

function OnZoneExit( zone, physics )
{
    if (zone.slice(0,9)=="speedzone") //slow the speed
	{
		TNTDoCommand('Objects(Sphere01).SetPhysicsMoveSpeed(8988)');
	}
}

function OnKeyPress( keyCode, ascii )
{
	if (keyCode==67 || keyCode==66)
	{
		if(TNTDoCommand('Objects('+popup+').GetVisible()')&&TNTDoCommand('Objects(close).GetMouseClickEvent()'))
		{
			OnClick('close');
			
		}
	}
	
	if (keyCode==1167)
	{
		if (CurrentT2L=="steelworks.t2l")
		{
			IntroLoopMode = 0;
			hidei('loop');
			clearTimeout(IntroLoopTimer);
			Walk_beginning();
		}
		else if (CurrentT2L=="steelworks_interior.t2l")
		{
			IntroLoopMode = 0;
			hidei('loop');
			clearTimeout(IntroLoopTimer);
	        cleartime();

			clearTimeout(IntroTimer1);
			clearTimeout(IntroTimer2);
			clearTimeout(IntroTimer3);
			clearTimeout(IntroTimer3b);
			clearTimeout(IntroTimer4);
			clearTimeout(IntroTimer5);
			clearTimeout(IntroTimer6);
			clearTimeout(IntroTimer7);
			clearTimeout(IntroTimerx);
			
			TNTDoCommand('Objects(Pop_finish).SetVisible(false)');
			
			IntMapObject="Camera01";
			IntMapRotObject="Sphere01";
			
			TNTDoCommand('Objects(Pop_start).SetVisible(false)');
			TNTDoCommand('Objects(Sphere01).SetEnable(true)');
			TNTDoCommand('CameraCtrl.SetCurrent("Camera01")');
		}
		else if (CurrentT2L=="steelworks_hotmill.t2l")
		{
			Walk();
 		}
	}

	if (keyCode==12)
	{

		if (IntroLoopMode==0)
		{
			IntroLoopMode = 1;
			showi('loop');
			OnZoneEnter('Zone_Exit01');
		}
		else
		{
			IntroLoopMode = 0;
			hidei('loop');
			clearTimeout(IntroLoopTimer);
		}
	}
}

function OnKeyRelease( keyCode, ascii )
{
	// 
}

function show(object)
{
    if(element(object))
	{
		element(object).style.visibility = 'visible';
	}
}


function hide(object)
{
    if(element(object))
	{
	    element(object).style.visibility = 'hidden';
	}
}

function hidemap()
{
	hidei('map_ext');
	hidei('map_int');
	hidei('map_hot');
}
 
function ShowMenu()
{
	hidemap();
	show('menu');
	changepic();
}

function HideMenu()
{
	hide('menu');
	hide('Processes');
	hide('Sponsors');
	show('map_ext');
}

function ShowProcess()
{
	changepic();
	element("changeprocess").src="../../../loi/process1.png";
	hide('Sponsors');
	show('Processes');
}

function ShowSponsors()
{
	changepic();
	element("changesponsor").src="../../../loi/sponsors1.png";
	hide('Processes');
	show('Sponsors');
}

function changepic()
{
	element("changeprocess").src="../../../loi/process.png";
	element("changesponsor").src="../../../loi/sponsors.png";
}

function Restart()
{
	setFocus();
	cleartime();

	
	if (CurrentT2L!="steelworks.t2l")
	{
		clearTimeout(IntroTimer1);
		clearTimeout(IntroTimer2);
		clearTimeout(IntroTimer3);
		clearTimeout(IntroTimer3b);
		clearTimeout(IntroTimer4);
		clearTimeout(IntroTimer5);
		clearTimeout(IntroTimer6);
		clearTimeout(IntroTimer7);
		clearTimeout(IntroTimerx);
		hide('Processes');
		showi('click_menu');
		FreshStart=1;
		createFlash(158,420,"flash_1.swf","myFlashmap");
		createTurnTool(600,374,"steelworks.t2l", "#000000", 0, false);
	}
	else
	{
		MapDisplacementVar = 0;
		MapDisplacementVar_phys = 100000;
		TNTDoCommand('SceneGraph.Physics.Reset()');
		TNTDoCommand('Objects(*).StopAnimation()');
		TNTDoCommand('Objects("Popup1_00").SetFrame(100)');
		TNTDoCommand('Objects("Popup1_01").SetFrame(100)');
		TNTDoCommand('Objects("Popup1_02").SetFrame(100)');
		TNTDoCommand('Objects("Popup1_03").SetFrame(100)');
		TNTDoCommand('Objects("Popup1_04").SetFrame(100)');
		TNTDoCommand('Objects("Popup1_05").SetFrame(100)');
		TNTDoCommand('Objects("Popup1_06").SetFrame(100)');
		TNTDoCommand('Objects("Popup1_07*").SetFrame(100)');
		TNTDoCommand('Objects("Popup1_08").SetFrame(100)');
		TNTDoCommand('CameraCtrl.SetCurrent("PhysicsCamera01")');
        GotoArea(1);
		//StartAnimationSequence();
	}
	//show('webcams');
}

function Movie()
{
	if (CurrentT2L=="steelworks.t2l")
	{
		Restart();
	}
	if (CurrentT2L=="steelworks_interior.t2l"||CurrentT2L=="steelworks_hotmill.t2l")
	{
		cleartime();
		clearTimeout(IntroTimer1);
		clearTimeout(IntroTimer2);
		clearTimeout(IntroTimer3);
		clearTimeout(IntroTimer3b);
		clearTimeout(IntroTimer4);
		clearTimeout(IntroTimer5);
		clearTimeout(IntroTimer6);
		clearTimeout(IntroTimer7);
		clearTimeout(IntroTimerx);
		
		TNTDoCommand('Objects(Pop_finish).SetVisible(true)');
		TNTDoCommand('CameraCtrl.SetCurrent("intro_cam_1")');
		
		OnReady();
	}
}


function doPassVar_Map(PosX,PosY,RotZ,PosXC,PosYC,RotZC)
{
	var sendPosX = PosX;
	var sendPosY = PosY;
	var sendRotZ = RotZ; 
	
	var sendPosXC = PosXC;
	var sendPosYC = PosYC;
	var sendRotZC = RotZC;
	
	window.parent.document[flashname].SetVariable("myVarPosX", sendPosX);
	window.parent.document[flashname].SetVariable("myVarPosY", sendPosY);
	window.parent.document[flashname].SetVariable("myVarRotZ", sendRotZ);
	window.parent.document[flashname].SetVariable("myVarPosX2", sendPosXC);
	window.parent.document[flashname].SetVariable("myVarPosY2", sendPosYC);
	window.parent.document[flashname].SetVariable("myVarRotZ2", sendRotZC);
}


function UpdateMap()      //flash map exterior
{
	// physics arrow
	srcPosX = 2300 - parseInt(TNTDoCommand('Objects(Sphere01).GetPositionWorldX()')) + MapDisplacementVar_phys;
	srcPosY = parseInt(TNTDoCommand('Objects(Sphere01).GetPositionWorldY()')) + 7750 + MapDisplacementVar_phys;
	srcRotZ1 = parseInt(TNTDoCommand('Objects(Sphere01).GetRotationLocalZ()'));

	srcRotZ = 180 - srcRotZ1;

	desPosX = (srcPosX * MapXConstant);
	desPosY= (srcPosY * MapYConstant);

	// camera arrow
	srcPosXC = 2300 - parseInt(TNTDoCommand('Objects(Camera02).GetPositionWorldX()')) + MapDisplacementVar;
	srcPosYC = parseInt(TNTDoCommand('Objects(Camera02).GetPositionWorldY()')) + 7750 + MapDisplacementVar;
	srcRotZ1C = parseInt(TNTDoCommand('Objects(Camera02).GetRotationLocalZ()'));

	srcRotZC = 180 - srcRotZ1C;

	desPosXC = (srcPosXC * MapXConstant);
	desPosYC= (srcPosYC * MapYConstant);

	doPassVar_Map(desPosX, desPosY, srcRotZ, desPosXC, desPosYC, srcRotZC);
	
	
	MapTimer = setTimeout("UpdateMap()", 50);
}



function UpdateMapInt()      //flash map interior
{
	// physics arrow
	srcPosX = parseInt(TNTDoCommand('Objects(' + IntMapObject + ').GetPositionWorldX()')) + 187 + MapDisplacementVar_phys;
	srcPosY = 448 - parseInt(TNTDoCommand('Objects(' + IntMapObject + ').GetPositionWorldY()')) + MapDisplacementVar_phys;
	srcRotZ1 = parseInt(TNTDoCommand('Objects(' + IntMapRotObject + ').GetRotationLocalZ()'));
	
	srcRotZ = 180 - srcRotZ1 - 180;
	
	desPosX = (srcPosX * IntMapXConstant);
	desPosY= (srcPosY * IntMapYConstant);
	
	doPassVar_Map(desPosX, desPosY, srcRotZ, -50, -50, -50);
	
	
	MapTimer = setTimeout("UpdateMapInt()", 50);
}

function UpdateMapHotmill()      //flash map interior
{
	aa = parseInt(TNTDoCommand('Objects(' + MillMapObject + ').GetPositionWorldX()'));
	bb = parseInt(TNTDoCommand('Objects(' + MillMapObject + ').GetPositionWorldY()'));
	cc = parseInt(TNTDoCommand('Objects(' + MillMapRotObject + ').GetRotationLocalZ()'));
	// physics arrow
	srcPosX = parseInt(TNTDoCommand('Objects(' + MillMapObject + ').GetPositionWorldX()')) + 6280;
	srcPosY = 50840 - parseInt(TNTDoCommand('Objects(' + MillMapObject + ').GetPositionWorldY()'));
	srcRotZ1 = parseInt(TNTDoCommand('Objects(' + MillMapRotObject + ').GetRotationLocalZ()'));
	
	srcRotZ = -srcRotZ1;
	
	desPosX = (srcPosX * MillMapXConstant);
	desPosY= (srcPosY * MillMapYConstant);
	
	doPassVar_Map(desPosX, desPosY, srcRotZ, -50, -50, -50);
	
	MapTimer = setTimeout("UpdateMapHotmill()", 50);
}

// End of functions.js
