// JavaScript Document

		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 			= 668;
			var tntHeight 			= 320;
			var tntFilename 		= "http://homepage.ntlworld.com/stewart.willis/pdg/3dfiles/freshice01.tnt";
			var tntColor 			= "#FFFFFF";
			var tntTransparent 		= 0;
			var h_layout            = "http://www.directfromdevelopers.com/images/bg1.gif"
			var tntInstalled 		= isTurnToolInstalled();
			if (tntInstalled==false)
			{
				document.getElementById('TurnTool_Message').innerHTML = 'You need to install the TurnTool viewer to view our interactive 3D properties. If the image does not load click on the following button, and press RUN:';
				createTurnTool(h_layout,tntWidth,tntHeight,tntFilename,tntColor,tntTransparent,true);
				checkRefresh();
			}
			else
				createTurnTool(h_layout,tntWidth,tntHeight,tntFilename,tntColor,tntTransparent,false);
		}
		
		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/OfflineInstall.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>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 focus()
		{
			var tntCtrl = element("TNTCtrl");
			if(tntCtrl && tntCtrl.ready)
			{
				tntCtrl.focus();
			}
		}
		
		function doCommand()
		{
			var retval = TNTDoCommand( element("doCommandEdit").value );
			if(retval)
				element("returnval").innerHTML = 'Return Value = "' + retval + '"';
			else
				element("returnval").innerHTML = "";
		}
		

		



		
		function Restart()
		{
			TNTDoCommand('SceneGraph.Physics.Reset()');
			TNTDoCommand('Objects(*).StopAnimation()');
			TNTDoCommand('Objects(*).SetFrame(0)');
			cameraName = TNTDoCommand('SceneGraph.Camera(0).GetName()');
			TNTDoCommand('CameraCtrl.SetCurrent("'+ cameraName+'")');
		}
		



		


		

		

		
		function saveImage()
		{
		   
			TNTDoCommand('Renderer.SaveImage("ScreenShot.bmp",2)')
		}
		
		function addEvent( obj, type, fn )
		{
			if (obj.addEventListener)
		 		obj.addEventListener( type, fn, false );
		 	else if (obj.attachEvent)
		 	{
			  obj["e"+type+fn] = fn;
			  obj.attachEvent( "on"+type, function() { obj["e"+type+fn](); } );
		 	}
		}
		
		function removeEvent( obj, type, fn )
		{
			if (obj.removeEventListener)
		  	obj.removeEventListener( type, fn, false );
		 	else if (obj.detachEvent)
		 	{
			  obj.detachEvent( "on"+type, obj["e"+type+fn] );
			  obj["e"+type+fn] = null;
		 	}
		}


var clockID = 0;


	
		function xy_pos()
		{
		
		   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }

   clockID = setTimeout("xy_pos()", 10);
   
		var startx = 439
		var starty = 2261
		var screenx= 500
		var screeny= 320
var cameraname = TNTDoCommand('SceneGraph.Camera(0).GetName()');
var xPos = ((TNTDoCommand('Objects("Camera01").GetPositionWorldX()') - startx)/4); 
var yPos = ((TNTDoCommand('Objects("Camera01").GetPositionworldy()') - starty)/4);
//var datatesting = ' x' + xPos + ' y' + yPos + ' ';
var datatesting = xPos;
//document.getElementById('testdatax').innerHTML=Math.round(yPos)+screenx;
//document.getElementById('testdatay').innerHTML=Math.round(xPos)+screeny;
element("Layer1").style.left = screenx-yPos;
element("Layer1").style.top = screeny-xPos;
		}
		

function StartClock() {
   clockID = setTimeout("xy_pos()", 10);
}

function KillClock() {
   if(clockID) {
      clearTimeout(clockID);
      clockID  = 0;
   }
}


addEvent(window,"load",initTurnTool);

function isvisible(objname) {

if (TNTDoCommand('Objects('  + TNTDoCommand('SceneGraph.Mesh(' + objname + ').GetName()') + ').getVisible()')==1)
{
TNTDoCommand('Objects('  + TNTDoCommand('SceneGraph.Mesh(' + objname + ').GetName()') + ').SetVisible(0)')
}
else
{TNTDoCommand('Objects('  + TNTDoCommand('SceneGraph.Mesh(' + objname + ').GetName()') + ').SetVisible(1)')
}
}

function changetexture(texture,filen) {
//texture="5";
TNTDoCommand('SceneGraph.Bitmap('+ texture +').Load("'+filen+'")');

}

function GuideTour()
{
	var frameCount = TNTDoCommand('SceneGraph.GetFrameCount()');
	TNTDoCommand('Objects(Camera02).PlayAnimation(0,'+frameCount+',true)');
	TNTDoCommand('CameraCtrl.SetCurrent("Camera02")');
	currCamera = 'Camera02';
	TNTDoCommand('ObjectTree("Camera*").SetEnable(false)');
	TNTDoCommand('ObjectTree("Camera02").SetEnable(true)');
}

		
