var strRollOver = '';
var aryTerrains = new Array();
aryTerrains[0] = 'Choose a terrain';
aryTerrains[1] = 'Stable Ground';
aryTerrains[2] = 'Earthquake Zone';
aryTerrains[3] = 'River';
aryTerrains[4] = 'Permafrost';

function initSafety(){
	if(!document.getElementById){ return; }
	var strPipeSelects = '';
	strPipeSelects += '<a id="lnk_manual_tab" href="safety_guide_1.html"><img id="guide" src="images/safety/survey_guide.gif" width="30" height="130" alt="Survey Guide" class="roll f_right" /></a>';
	strPipeSelects += '<p><img id="p1" src="images/safety/pipe_bridge_over.gif" width="75" height="38" alt="Bridge-Supported Pipe" title="Bridge-Supported Pipe" class="f_left" />' + uiReturnSelect('pipe_1') + '<br class="l_clear" /></p>';
	strPipeSelects += '<p id="rolltxt_1">&nbsp;</p>';
	strPipeSelects += '<p><img id="p2" src="images/safety/pipe_refrigerated_over.gif" width="75" height="35" alt="Refrigerated Buried Pipe" title="Refrigerated Buried Pipe" class="f_left" />' + uiReturnSelect('pipe_2') + '<br class="l_clear" /></p>';
	strPipeSelects += '<p id="rolltxt_2">&nbsp;</p>';
	strPipeSelects += '<p><img id="p3" src="images/safety/pipe_zigzag_over.gif" width="75" height="50" alt="Above-Ground Zigzags" title="Above-Ground Zigzags" class="f_left" />' + uiReturnSelect('pipe_3') + '<br class="l_clear" /></p>';
	strPipeSelects += '<p id="rolltxt_3">&nbsp;</p>';
	strPipeSelects += '<p><img id="p4" src="images/safety/pipe_buried_over.gif" width="75" height="28" alt="Buried Pipe" title="Buried Pipe" class="f_left" />' + uiReturnSelect('pipe_4') + '<br class="l_clear" /></p>';
	strPipeSelects += '<p id="rolltxt_4">&nbsp;</p>';
	if(document.getElementById('pipes')){ document.getElementById('pipes').innerHTML = strPipeSelects; }

	initSelects();

	// manual btns
	document.getElementById('lnk_manual').onclick = function() { return uiShowGuide1(); };
	document.getElementById('lnk_manual_tab').onclick = function() { return uiShowGuide1(); };
}

function uiReturnSelect(newID){
	var strOut = '<select id="' + newID + '" size="1">';
//	strOut += '<option value="' + newID + 'optnone" selected="selected">Choose a project</option>';
	for(var i=0; i<aryTerrains.length; i++){
		strOut += '<option value="' + newID + 'opt' + i + '">' + aryTerrains[i] + '</option>';
	}
	strOut += '</select>';
	return strOut;
}

function initSelects(){
	document.getElementById('pipe_1').onchange = function (){
		if(this.selectedIndex == 3){
			uiFeedbackCorrect(this.id);
		} else {
			uiFeedbackIncorrect(this.id, this.selectedIndex);
		}
	}
	document.getElementById('pipe_2').onchange = function (){
		if(this.selectedIndex == 4){
			uiFeedbackCorrect(this.id);
		} else {
			uiFeedbackIncorrect(this.id, this.selectedIndex);
		}
	}
	document.getElementById('pipe_3').onchange = function (){
		if(this.selectedIndex == 2){
			uiFeedbackCorrect(this.id);
		} else {
			uiFeedbackIncorrect(this.id, this.selectedIndex);
		}
	}
	document.getElementById('pipe_4').onchange = function (){
		if(this.selectedIndex == 1){
			uiFeedbackCorrect(this.id);
		} else {
			uiFeedbackIncorrect(this.id, this.selectedIndex);
		}
	}
}

function uiFeedbackCorrect(pipeId){
	var strFeedback = '';
	var strTerrain = '';
	switch(pipeId){
	case 'pipe_1': // bridge supported
		strFeedback = 'Right! A bridge will span the gorge and the river.';
		document.getElementById('rolltxt_1').innerHTML = strFeedback;
		strTerrain += '<p id="terrain_river-on" class="f_left">';
		strTerrain += '<a id="lnk_terrain-river" href="#"><span>This river runs through a deep gorge, downstream from a glacier.</span></a>';
		strTerrain += '<img src="images/safety/correct_river_pipe.gif" width="97" height="35" alt="Bridge-Supported Pipe" title="Bridge-Supported Pipe" />';
		strTerrain += '</p>';
		document.getElementById('terrain_3').innerHTML = strTerrain;
		break;
	case 'pipe_2': // refrigerated
		strFeedback = 'You got it! A refrigerated pipeline will keep the oil\'s heat from damaging permafrost.';
		document.getElementById('rolltxt_2').innerHTML = strFeedback;
		strTerrain += '<p id="terrain_permafrost-on" class="f_left">';
		strTerrain += '<a id="lnk_terrain-permafrost" href="#"><span>Terrain with a deep layer of permafrost.</span></a>';
		strTerrain += '<img src="images/safety/correct_permafrost_pipe.gif" width="96" height="35" alt="Refrigerated Buried Pipe" title="Refrigerated Buried Pipe" />';
		strTerrain += '</p>';
		document.getElementById('terrain_4').innerHTML = strTerrain;
		break;
	case 'pipe_3': // zigzag
		strFeedback = 'Nicely done. This design will survive earthquakes up to 8.5 on the Richter scale.';
		document.getElementById('rolltxt_3').innerHTML = strFeedback;
		strTerrain += '<p id="terrain_earthquake-on" class="f_left">';
		strTerrain += '<a id="lnk_terrain-earthquake" href="#"><span>Seismic activity has been measured in this area, near a major fault line.</span></a>';
		strTerrain += '<img src="images/safety/correct_earthquake_pipe.gif" width="96" height="35" alt="Above-Ground Zigzags" title="Above-Ground Zigzags" />';
		strTerrain += '</p>';
		document.getElementById('terrain_2').innerHTML = strTerrain;
		break;
	case 'pipe_4': // buried
		strFeedback = 'Yes, this basic method will work well here.';
		document.getElementById('rolltxt_4').innerHTML = strFeedback;
		strTerrain += '<p id="terrain_stable-on" class="f_left">';
		strTerrain += '<a id="lnk_terrain-stable" href="#"><span>Terrain with no permafrost or seismic tremors.</span></a>';
		strTerrain += '<img src="images/safety/correct_stable_pipe.gif" width="97" height="35" alt="Buried Pipe" title="Buried Pipe" />';
		strTerrain += '</p>';
		document.getElementById('terrain_1').innerHTML = strTerrain;
		break;
	}
	if(checkAllCorrect()){ uiShowAllCorrect(); }
}

function uiFeedbackIncorrect(pipeId, idxNum){
	var strFeedback = '';
	var strTerrain = '';
	var rolloverId = '';
	switch(pipeId){
	case 'pipe_1': // bridge supported
		strFeedback = 'No, a bridge isn\'t really needed here.';
		rolloverId = 'rolltxt_1';
		strTerrain = '<p id="terrain_river" class="f_left"><a id="lnk_terrain-river" href="#"><span>This river runs through a deep gorge, downstream from a glacier.</span></a></p>';
		document.getElementById('terrain_3').innerHTML = strTerrain;
		break;
	case 'pipe_2': // refrigerated
		strFeedback = 'No, think about why you\'d want to keep the pipe cold.';
		rolloverId = 'rolltxt_2';
		strTerrain = '<p id="terrain_permafrost" class="f_left"><a id="lnk_terrain-permafrost" href="#"><span>Terrain with a deep layer of permafrost.</span></a></p>';
		document.getElementById('terrain_4').innerHTML = strTerrain;
		break;
	case 'pipe_3': // zigzag
		strFeedback = 'No, think of an area that might have the potential for movement.';
		rolloverId = 'rolltxt_3';
		strTerrain = '<p id="terrain_earthquake" class="f_left"><a id="lnk_terrain-earthquake" href="#"><span>Seismic activity has been measured in this area, near a major fault line.</span></a></p>';		
		document.getElementById('terrain_2').innerHTML = strTerrain;
		break;
	case 'pipe_4': // buried
		strFeedback = 'This won\'t work here.  It must be buried in a solid, secure environment.';
		rolloverId = 'rolltxt_4';
		strTerrain = '<p id="terrain_stable" class="f_left"><a id="lnk_terrain-stable" href="#"><span>Terrain with no permafrost or seismic tremors.</span></a></p>';
		document.getElementById('terrain_1').innerHTML = strTerrain;
		break;
	}
	if(idxNum == 0 && rolloverId != ''){
		document.getElementById(rolloverId).innerHTML = '';
	}
	if(idxNum != 0 && rolloverId != ''){
		document.getElementById(rolloverId).innerHTML = strFeedback;
	}
}

function checkAllCorrect(){
	var allCorrect = true;
	if(document.getElementById('pipe_1').selectedIndex != 3) { allCorrect = false; }
	if(document.getElementById('pipe_2').selectedIndex != 4) { allCorrect = false; }
	if(document.getElementById('pipe_3').selectedIndex != 2) { allCorrect = false; }
	if(document.getElementById('pipe_4').selectedIndex != 1) { allCorrect = false; }
	return allCorrect;
}

function uiShowAllCorrect(){
	var strCorrect = '';
	strCorrect += '<b>Congratulations!</b> You\'ve built a safe pipeline. No design is 100% foolproof, though. The company will need to monitor the line continually, to identify weak spots and minimize environmental damage.  ';
	strCorrect += 'Learn about <a href="../sfeature/pumping.html" rel="external" target="_blank">pumping</a> or <a href="../sfeature/welding.html" rel="external" target="_blank">welding</a>.';
	var strNewRightSide = '';
	strNewRightSide += '<a href="#" onclick="uiShowGuide1();"><img id="guide" src="images/safety/survey_guide.gif" width="30" height="130" alt="Survey Guide" class="roll f_right mar_t" /></a>';

	strNewRightSide += '<p><img id="p1" src="images/safety/pipe_bridge_over.gif" width="75" height="38" alt="Bridge-Supported Pipe" title="Bridge-Supported Pipe" class="f_left" /><b>River</b><br />';
	strNewRightSide += 'Right! A bridge will span the gorge and the river.<br class="l_clear" /></p>';

	strNewRightSide += '<p><img id="p2" src="images/safety/pipe_refrigerated_over.gif" width="75" height="35" alt="Refrigerated Buried Pipe" title="Refrigerated Buried Pipe" class="f_left" /><span class="t_choices"><b>Permafrost</b></span>';
	strNewRightSide += 'You got it! A refrigerated pipeline will keep the oil\'s heat from damaging permafrost.<br class="l_clear" /></p>';

	strNewRightSide += '<p><img id="p3" src="images/safety/pipe_zigzag_over.gif" width="75" height="50" alt="Above-Ground Zigzags" title="Above-Ground Zigzags" class="f_left" /><span class="t_choices"><b>Earthquake Zone</b><br /></span>';
	strNewRightSide += 'Nicely done. This design will survive earthquakes up to 8.5 on the Richter scale.<br class="l_clear" /></p>';

	strNewRightSide += '<p><img id="p4" src="images/safety/pipe_buried_over.gif" width="75" height="28" alt="Buried Pipe" title="Buried Pipe" class="f_left" /><span class="t_choices"><b>Stable Ground</b></span>';
	strNewRightSide += 'Yes, this basic method will work well here.<br class="l_clear" /></p>';

	if(document.getElementById('pipes')){ document.getElementById('pipes').innerHTML = strNewRightSide; }
	if(document.getElementById('instruct_txt')){ document.getElementById('instruct_txt').innerHTML = strCorrect; }
}

function uiShowGuide1(){
	document.getElementById('cnt_man').innerHTML = returnGuide1();
	document.getElementById('cnt_man').className = 'show';
	document.getElementById('guide_bg').className = 'show';
	document.getElementById('terrain_1').className = 'hide';
	document.getElementById('terrain_2').className = 'hide';
	document.getElementById('terrain_3').className = 'hide';
	document.getElementById('terrain_4').className = 'hide';
	if(!mac && ie){ //these vars set by popups.js
		document.getElementById('pipe_1').className = 'hide';
		document.getElementById('pipe_2').className = 'hide';
		document.getElementById('pipe_3').className = 'hide';
		document.getElementById('pipe_4').className = 'hide';
	}
	return false;
}
function uiShowGuide2(){
	document.getElementById('cnt_man').innerHTML = returnGuide2();
	document.getElementById('cnt_man').className = 'show';
	document.getElementById('guide_bg').className = 'show';
	document.getElementById('terrain_1').className = 'hide';
	document.getElementById('terrain_2').className = 'hide';
	document.getElementById('terrain_3').className = 'hide';
	document.getElementById('terrain_4').className = 'hide';
	if(!mac && ie){ //these vars set by popups.js
		document.getElementById('pipe_1').className = 'hide';
		document.getElementById('pipe_2').className = 'hide';
		document.getElementById('pipe_3').className = 'hide';
		document.getElementById('pipe_4').className = 'hide';
	}
	return false;
}
function uiHideGuide(){
	document.getElementById('cnt_man').innerHTML = '';
	document.getElementById('cnt_man').className = 'hide';
	document.getElementById('guide_bg').className = 'hide';
	document.getElementById('terrain_1').className = 'show';
	document.getElementById('terrain_2').className = 'show';
	document.getElementById('terrain_3').className = 'show';
	document.getElementById('terrain_4').className = 'show';
	if(!mac && ie){ //these vars set by popups.js
		document.getElementById('pipe_1').className = 'show';
		document.getElementById('pipe_2').className = 'show';
		document.getElementById('pipe_3').className = 'show';
		document.getElementById('pipe_4').className = 'show';
	}
	return false;
}

function returnGuide1(){
	var strOut = '';
	strOut += '<p><span class="f_right">';
	strOut += '<a href="#" onclick="uiShowGuide1();" class="lnk_active">Pipe Designs</a>&nbsp;|&nbsp;';
	strOut += '<a href="#" onclick="uiShowGuide2();">Natural Threats</a>&nbsp;|&nbsp;';
	strOut += '<a href="#" onclick="uiHideGuide();" id="lnk_manual_close">Close</a>';
	strOut += '</span>';
	strOut += '<span class="title">Pipe Designs</span></p>';
	strOut += '<p><b>Buried Pipe</b><br /><img src="images/safety/icon_buried.gif" alt="" width="46" height="46" class="f_left img_icon" />Pipe is buried underground, on a layer of gravel cleared of sharp rocks.</p>';
	strOut += '<p class="clear"><b>Refrigerated Buried Pipe</b><br /><img src="images/safety/icon_refrigerated.gif" alt="" width="46" height="46" class="f_left img_icon" />Insulated pipe is buried underground. Chilled brine circulates through loops of six-inch diameter pipe to keep the ground frozen.</p>';
	strOut += '<p class="clear"><b>Above-Ground Zigzags</b><br /><img src="images/safety/icon_zigzag.gif" alt="" width="46" height="46" class="f_left img_icon" />Pipe is elevated on vertical supports that allow for the ground\'s movement. The zigzag path allows the pipe to expand or contract as the temperature changes. This configuration also protects against earthquakes.</p>';
	strOut += '<p class="clear"><b>Bridge-Supported Pipe</b><br /><img src="images/safety/icon_bridge_pipe.gif" alt="" width="46" height="46" class="f_left img_icon" />Bridges carry the Trans-Alaska pipeline over 13 river crossings. Bridge designs include: a welded trough that supports the pipe, suspension bridges, a box beam that encases the pipe, and a variant known as a tied arch bridge.</p>';
	strOut += '<p><br /><br /><a href="#" onclick="uiShowGuide2();">See Natural Threats</a> &gt;</p>';
	strOut += '<img id="cnr_man_tl" src="images/safety/manual_corner_top.gif" width="16" height="16" alt="" />';
	strOut += '<a href="#" onclick="uiHideGuide();" id="lnk_manual_tab"><img id="manual_tab" src="images/safety/survey_guide.gif" width="30" height="130" alt="Survey Guide" class="roll" /></a>';
	strOut += '<img id="cnr_man_bl" src="images/safety/manual_corner_bottom.gif" width="16" height="16" alt="" />';
	return strOut;
}

function returnGuide2(){
	var strOut = '';
	strOut += '<p><span class="f_right">';
	strOut += '<a href="#" onclick="uiShowGuide1();">Pipe Designs</a>&nbsp;|&nbsp;';
	strOut += '<a href="#" onclick="uiShowGuide2();" class="lnk_active"s>Natural Threats</a>&nbsp;|&nbsp;';
	strOut += '<a href="#" onclick="uiHideGuide();" id="lnk_manual_close">Close</a>';
	strOut += '</span>';
	strOut += '<span class="title">Natural Threats</span></p>';
	strOut += '<p><b>Earthquakes</b><br /><img src="images/safety/icon_earthquake.gif" alt="" width="46" height="46" class="f_left img_icon" />In 1964, an earthquake measuring 9.2 on the Richter scale devastated Alaska, killing 125 people and causing hundreds of millions of dollars in damage. A 2002 earthquake with a Richter measurement of 7.9 damaged some vertical supports in elevated sections of the pipeline, but did not cause any breaches in the pipe.</p>';
	strOut += '<p><b>Glacial Flash Floods (<em>J&ouml;kulhlaups</em>)</b><br /><img src="images/safety/icon_wave.gif" alt="" width="46" height="46" class="f_left img_icon" />Sometimes glaciers act as dams for temporary lakes formed by glacial run-off or rain. If the waters rise high enough, they can breach glacial barriers and cause flash floods with an Icelandic name, <em>J&ouml;kulhlaups</em>. Pipeline supports are built to withstand these unpredictable floods.</p>';
	strOut += '<p><b>Upward Ice (<em>Aufeis</em>)</b><br /><img src="images/safety/icon_ice.gif" alt="" width="46" height="46" class="f_left img_icon" />Ground water that moves to the surface and freezes can push up layers of ice already on the ground, causing jagged stacked ice layers known as <em>aufeis</em> (German for "upward ice"). The ice can move down hills and rivers, causing damage to structures in its path. Elevating the pipeline on vertical supports minimizes its contact with <em>aufeis</em>, and the supports are designed to withstand the moving ice\'s force.</p>';
	strOut += '<p><br /><br /><br />&lt; <a href="#" onclick="uiShowGuide1();">See Pipe Designs</a></p>';
	strOut += '<img id="cnr_man_tl" src="images/safety/manual_corner_top.gif" width="16" height="16" alt="" />';
	strOut += '<a href="#" onclick="uiHideGuide();" id="lnk_manual_tab"><img id="manual_tab" src="images/safety/survey_guide.gif" width="30" height="130" alt="Survey Guide" class="roll" /></a>';
	strOut += '<img id="cnr_man_bl" src="images/safety/manual_corner_bottom.gif" width="16" height="16" alt="" />';
	return strOut;
}