﻿// insert_media.js
//
// Modified to include tickertape text for the LOI chinese game.
// True2Life Ltd - August 21st 2009
// Geoff Coope (geoff.coope@true2life.co.uk)
// Version 1.3 -  01/09/09
// --------------------------------------------------------------------------

// Typewritter effect

function type()
{
  if (document.getElementById)
  {
    var dest=document.getElementById(destination);
    if (dest)
    {
      dest.innerHTML=text.substr(0, currentChar);
      currentChar++
      if (currentChar<=text.length)
        t = setTimeout("type()", delay);  	
    }
  }
}

function startTyping(textParam, delayParam, destinationParam)
{
  //clearTimers();
  text=textParam;
  delay=5;
  currentChar=1;
  destination=destinationParam;
  type();

  // Clear the intro line in 10 seconds....
  setTimeout("clearTimerCHI();",11000);   
}

function clearTimerCHI(){

	if(element("ticker"))
		element("ticker").innerHTML = '';
		
}


function createFlash(width, height, file, id)
{
		hidei('map_ext');
		hidei('map_int');
		hidei('map_hot');
		//alert('a')
		switch (file) {
			case 'flash_1.swf':
			mapname= 'map_ext';
			showi(mapname);
			flashname = "myFlashmap_ext"
			break;
			case 'flash_int_1.swf':
			mapname= 'map_int';
			showi(mapname);
			flashname = "myFlashmap_int"
			break;
			case 'flash_hotmill.swf':
			mapname= 'map_hot';
			showi(mapname);
			flashname = "myFlashmap_hot"
			break;
			default:
			break;
			
		}
	
}

function createTurnTool(width, height, file, color, transparent, install)
{
  var DownloadText = "Downloading True2Life Resource";
  var CoreDownloadText = "True2Life Viewer Update Downloading";
  var SetLogo = "None";
  
  var turntoolObject = ''
  if (install)
  {
    turntoolObject = '<center><input type="button" value="Install True2Life Viewer" onclick="installTurnTool();" /></center>';
  }
  if (ie4||ie5)
  {
  	turntoolObject += '<object id="TNTCtrl" width="'+width+'" height="'+height+'" classid="CLSID:402ee96e-2ce8-482d-ada5-ceceea07e16d" codebase="http://www.true2life.co.uk/ViewerInstall.exe#version=2,12,0,8"><param name="transparent" value="'+transparent+'"><param name="ctrl_color" value="'+color+'"><param name="tnt_back_color" value="'+color+'"><param name="src" value="../../../loi/'+file+'"><param name="script" value="ProgressBar.SetDownloadText(\''+DownloadText+'\');ProgressBar.SetCoreDownloadText(\''+CoreDownloadText+'\');TNTCtrl.SetLogo(\''+SetLogo+'\')"></OBJECT>';
  	turntoolObject += '<scr'+'ipt type="text/javascript" for="TNTCtrl" event="TNTEvent(string);">execScript(string);</scr'+'ipt>';
  }
  else
  {
      if (install==false)
      {
	  	turntoolObject += '<embed id="TNTCtrl" width="'+width+'" height="'+height+'" src="../../../loi/'+file+'" transparent="0" ctrl_color="'+color+'" tnt_back_color="'+color+'" pluginspage="http://www.true2life.co.uk/download/" type="application/tntfile" script="ProgressBar.SetDownloadText(\''+DownloadText+'\');ProgressBar.SetCoreDownloadText(\''+CoreDownloadText+'\');TNTCtrl.SetLogo(\''+SetLogo+'\')"></embed>';
	    
		}
  }
  CurrentT2L = file;
  
  if(element('TurnTool'))
  {
	  element('TurnTool').innerHTML = '';
	  element('TurnTool').innerHTML = turntoolObject;
  }



}

function insert()
{
	
	insertflash('map_ext','myFlashmap_ext','flash_1.swf');
	insertflash('map_int','myFlashmap_int','flash_int_1.swf');
	insertflash('map_hot','myFlashmap_hot','flash_hotmill.swf');

	insertbar('sidebar','navigation.swf','122','234');


	insertmovie('t2lmovie', 'intro.swf');
	insertmovie('endmovie', 'end.swf');
	

	if(element("ticker")) // Element ticker should only be available on Chinese pages!
	{
		//var a = setTimeout("startTyping('你已经了解铁矿石是如何被开采，破碎和运输到钢厂的。现在让我们共同探索和揭秘铁矿石是如何转变成钢的，祝好运！', 10, 'ticker');",1000); // should be 120000
		var a = setTimeout("startTyping('&#20320;&#24050;&#32463;&#20102;&#35299;&#38081;&#30719;&#30707;&#26159;&#22914;&#20309;&#34987;&#24320;&#37319;&#65292;&#30772;&#30862;&#21644;&#36816;&#36755;&#21040;&#38050;&#21378;&#30340;&#12290;&#29616;&#22312;&#35753;&#25105;&#20204;&#20849;&#21516;&#25506;&#32034;&#21644;&#25581;&#31192;&#38081;&#30719;&#30707;&#26159;&#22914;&#20309;&#36716;&#21464;&#25104;&#38050;&#30340;&#65292;&#31069;&#22909;&#36816;&#65281;', 10, 'ticker');",120000); 

}

}

function insertflash(aaa, id, file)
{
	if(ie4||ie5)
	{
		var t2lflash = '<object id="'+id+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="158" height="420">';
		t2lflash += '  <param name="movie" value="../../../loi/'+file+'" /><param name="quality" value="high" /><param name="PLAY" value="false" /><param name="swliveconnect" value="true" /><embed name="myFlashmap_ext" src="../../../loi/'+file+'" width="158" height="420" quality="high" play="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" swliveconnect="true"></embed>';
		t2lflash += '</object>';
		
		if(element(aaa))
		{
			element(aaa).innerHTML = t2lflash;
		}
		
	} 
}


function insertbar(aaa,file,width,height)
{
	if(ie4||ie5)
	{
		var t2lflash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+width+'" height="'+height+'">';
		t2lflash += '  <param name="movie" value="../../../loi/'+file+'" /><param name="quality" value="high" /><param name="PLAY" value="false" /><param name="swliveconnect" value="true" /><embed src="../../../loi/'+file+'" width="'+width+'" height="'+height+'" quality="high" play="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" swliveconnect="true"></embed>';
		t2lflash += '</object>';
		
		if(element(aaa))
		{
			element(aaa).innerHTML = t2lflash;
		}
	}
}

function inserttflash(aaa,file,width,height)
{

	if(ie4||ie5)
	{
		var t2lflash = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+width+'" height="'+height+'">';
		t2lflash += '  <param name="movie" value="../../../loi/ttfla/'+file+'" /><param name="quality" value="high" /><param name="PLAY" value="false" /><param name="swliveconnect" value="true" /><embed src="../../../loi/'+file+'" width="'+width+'" height="'+height+'" quality="high" play="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" swliveconnect="true"></embed>';
		t2lflash += '</object>';
		
		if(element(aaa))
		{
			element(aaa).innerHTML = t2lflash;
		}
		if(elementi(aaa))
		{
			elementi(aaa).innerHTML = t2lflash;
		}
	}
}

function insertinout()
{
	inserttflash('in','in.swf',58,30);
	inserttflash('out','out.swf',62,31);
	var flash_wid = new Array(0,110,110,110,110,216,216,216,110);
	
	for(var i=1;i<=8;i++)
	{
		var obj_divfla = 'leftimg0'+i;
		var obj_ttfla = 'leftimg0'+i+'.swf';
		inserttflash(obj_divfla,obj_ttfla,flash_wid[i],50);
		
		obj_divfla = 'rightimg0'+i;
		obj_ttfla = 'rightimg0'+i+'.swf';
		inserttflash(obj_divfla,obj_ttfla,110,50);
	}




//	inserttflash('in','in.swf',58,30);
//	inserttflash('out','out.swf',58,30);
//	inserttflash('leftimg','leftimg01.swf',110,50);
//	inserttflash('rightimg','rightimg01.swf',110,50);

//	inserttt('TNTCtrlin','in','in.t2l',58,30);
//	inserttt('TNTCtrlout','out','out.t2l',58,30);
//	inserttt('TNTCtrlleft','leftimg','left01.t2l',110,50);
//	inserttt('TNTCtrlleftl','leftimg01','left05.t2l',216,50);
//	inserttt('TNTCtrlright','rightimg','right01.t2l',110,50);
}

function inserttt(id,aaa,file,width,height)
{
	  var DownloadText = "Downloading True2Life Resource";
	  var CoreDownloadText = "True2Life Viewer Update Downloading";
	  var SetLogo = "None";
	  var obj_tt = '';
	
  if (ie4||ie5)
  {
	obj_tt += '<object id="'+id+'" width="'+width+'" height="'+height+'" classid="CLSID:402ee96e-2ce8-482d-ada5-ceceea07e16d" codebase="http://www.true2life.co.uk/ViewerInstall.exe#version=2,12,0,8">';
	obj_tt += '<param name="src" value="../../../loi/inout/'+file+'"><param name="script" value="ProgressBar.SetDownloadText(\''+DownloadText+'\');ProgressBar.SetCoreDownloadText(\''+CoreDownloadText+'\');TNTCtrl.SetLogo(\''+SetLogo+'\')">';
	obj_tt += '</OBJECT>';
  }
  else
  {
	obj_tt += '<embed id="'+id+'" width="'+width+'" height="'+height+'" src="../../../loi/inout/'+file+'" transparent="0" pluginspage="http://www.true2life.co.uk/download/" type="application/tntfile" script="ProgressBar.SetDownloadText(\''+DownloadText+'\');ProgressBar.SetCoreDownloadText(\''+CoreDownloadText+'\');TNTCtrl.SetLogo(\''+SetLogo+'\')"></embed>';
  }
	
	if(element(aaa))
	{
		element(aaa).innerHTML = obj_tt;
	}
	if(elementi(aaa))
	{
		elementi(aaa).innerHTML = obj_tt;
	}
}

function insertmovie(bbb, file)
{
	if(ie4||ie5)
	{
		var t2lmovie = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="600" height="420">';
		t2lmovie += '<param name="movie" value="../../../loi/movie/'+file+'" />';
		t2lmovie += '<param name="quality" value="high" />';
		t2lmovie += '<param name="allowScriptAccess" value="always"/>';
		t2lmovie += '<embed src="../../../loi/movie/'+file+'" allowScriptAccess="always" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="600" height="420"></embed>';
		t2lmovie += '</object>';
		
		if(file == 'intro.swf')
		{
			t2lmovie +=	'<div id="Layer1">';
			t2lmovie +=	'<table width="120" border="0" cellspacing="0" cellpadding="0">';
  			t2lmovie +=	'<tr>    <td><div class="navigationbaritem">Navigation</div></td>    </tr>';
  			t2lmovie +=	'<tr>    <td><img src="../../../loi/navigation.png" width="120" height="142" /></td>    </tr>';
  			t2lmovie +=	'<tr>    <td><div class="navigationbaritem">Options&nbsp;Webcams</div></td>    </tr>';
  			t2lmovie +=	'<tr>    <td><div id="sidebar"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="122" height="234">';
      		t2lmovie +=	'<param name="movie" value="../../../loi/navigation.swf" />';
      		t2lmovie +=	'<param name="quality" value="high" />';
      		t2lmovie +=	'<embed src="../../../loi/navigation.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="122" height="234"></embed>';
    		t2lmovie +=	'</object></div></td>    </tr>';
			t2lmovie +=	'</table>';

		}
		
		if(element(bbb))
		{
			element(bbb).innerHTML = t2lmovie;
		}
		
	}
}

function firefoxmovie(bbb, file)
{
		var t2lmovie = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="600" height="420">';
		t2lmovie += '<param name="movie" value="../../../loi/movie/'+file+'" />';
		t2lmovie += '<param name="quality" value="high" />';
		t2lmovie += '<param name="allowScriptAccess" value="always"/>';
		t2lmovie += '<embed src="../../../loi/movie/'+file+'" allowScriptAccess="always" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="600" height="420"></embed>';
		t2lmovie += '</object>';
		
		if(element(bbb))
		{
			element(bbb).innerHTML = t2lmovie;
		}
		
		if(elementi(bbb))
		{
			elementi(bbb).innerHTML = t2lmovie;
		}
		
}

function intromovie()
{
	setTimeout("hide('t2lmovie');",6000);
	setTimeout("show('maint2l');",6600);
	setTimeout("insertmaint2l();",6600);
	setTimeout("insertinout();",6600);
}

function insertmaint2l()
{
	element('ttframe').src = maint2lobj+'t2l.htm'
}

///////// firefoxmovie('endmovie', 'end.swf');??
function endmovie()
{

	if(elementi('endmovie'))
	{
	  element('TurnTool').innerHTML = "";
	  element('navbar').innerHTML = "";
	  	
		hidei('in');
		hidei('out');
		//////just same with previous version
		hidei('map_hot');
		showi('map_ext');
		
		for(var i=1;i<=8;i++)
		{
			hidei('leftimg0'+i);
			hidei('rightimg0'+i);
		}


	}
	else
	{
		quiz(); 
	}
	
	showi('endmovie');
///////// firefoxmovie('endmovie', 'end.swf');??
	firefoxmovie('endmovie', 'end.swf');///////// firefoxmovie('endmovie', 'end.swf');??
///////// firefoxmovie('endmovie', 'end.swf');??
///////// firefoxmovie('endmovie', 'end.swf');??
///////// firefoxmovie('endmovie', 'end.swf');??

		
		
}

function quiz()
{
	  //hide('endmovie');
	  var divobj;
	  
	divobj = '<p></p><p></p><p></p><CENTER>Do you want to take the test?<br>';
	divobj +='<INPUT TYPE=button VALUE="YES" onClick="javascript:location=\'http://www.steeluniversity.org/content/html/eng/default.asp?catid=189&pageid= 2081272173\'">';
	divobj +='<INPUT TYPE=button VALUE="NO" onClick="javascript:location=\'index.html\'"></CENTER>';
	
	if(element('endmovie'))
		element('endmovie').innerHTML =divobj;
//	element('TurnTool').innerHTML =divobj;
}



function fixcamera()
{
	//TNTDoCommand('Objects(Camera01).SetRotationWorld(0,0,0)');

	TNTDoCommand('CameraCtrl.SetRotationSpeedX(0)')
	TNTDoCommand('CameraCtrl.SetRotationSpeedY(0)')
	TNTDoCommand('CameraCtrl.SetRotationSpeedZ(0)')
	
	
	
}

function recamera()
{
	TNTDoCommand('CameraCtrl.SetRotationSpeedX(0)')
	TNTDoCommand('CameraCtrl.SetRotationSpeedY(0.007)')
	TNTDoCommand('CameraCtrl.SetRotationSpeedZ(0)')
	
}




////////////////in out for iframe
function elementi(id)
{
	if(ie4)	// Explorer 4
		return parent.document.all[id];
	else	// Explorer 5+ Netscape 6+ and Mozilla and Firefox
		return parent.document.getElementById(id);
}


var showtimer1;
var showtimer2;
var showtimer3;

function showT(object, nums,width,height)
{
    if(elementi(object))
	{
		elementi(object).style.visibility = 'visible';
		//element(object).style.z-index = 8;
	}
	
//	var file = object+nums+'.swf';
//	
//	inserttflash(object,file,width,height);
	
	//alert('s')
//	showtimer1 = setTimeout("elementi(\"TNTCtrlleft\").TNTDoCommand('SceneGraph.Bitmap(\"left01\").Load(\"../../../loi/inout/left"+nums+".png\")');",500);
//	showtimer2 = setTimeout("elementi(\"TNTCtrlright\").TNTDoCommand('SceneGraph.Bitmap(\"right01\").Load(\"../../../loi/inout/right"+nums+".png\")');",500);
//
//	showtimer3 = setTimeout("elementi(\"TNTCtrlleftl\").TNTDoCommand('SceneGraph.Bitmap(\"left05\").Load(\"../../../loi/inout/left"+nums+".png\")');",500);

	

}

function showi(object)
{
    if(elementi(object))
	{
		elementi(object).style.visibility = 'visible';
 	}
}


function hidei(object)
{
    if(elementi(object))
	{
	    elementi(object).style.visibility = 'hidden';
 	}
	
//	if(object == 'map_int')
//	   {
//		elementi('Submit').click();
//	   }
}

