// Custom script
var currentScene = "green_slope";
var timer;
var gWaitingCommand = null;
infoArray = new Array();
infoArray[1] = "<span class='large'>01</span><p>Tensar<i>tech</i>GreenSlope Systems are ideal where existing levels need to be raised with very little or no additional land-take - such as the addition of available land for car parking or development.</p>";
infoArray[2] = "<span class='large'>02</span><p>Prepare the foundation and ensure that the bearing capacity is as required by the design</p>";
infoArray[3] = "<span class='large'>03</span><p>Cut the Tensar Uniaxial geogrid to length from the roll and place the adjacent strips of material on to the formation – no overlaps required.</p>";
infoArray[4] = "<span class='large'>04</span><p>The prefabricated steel facing units should be placed in position to the required alignment and wired together</p>";
infoArray[5] = "<span class='large'>05</span><p>The short steel anchor bars are located behind the longitudinal steel on the base to prevent backward movement of the facing unit when tensioning the geogrid</p>";
infoArray[6] = "<span class='large'>06</span><p>Using a hooked bar, carefully pull the ribs of the uniaxial geogrid through the base of the steel mesh unit to form loops</p>";
infoArray[7] = "<span class='large'>07</span><p>The bodkin anchor can then be inserted through the loops, thereby securely fixing the uniaxial geogrid to the facing unit</p>";
infoArray[8] = "<span class='large'>08</span><p>Using the tensioning beam, ensure that all slack is removed from the bodkin joint created in step 6.  To retain the tension either place fill immediately whilst holding the tension or use locating pins as shown.</p>";
infoArray[9] = "<span class='large'>09</span><p>For a vegetated face the steel facing should be lined with the appropriate material supplied; in this case a geotextile suitable for planting through or hydraseeding.  If a rock finish is specified the face liner may be an appropriate geogrid or nothing at all</p>";
infoArray[10] = "<span class='large'>10</span><p>Locate the diagonal brace bars (3 per unit) to retain the facing unit at the desired angle (usually 70 degrees)</p>";
infoArray[11] = "<span class='large'>11</span><p>Place and compact the structural fill material to a suitable thickness and remove the geogrid locating pins where used.  Remember to leave room at the face for the topsoil if required.  Compaction of the structural fill should be with suitable lightweight compaction plant within 2m of the face.</p>"
infoArray[12] = "<span class='large'>12</span><p>Now place a suitable topsoil or growing medium. Care should be taken not to over-compact the topsoil. The soil should be lightly compacted with a spade as shown or ‘heeled-in’ so as not to exclude all the air content.</p>";
infoArray[13] = "<span class='large'>13</span><p>Repeat the procedure of placing and compacting both structural fill and topsoil, up to the level of the next steel facing unit.  Fold the face liner down over the fill as shown</p>";
infoArray[14] = "<span class='large'>14</span><p>Place the next layer of uniaxial geogrid followed by the steel mesh units, which are located inside the ones below.  Offset the location of the steel face units from those below, as you would with brickwork (often referred to as stretcher bond)</p>";
infoArray[15] = "<span class='large'>15</span><p>The procedure now repeats as before; anchor the units; pull through the geogrid locating the bodkin prior to tensioning the geogrid.  Place and compact both structural fill and topsoil where necessary to the level of the next facing unit and geogrid</p>";
infoArray[16] = "<span class='large'>16</span><p>Fold down the face liner and continue the construction process to the top of the structure. Where the finished face angle necessitates, the face may be terraced to the desired profile</p>";
infoArray[17] = "<span class='large'>17</span><p>The choice of vegetation may vary from grass to ground cover shrubs to climbing plants and depending on the this choice and the time year planting takes place, the structure will ‘green-over’ in due course</p>";
infoArray[18] = "<span class='large'>18</span><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Fusce id libero. Curabitur semper porttitor nunc. Mauris sapien sem, tincidunt et, gravida eget, ullamcorper hendrerit, ipsum.</p>";
infoArray[19] = "<span class='large'>19</span><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Fusce id libero. Curabitur semper porttitor nunc. Mauris sapien sem, tincidunt et, gravida eget, ullamcorper hendrerit, ipsum.</p>";
infoArray[20] = "<span class='large'>20</span><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Fusce id libero. Curabitur semper porttitor nunc. Mauris sapien sem, tincidunt et, gravida eget, ullamcorper hendrerit, ipsum.</p>";
infoArray[21] = "<span class='large'>21</span><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Fusce id libero. Curabitur semper porttitor nunc. Mauris sapien sem, tincidunt et, gravida eget, ullamcorper hendrerit, ipsum.</p>";
infoArray[22] = "<span class='large'>22</span><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Fusce id libero. Curabitur semper porttitor nunc. Mauris sapien sem, tincidunt et, gravida eget, ullamcorper hendrerit, ipsum.</p>";
infoArray[23] = "<span class='large'>23</span><p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Fusce id libero. Curabitur semper porttitor nunc. Mauris sapien sem, tincidunt et, gravida eget, ullamcorper hendrerit, ipsum.</p>";
infoArray[51] = "<span class='large'>01</span><p>Hydraseeding</p>";
infoArray[61] = "<span class='large'>01</span><p>Irrigation</p>";
infoArray[62] = "<span class='large'>01</span><p>Irrigation - Close up on system</p>";
infoArray[71] = "<span class='large'>01</span><p>Planting</p>";

function viewSingle() {
	clearTimeout(timer);
	
	if(currentScene != "green_slope") loadScene("green_slope");
	
	swapping = true;
	Restart();
	setInfo(1);	
}

// Sets information bar
function setInfo(num) {
	element('info').innerHTML = infoArray[num];
}
function commandWaiting(command) {
	// Sets the command waiting to the command supplied, this will be executed when the onReady() state of
	// of the 3D scene is true. Commands can not be executed before this is the case, therefore a wait is necessary.
	
	gWaitingCommand = command;
}	
function playStage(theStage) {
	// element('TNTCtrl').src = "tnt/animate.tnt";
	swapping = true;	
	clearTimeout(timer);
	if(currentScene != "green_slope") {
		currentScene = "green_slope";
		commandWaiting("playStage(" + theStage + ")");
		loadScene("green_slope");
	}
	else {
		switch(theStage) {
			case 1:
				from = '0';
				to = '100';
				setInfo(1);
			break
			case 2:
				from = '100';
				to = '150';			
				setInfo(2);			
			break
			case 3:
				from = '150';
				to = '375';			
				setInfo(3);			
			break
			case 4:
				from = '375';
				to = '575';			
				setInfo(4);				
			break		
			case 5:
				from = '575';
				to = '675';			
				setInfo(5);				
			break
			case 6:
				from = '675';
				to = '1120';			
				setInfo(6);				
			break
			case 7:
				from = '1120';
				to = '1170';			
				setInfo(7);				
			break
			case 8:
				from = '1170';
				to = '1455';			
				setInfo(8);				
			break
			case 9:
				from = '1455';
				to = '1730';			
				setInfo(9);				
			break
			case 10:
				from = '1730';
				to = '1855';			
				setInfo(10);				
			break
			case 11:
				from = '1855';
				to = '2475';			
				setInfo(11);				
			break
			case 12:
				from = '2475';
				to = '2745';			
				setInfo(12);				
			break
			case 13:
				from = '2745';
				to = '3145';			
				setInfo(13);				
			break
			case 14:
				from = '3145';
				to = '3255';			
				setInfo(14);				
			break		
			case 15:
				from = '3255';
				to = '3700';			
				setInfo(15);				
			break
			case 16:
				from = '3700';
				to = '4000';			
				setInfo(16);				
			break
			case 17:
				from = '4000';
				to = '4550';			
				setInfo(17);				
			break
		}
		TNTDoCommand('Objects("*").PlayAnimation('+from+','+to+',false,20)');
	}
	
}

var swapping = false;
function playAll() {
	
	clearTimeout(timer);
	
	resetSlider();
	
	swapping = true;
	
	if(currentScene == "green_slope") {
		TNTDoCommand('Objects("*").PlayAnimation(0,4550,false,20)');
	}
	else {
		loadScene("green_slope");
	}

	getFrame();
}

// recursive function to get current frame number
function getFrame() {
	clearTimeout(timer);
	frmcnt = TNTDoCommand('Objects("*").GetFrame()');
	reportStage(frmcnt);
	timer = setTimeout("getFrame()",1000);	
}

// called by getFrame() to display the current stage number
function reportStage(theFrame) {
	// 1
	if(theFrame >= 1 && theFrame < 100) {
		setInfo('1');
		currentStage = 1;
	}
	// 2
	if(theFrame >= 100 && theFrame < 150) {
		setInfo('2');	
		currentStage = 2;
	}
	// 3
	if(theFrame >= 150 && theFrame < 375) {
		setInfo('3');
		currentStage = 3;
	}
	// 4
	if(theFrame >= 375 && theFrame < 575) {
		setInfo('4');	
		currentStage = 4;
	}
	// 5
	if(theFrame >= 575 && theFrame < 675) {
		setInfo('5');	
		currentStage = 5;
	}
	// 6
	if(theFrame >= 675 && theFrame < 1120) {
		setInfo('6');	
		currentStage = 6;
	}
	// 7
	if(theFrame >= 1120 && theFrame < 1170) {
		setInfo('7');	
		currentStage = 7;
	}
	// 8
	if(theFrame >= 1170 && theFrame < 1455) {
		setInfo('8');	
		currentStage = 8;		
	}
	// 9
	if(theFrame >= 1455 && theFrame < 1730) {
		setInfo('9');	
		currentStage = 9;		
	}
	// 10
	if(theFrame >= 1730 && theFrame < 1855) {
		setInfo('10');
		currentStage = 10;		
	}	
	// 11
	if(theFrame >= 1855 && theFrame < 2475) {
		setInfo('11');
		currentStage = 11;		
	}	
	// 12
	if(theFrame >= 2475 && theFrame < 2745) {
		setInfo('12');
		currentStage = 12;		
	}	
	// 13
	if(theFrame >= 2745 && theFrame < 3145) {
		setInfo('13');
		currentStage = 13;		
	}	
	// 14
	if(theFrame >= 3145 && theFrame < 3255) {
		setInfo('14');
		currentStage = 14;		
	}
	// 15
	if(theFrame >= 3255 && theFrame < 3700) {
		setInfo('15');
		currentStage = 15;		
	}	
	// 16
	if(theFrame >= 3700 && theFrame < 4000) {
		setInfo('16');
		currentStage = 16;		
	}
	// 17
	if(theFrame >= 4000 && theFrame < 4550) {
		setInfo('17');
		currentStage = 17;	
	}
}
function loadScene(scene) {
	
	// Turntool Parameters
	width = 639;
	height = 409;
	color = "#FFFFFF";
	transparent = 0;
	install = 0;
	
	switch(scene) {
		case "hydraseeding":
			createTurnTool(width, height, "tnt/green_slope_hydraseeding.tnt", color, transparent, install);
		break;
		case "irrigation":
			createTurnTool(width, height, "tnt/green_slope_irrigation.tnt", color, transparent, install);
		break;
		case "irrigationCloseUp":
			createTurnTool(width, height, "tnt/green_slope_irrigation.tnt", color, transparent, install);
		break;
		case "green_slope":
			createTurnTool(width, height, "tnt/green_slope.tnt", color, transparent, install);
		break;
		case "planting":
			createTurnTool(width, height, "tnt/green_slope_planting.tnt", color, transparent, install);
		break;
	}
}
function hydraseeding() {
	if(currentScene != "hydraseeding") {
		currentScene = "hydraseeding";
		loadScene("hydraseeding");
	}
	else {
		TNTDoCommand('CameraCtrl.SetCurrent("Camera01")');
		TNTDoCommand('Objects("Plane05").PlayAnimation(0,400,false)');
		TNTDoCommand('Objects("water").PlayAnimation(0,30,true)');
		TNTDoCommand('Objects("line01").PlayAnimation(0,400,true)');
		TNTDoCommand('Objects("hose").PlayAnimation(0,400,true)');
		TNTDoCommand('ObjectTree("[man]").PlayAnimation(0,400,true)');
	}
	setInfo(51);
}
function irrigation() {
	if(currentScene == "irrigation") {
	   TNTDoCommand('CameraCtrl.SetCurrent("Camera01")');
	   TNTDoCommand('Objects("Object01").PlayAnimation(0,400,false)');
	   TNTDoCommand('Objects("Camera01").PlayAnimation(0,400,true)');
	   TNTDoCommand('ObjectTree("[drip]").PlayAnimation(0,30,true)');
	}
	else {
		currentScene = "irrigation";
		loadScene("irrigation");
	}
	setInfo(61);
}
function irrigationCloseUp() {
	
	if(currentScene == "irrigationCloseUp") {
		TNTDoCommand('CameraCtrl.SetCurrent("Camera02")');
		TNTDoCommand('ObjectTree("[drip]").PlayAnimation(0,30,true)');
	}
	else {
		currentScene = "irrigationCloseUp";
		loadScene("irrigationCloseUp");	
	}
	setInfo(62);
}
function planting() {
	if(currentScene == "planting") {
		TNTDoCommand('CameraCtrl.SetCurrent("Camera01")');
		TNTDoCommand('Objects("*").PlayAnimation(0,250,false)');
	}
	else {
		currentScene = "planting";
		loadScene("planting");
				
	}
	setInfo(71);
}
// Sets status message
function setStatus(message) {
	window.status = message;
}
