
/*
all of this was hacked together.  do not base new sites on this.  must rewrite it all, as this current stuff was 'just to see if we could do it'
*/

// -----------------------------------------
// ------------ GLOBAL SETTINGS ------------ 
// -----------------------------------------

var currentLocation = "http://dev.starwardhomes.brickworkscomm.com/dev_encore/";
//var currentLocation = "http://www.starwardhomes.com/dev_encore/";



var placemarks;
var total;
var paused;
var state;
var timed;
var progressTime;
var backed;
var progPercentage;
var t;
var balloonTimer;
var playing;
var vid;
var quickstart;



google.load("earth", "1"); 

//GLOBAL : FOR JAVASCRIPT GEOCODER
google.load("maps", "2.99"); 
var ge = null;
var geocoder;
var camera;
var x1;
var y1;
var vw;



//GLOBAL : FOR FIRST PERSON CAM
var cam;

//GLOBAL : NETWORK LINK DEFINITIONS
var nl = null;
var encorePolygons = null;
var encoreModels = null;

//GLOBAL : TOURING DEFINITIONS 
var features = null;
var fc = null;
var full_map;

//GLOBAL : SWAP KML DEFINITIONS
var swapKmlObject = null;
var empty_kml = currentLocation+"kml/emptyfolder.kml";
var swapCount = 0;


//EARTH CANVAS 

function initCB(object) {
document.getElementById("overlayText").innerHTML = "<br><br>Initializing Google Earth Plugin ... ";
  ge = object;
  ge.getOptions().setFlyToSpeed(0.10);
  ge.getOptions().setStatusBarVisibility(false);
// 43.218428, -79.94305
 y1 = -79.94305;
 x1 = 43.218428;
 vw = 2;

 camera = ge.createCamera('xyz');
 camera = ge.getView().copyAsCamera(ge.ALTITUDE_RELATIVE_TO_GROUND); 
 //ge, la, lat,lng,heading,tilt,range
//camera.set(x1, y1, 120, ge.ALTITUDE_RELATIVE_TO_GROUND, 65,55,360);
camera = ge.getView().copyAsCamera(ge.ALTITUDE_RELATIVE_TO_GROUND); 


//camera.set(x1, y1, 120, ge.ALTITUDE_RELATIVE_TO_GROUND, 65,55,360);

ge.getNavigationControl().setVisibility(ge.VISIBILITY_SHOW); 
ge.getView().setAbstractView(camera);	
ge.getWindow().setVisibility(true); 
ge.getLayerRoot().enableLayerById(ge.LAYER_TERRAIN, false);


//make sure this is off for better performance
//ge.getOptions().setAtmosphereVisibility(false);


//FOR LOGO OVERLAY
var screenOverlay = ge.createScreenOverlay('');
screenOverlay.setIcon(ge.createIcon(''));
screenOverlay.getIcon().
//---- Get overlay
  setHref(currentLocation+"web_images/encore/logo_transparent.png");

//---- Screen position in pixels
  screenOverlay.getOverlayXY().setXUnits(ge.UNITS_PIXELS); screenOverlay.getOverlayXY().setYUnits(ge.UNITS_PIXELS);
  screenOverlay.getOverlayXY().setX(60);
  screenOverlay.getOverlayXY().setY(45);
//---- Rotation around object's center point
  screenOverlay.getRotationXY().setXUnits(ge.UNITS_FRACTION); screenOverlay.getRotationXY().setYUnits(ge.UNITS_FRACTION);
  screenOverlay.getRotationXY().setX(0);
  screenOverlay.getRotationXY().setY(0);
//---- Object's size in pixels
  screenOverlay.getSize().setXUnits(ge.UNITS_PIXELS); screenOverlay.getSize().setYUnits(ge.UNITS_PIXELS);
  screenOverlay.getSize().setX(80);
  screenOverlay.getSize().setY(58);
//---- Rotation in degrees
  screenOverlay.setRotation(0);
ge.getFeatures().appendChild(screenOverlay);

//*** start oogletours
var screenOverlay = ge.createScreenOverlay('');
screenOverlay.setIcon(ge.createIcon(''));
screenOverlay.getIcon().
//---- Get overlay
  setHref(currentLocation+"web_images/oogle_tours_logo.png");

//---- Screen position in pixels
  screenOverlay.getOverlayXY().setXUnits(ge.UNITS_PIXELS); screenOverlay.getOverlayXY().setYUnits(ge.UNITS_PIXELS);
  
  screenOverlay.getOverlayXY().setX(100);

  var logo_y_position = $('map3d').getHeight() - 30; //427
  screenOverlay.getOverlayXY().setY(logo_y_position);

//---- Rotation around object's center point
  screenOverlay.getRotationXY().setXUnits(ge.UNITS_FRACTION); screenOverlay.getRotationXY().setYUnits(ge.UNITS_FRACTION);
  screenOverlay.getRotationXY().setX(0);
  screenOverlay.getRotationXY().setY(0);
//---- Object's size in pixels
  screenOverlay.getSize().setXUnits(ge.UNITS_PIXELS); screenOverlay.getSize().setYUnits(ge.UNITS_PIXELS);
  screenOverlay.getSize().setX(201);
  screenOverlay.getSize().setY(50);
//---- Rotation in degrees
  screenOverlay.setRotation(0);
ge.getFeatures().appendChild(screenOverlay);
//*** end oogletours



//ENABLE BORDERS, ROADS ON STARTUP
ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, false);


document.getElementById("overlayText").innerHTML = "<br><br>Preparing 3D Models ... ";


//NETWORK LINK LOCATIONS
encoreSite = getNL(currentLocation+'kml/site_visit.kml?'+Math.random() * 9999);
encoreSite.setVisibility(false);

//tour_video.kml
encoreVideo = getNL(currentLocation+'kml/tour_video.kml?'+Math.random() * 9999);
encoreVideo.setVisibility(false);

//pantagesVideo = getNL(currentLocation+'kml/tour_pantages.kml?'+Math.random() * 9999);
//pantagesVideo.setVisibility(false);


salesOffice = getNL(currentLocation+'kml/sales_office.kml?'+Math.random() * 9999);
salesOffice.setVisibility(false);

encorePolygons = getNL(currentLocation+'kml/get_homes.php?kml=available_homes&'+Math.random() * 9999);


/*
encoreModels = getNL(currentLocation+'kml/model_base.kmz');
encoreModels2 = getNL(currentLocation+'kml/model_2.kmz');
encoreModels1 = getNL(currentLocation+'kml/model_1.kmz');
encoreModels3 = getNL(currentLocation+'kml/model_3.kmz');
encoreModelsLand = getNL(currentLocation+'kml/model_landscape.kmz');
/**/

//************* dae file import
// A textured model created in Sketchup and exported as Collada.



base = ge.createPlacemark('');
base.setName('model');
model = ge.createModel('');
ge.getFeatures().appendChild(base);
loc = ge.createLocation('');
model.setLocation(loc);
link = ge.createLink('');
link.setHref(currentLocation+'dae/model_base.dae');
model.setLink(link);
loc.setLatitude(43.21931063936671);
loc.setLongitude(-79.94212791477877);
base.setGeometry(model);




model1 = ge.createPlacemark('');
model1.setName('model');
model = ge.createModel('');
ge.getFeatures().appendChild(model1);
loc = ge.createLocation('');
model.setLocation(loc);
link = ge.createLink('');
link.setHref(currentLocation+'dae/model_1.dae');
model.setLink(link);
loc.setLatitude(43.21931063936671);
loc.setLongitude(-79.94212791477877);
model1.setGeometry(model);


model2 = ge.createPlacemark('');
model2.setName('model');
model = ge.createModel('');
ge.getFeatures().appendChild(model2);
loc = ge.createLocation('');
model.setLocation(loc);
link = ge.createLink('');
link.setHref(currentLocation+'dae/model_2.dae');
model.setLink(link);
loc.setLatitude(43.21931063936671);
loc.setLongitude(-79.94212791477877);
model2.setGeometry(model);


model3 = ge.createPlacemark('');
model3.setName('model');
model = ge.createModel('');
ge.getFeatures().appendChild(model3);
loc = ge.createLocation('');
model.setLocation(loc);
link = ge.createLink('');
link.setHref(currentLocation+'dae/model_3.dae');
model.setLink(link);
loc.setLatitude(43.21931063936671);
loc.setLongitude(-79.94212791477877);
model3.setGeometry(model);


landscape = ge.createPlacemark('');
landscape.setName('model');
model = ge.createModel('');
ge.getFeatures().appendChild(landscape);
loc = ge.createLocation('');
model.setLocation(loc);
link = ge.createLink('');
var href = window.location.href;
link.setHref(currentLocation+'dae/model_landscape_a.dae');
model.setLink(link);
loc.setLatitude(43.21931063936671);
loc.setLongitude(-79.94212791477877);
landscape.setGeometry(model);


//************** end dae file import


//encoreModels2hi = getNL(currentLocation+'kml/model_2_detailed.kmz');
//encoreModels1hi = getNL(currentLocation+'kml/model_1_detailed.kmz');
//encoreModels3hi = getNL(currentLocation+'kml/model_3_detailed.kmz');

//currently way too big to load
 encoreTiles = getNL(currentLocation+'kml/overlay_tiles_greener.kmz');
 
 encoreTiles.setVisibility(true);	
  
  
  
  
//ENABLE SITEMAP ON STARTUP
var networkLink = ge.createNetworkLink("");
networkLink.setDescription("NetworkLink open to fetched content");
networkLink.setName("Open NetworkLink");
networkLink.setFlyToView(false);  
var nllink = ge.createLink("");
nllink.setHref(currentLocation+"kml/siteplan.kmz");
networkLink.setLink(nllink);
ge.getFeatures().appendChild(networkLink);

updateOptions();

swapKml("start_tour");

google.earth.fetchKml(ge, empty_kml, fetchKmlCallback );
dropout = setTimeout("Effect.BlindUp('welcomeOverlay')", 15000);
salesoffice = setTimeout("salesOffice.setVisibility(true)", 30000); 

base.setVisibility(true);
startLoad = setTimeout("modelsMed();document.getElementById('complexity2').selected = true", 18000);

//document..PercentLoaded();

if ( ge.getPluginVersion() < "5.0.11655.6079") {
	$('extraContent').innerHTML = "<br><br><font color='red'><b>Your Google Earth Plugin appears to be out of date. Some 3D models may not load correctly. Update at <a href='http://earth.google.com/'>http://earth.google.com/</a> </b></font>";	
}



} // END initCB

//EARTH INITIALIZER
function init() {
  geocoder = new GClientGeocoder();

  google.earth.createInstance("map3d", initCB, failureCB);
  
  

}


//FAILURE ON STARTUP
function failureCB(object) {
  alert('Could not load Google Earth browser plugin. Please refresh the page or reinstall the plugin.');
  }

//FORM CONTROLS : MODELS
function updateOptions() {
    encorePolygons.setVisibility(document.options.enmodels.checked)
}

function setCheckBoxes(FormName, FieldName, CheckValue) {
  if(!document.forms[FormName])
	return;
  var objCheckBoxes = document.forms[FormName].elements[FieldName];
  if(!objCheckBoxes)
	return;
  var countCheckBoxes = objCheckBoxes.length;
  if(!countCheckBoxes)
	objCheckBoxes.checked = CheckValue;
  else
	// set the check value for all check boxes
	for(var i = 0; i < countCheckBoxes; i++)
		objCheckBoxes[i].checked = CheckValue;
}

function optimizeTour() {
  setCheckBoxes('options', 'enmodels', true);
  setCheckBoxes('options', 'enpolygons', true);
  updateOptions();
}

//FOR OVERLAY CONTROLS (BORDERS, ROADS, 3D)
function bron()	{	ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true); 		ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);	
//<a href="#" onClick="broff();"/>Hide Roads & Borders</a>
document.getElementById('roads').innerHTML = '<span class="white">Show Roads: </span><input type="checkbox" onClick="broff();" class="controllink" id="roads" name="roads"  checked />'; 
//<p style="margin:0; padding-top:17px;"><span class="white">Hide Roads:</span><input type="checkbox" onClick="broff();" class="controllink" id="roads" name="roads" /></p>

}
function broff() 	{	ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, false);		ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, false);	
//<a href="#" onClick="bron();"/>Show Roads & Borders</a>
document.getElementById('roads').innerHTML = '<span class="white">Show Roads: </span><input type="checkbox" onClick="bron();" class="controllink" id="roads" name="roads"/>'; 
}

function don()	{	ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS, true);	}
function doff() {	ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS, false);	}


// ---------------------------------------
// ------------ FIRST PERSON CAM --------- 
// ---------------------------------------

function switchControls(state){
	if (state == "on") {

	document.getElementById('controls').style.visibility = 'visible';
	}
	if (state == "off") {
	document.getElementById('controls').style.visibility = 'hidden';
	}
}

function fpOff() {
		if(vw == 1){ 
		vw = 2;
    	ge.getNavigationControl().setVisibility(ge.VISIBILITY_SHOW);
		camera.set(x1, y1, 200, ge.ALTITUDE_RELATIVE_TO_GROUND,  -53,56,360);
 		
		ge.getView().setAbstractView(camera);	
 		delete cam;
		hide('fptoggle');
		show('overheadControl');
		}
		else {
		//camera = ge.getView().copyAsCamera(ge.ALTITUDE_RELATIVE_TO_GROUND); 
		y1 = -79.94230074712334;
	  	x1 = 43.2181146391591;
			
		ge.getOptions().setFlyToSpeed(100);
		ge.getNavigationControl().setVisibility(ge.VISIBILITY_HIDE);
		cam = new FirstPersonCam();
		
  		cam.updateCamera();
		vw = 1;
		hide('overheadControl');
		show('fptoggle');

		}
}

// ---------------------------------------
// ------------ NETWORK LINKS ------------ 
// ---------------------------------------

//FOR NETWORK LINKS
function getNL(kmlURL){

  nl = ge.createNetworkLink("");
  var link = ge.createLink("");
  link.setHref(kmlURL);
  nl.setLink(link);
nl.setFlyToView(false);
  ge.getGlobe().getFeatures().appendChild(nl);
  return nl;
}



// ---------------------------------------------------
// ------------ TOURING (swapKml, swapto) ------------ 
// ---------------------------------------------------

function nocache() { return Math.random() * 9999;	}
function fetchKmlCallback(object) {
  if(!object){ alert('Bad or NULL kml!'); }
    swapKmlObject = object;
  ge.getGlobe().getFeatures().appendChild(swapKmlObject);

	//features = object.getFeatures();
    features = object.getFeatures();
	full_map = features.getFirstChild();
    inside_features = full_map.getFeatures();
    fc = inside_features.getFirstChild(); 
  slowdown(0.2);
	if (fc != null) {
  ge.getView().setAbstractView(fc.getAbstractView()); 
	}
}

function swapKml(kmlfile) {
extraContent('clear');
videoControls("off");
ge.setBalloon(null);
clearTimeout(balloonTimer);


if (kmlfile == "video_tour") {
encoreVideo.setVisibility(true);
videoControls("on");
extraContent("video");
return false; 	
}
if (kmlfile != "pantages" && kmlfile != "video_tour") {
	encoreVideo.setVisibility(false);
	videoControls("off");
	extraContent("clear");
}
if (kmlfile == "firstperson") {
	show('fptoggle');
	fpOff();
}

else {
  	//force user out of first person camera
	unpause();
	modelsOff();
	if (vw != 2) {
		fpOff();
	}
	
	swapCount++;

   switch(kmlfile) {
	case 'encoretour': new_kml = currentLocation+"kml/encore_tour.kml?"; progressReset(); break;
	case 'home': new_kml = currentLocation+"kml/encorehome.kml?"; progressReset(); ge.setBalloon(null); setTimeout("changeModels(document.getElementById('complexity').value)", 5000); document.getElementById('resetState').selected=true; encoreSite.setVisibility(false); break;
	//case 'walking_tour': new_kml = currentLocation+"kml/site_visit.kml?"; progressReset(); changeModels("high"); placemarks = 0; total = 14; t = 6000; break;
	case 'video_tour': new_kml = currentLocation+"kml/tour_video.kml?"; break;
	case 'pantages': new_kml = currentLocation+"kml/tour_pantages.kml?"; break;
	case 'walking_tour': new_kml = currentLocation+"kml/site_visit.kml?"; progressReset(); changeModels("medium");  placemarks = 0; total = 18; t = 8000; setTimeout("startAudio('site_visit')", 5000); break;
	case 'schools': new_kml = currentLocation+"kml/tour_schools.kml?"; progressReset(); placemarks = 0; total = 10; t = 13000; break;
	case 'recreation': new_kml = currentLocation+"kml/tour_recreation.kml?"; progressReset(); placemarks = 0; total = 13; t = 10000; break;
	case 'culture': new_kml = currentLocation+"kml/tour_culture.kml?"; progressReset(); placemarks = 0; total = 8; t = 13000; break;
	case 'shopping': new_kml = currentLocation+"kml/tour_shopping.kml?"; progressReset(); placemarks = 0; total = 6; t = 10000; break;
	case 'restaurants': new_kml = currentLocation+"kml/tour_restaurants.kml?"; progressReset(); placemarks = 0; total = 7; t = 10000; break;
	//case 'tour_attractions': new_kml = "http://etournow.brickworkscomm.com/sr/kml/fetch_kml.php?kml="+kmlfile+"&"; break;
	case 'attractions': new_kml = currentLocation+"kml/tour_attractions.kml?"; progressReset(); placemarks = 0; total = 8; t = 28000; break;
	case 'convenience': new_kml = currentLocation+"kml/tour_convenience.kml?"; progressReset(); placemarks = 0; total = 6; t = 10000; break;	
	case 'travel': new_kml = currentLocation+"kml/tour_travel.kml?"; progressReset(); placemarks = 0; total = 6; t = 20000; break;
	case 'start_tour': new_kml = currentLocation+"kml/start_tour.kml?"; progressReset(); modelsOff(); placemarks = 0; total = 0; t = 3000; break;
	case 'firstperson': new_kml = empty_kml; modelsOn(); break;
	default: new_kml = empty_kml; modelsOn(); break;

	}
  new_kml += "r="+nocache();
 
//IE7 can't removeChild if the object doesn't exist, so it would die here if we didn't do this check..
if (swapKmlObject != null) {
 ge.getGlobe().getFeatures().removeChild(swapKmlObject);
 }

  google.earth.fetchKml(ge, new_kml, fetchKmlCallback);
  
 

  starttimer(t);

}
}	




function swapto_ff() { 
 //features = full_map.getFeatures();
 fc = features.getFirstChild() ; //FIRST PLACEMARK
}

function swapto_next(forward) {
	
	clearTimeout(timed);
	clearTimeout(progressTime);
  if (!fc || fc.getName() == 'Placemark 5') { //LAST PLACEMARK NAME this does nothing?
    swapto_ff();
  }
  else {
    if (forward) {
					
	if (paused != 1) {
		if (new_kml.search(/start_tour/i) == -1 && (new_kml.search(/^home/i) == -1)) {
	ge.getNavigationControl().setVisibility(ge.VISIBILITY_HIDE);
		}
	fc = fc.getNextSibling();
		
		if(fc != null) {
		if (fc.getNextSibling() == null) {
			changeModels(document.getElementById('complexity').value);
		}
		}
	
	}
	}
    else {
	fc = fc.getPreviousSibling();
	
	}
	
    }
  slowdown(0.15);
  ge.setBalloon(null);
	if (fc != null) {
  ge.getView().setAbstractView(fc.getAbstractView()); 
	}
  balloon = ge.createFeatureBalloon('');
  balloon.setFeature(fc);

if (new_kml.search(/start_tour/i) == -1 && (new_kml.search(/^home/i) == -1)) {
  balloonTimer = setTimeout("ge.setBalloon(balloon)",3000);
}

if (t == 500 && placemarks > 0) {
t = 13000; 
}
if (new_kml.search(/^home/i) == -1) {
	starttimer(t);	
}


}

//SET EVENT NAVIGATION SPEED
function slowdown(x) {
  ge.getOptions().setFlyToSpeed(x);
}


function fullscreen() {
if (document.viewport.getHeight() > 0) {
	
document.getElementById("map3d").style.height = document.viewport.getHeight();
document.getElementById('map3d').style.width = document.viewport.getWidth();
document.getElementById('map3d').style.zIndex = "200";
}
else {
document.getElementById('map3d').style.zIndex = "200";
document.getElementById("map3d").style.height = document.body.clientHeight - 100;
document.getElementById('map3d').style.width = document.body.clientWidth;
document.getElementById('map3d').style.left = 1;
}
}

function getHeight() {
document.getElementById('tour_encore').style.left = (document.body.clientWidth / 2) - 302;
document.getElementById('logo_banner').style.height = document.viewport.getHeight() - 50 ;
}



function progress() {
	if (placemarks < total && total > 0) {
		if (backed != 1) {
			placemarks++;
			document.getElementById('tourprogress').innerHTML = "Tour Progress: "+ Math.round((placemarks / total) * 100) +"% <br /> During a Community tour, the Model reverts to 2D mode. It will go back to your default model setting when the tour is over.<br />Use the forward and back buttons to manually step through the tour.";
			progPercentage = Math.round((placemarks / total) * 100);
				if (progPercentage == 100) {
					pause();
				}
				else {
					clearTimeout(timed);
					starttimer(t);
				}   
		}
	else {
		backed = 0;	
		}
	}
}


function backup() {
	if (placemarks > 0) {
	placemarks--;
	document.getElementById('tourprogress').innerHTML = "Tour Progress: "+ Math.round((placemarks / total) * 100) +"% <br /> During a tour, the Model reverts to 2D mode. It will go back to your selected setting when the tour is over.<br />Use the forward and back buttons to manually step through the tour.";
	placemarks--;
	backed = 1;
	}
}

function progressReset() {
	document.getElementById('tourprogress').innerHTML = "";
	clearTimeout(timed);
	clearTimeout(progressTime);
}

function starttimer(t) { 
		if (paused == 1) { 
			timed = "";
		} 
		else { 
			clearTimeout(timed);
				if (progPercentage == 100) { 
					pause();
					} 
					else { 
						if (t == null) {
							t = 9000
						} 
						if (placemarks == 0) { 
						timed =setTimeout("swapto_next(1); progress();", 5000);
						} 
						else { 
							timed =setTimeout("swapto_next(1); progress();", t);	
						} 
					} 

				}	
} 

function pause() {
	
	clearTimeout(timed);
	clearTimeout(progressTime);
	paused = 1;
	timed ="";
	ge.getNavigationControl().setVisibility(ge.VISIBILITY_SHOW);
	document.getElementById("pause").innerHTML = '<a href="javascript: unpause();"><img src="web_images/play.png" border="0" alt="play" title="play" /></a>';
	//<a href="#"><img onClick="unpause();"  src="web_images/play.png" border="0" alt="" /></a>
	
	}

function unpause() {
	videoSearch();
clearTimeout(timed);
clearTimeout(progressTime);

paused = 0;	
document.getElementById("pause").innerHTML = '<a href="javascript: pause();"><img src="web_images/pause.png" border="0" alt="pause" title="pause"/></a>';
//<a href="#"><img onClick="pause();"   src="web_images/pause.png" border="0" alt="" /></a>
	
	if (progPercentage == 100) {
	progPercentage = 0;
	swapKml(document.getElementById('tourSelect').value);
	}
	else {
	if(placemarks < 0) {
		placemarks = 0;
	}
	placemarks++;
	placemarks++;
	placemarks++;
	timed = setTimeout("swapto_next(1)",1000);	
	}

}




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];}
}


function hide(toHide) {
$(toHide).hide();	
}

function show(toShow) {
$(toShow).show();	
}


function overlayPosition() {
	document.getElementById('welcomeOverlay').style.left = (document.body.clientWidth / 2) - 352;
}

function modelsOn() {
	
	
	landscape.setVisibility(false);
	model1.setVisibility(true);
	model2.setVisibility(true);
	model3.setVisibility(true);
	base.setVisibility(true);
	
	/*
encoreModels.setVisibility(true);
encoreModels1.setVisibility(true);	
encoreModels2.setVisibility(true);	
encoreModels3.setVisibility(true);	
encoreModelsLand.setVisibility(false);	
*/
//document.getElementById('landscape').innerHTML = '<span class="white">Model Complexity:</span> off <input type="checkbox" onClick="modelsOff()" name="landscape" id="landscapecheck" /> med <input type="checkbox" onClick="modelsMed()" name="landscape" id="landscapecheck" checked /> hi <input type="checkbox" onClick="modelsHigh()" name="modelhigh" id="modelhigh" > ';

}

function modelsOff() {
	
	landscape.setVisibility(false);
	model1.setVisibility(false);
	model2.setVisibility(false);
	model3.setVisibility(false);
	base.setVisibility(false);
	
	/*
encoreModels.setVisibility(false);
encoreModels1.setVisibility(false);	
encoreModels2.setVisibility(false);	
encoreModels3.setVisibility(false);	
encoreModels1hi.setVisibility(false);	
encoreModels2hi.setVisibility(false);	
encoreModels3hi.setVisibility(false);
encoreModelsLand.setVisibility(false);	
*/
//document.getElementById('landscape').innerHTML = '<span class="white">Model Complexity:</span> off <input type="checkbox" onClick="modelsOff()" name="landscape" id="landscapecheck" checked /> med <input type="checkbox" onClick="modelsMed()" name="landscape" id="landscapecheck" /> hi <input type="checkbox" onClick="modelsHigh()" name="modelhigh" id="modelhigh" >';

}

function modelsMed() {
	
	landscape.setVisibility(false);
	model1.setVisibility(true);
	model2.setVisibility(true);
	model3.setVisibility(true);
	base.setVisibility(true);
	
	/*
encoreModels.setVisibility(true);
encoreModels1.setVisibility(true);	
encoreModels2.setVisibility(true);	
encoreModels3.setVisibility(true);	
encoreModelsLand.setVisibility(false);	
*/
//document.getElementById('landscape').innerHTML = '<span class="white">Model Complexity:</span> off <input type="checkbox" onClick="modelsOff()" name="landscape" id="landscapecheck" /> med <input type="checkbox" onClick="modelsMed()" name="landscape" id="landscapecheck" checked /> hi <input type="checkbox" onClick="modelsHigh()" name="modelhigh" id="modelhigh" > ';

}


function modelsHigh() {
	
	landscape.setVisibility(true);
	model1.setVisibility(true);
	model2.setVisibility(true);
	model3.setVisibility(true);
	base.setVisibility(true);
	/*
encoreModels.setVisibility(true);
encoreModels1.setVisibility(true);	
encoreModels2.setVisibility(true);	
encoreModels3.setVisibility(true);	
encoreModelsLand.setVisibility(true);	
*/
//document.getElementById('landscape').innerHTML = '<span class="white">Model Complexity:</span> off <input type="checkbox" onClick="modelsOff()" name="landscape" id="landscapecheck" /> med <input type="checkbox" onClick="modelsMed()" name="landscape" id="landscapecheck" /> hi <input type="checkbox" onClick="modelsHigh()" name="modelhigh" id="modelhigh" checked>';

}


function extraContent(task) {
	if (task == "clear") {
	document.getElementById('extraContent').innerHTML = '';
	ie6checker();
	}
	if (task == "photo") {
	document.getElementById('extraContent').innerHTML = '<br>Please navigate around the site, and click on the photo icons to view related photographs.  ';
	}
	if (task == "video") {
	document.getElementById('extraContent').innerHTML = '<br>Click on the yellow icon for video.  If your video does not start automatically, try clicking on the play button above.';
	}
}


function changeModels(which) {
	modelsOff();
	if (which == "medium") {
	modelsMed();	
	}
	
	else if (which == "high") {
		modelsHigh();
	}
	
	else {
	modelsOff();	
	}
	
	
}


function pulldown(kml) {
	if (kml == "photo_tour") {
	encoreSite.setVisibility(true)
	extraContent('photo');
	changeModels("medium");
	}
	else {
	encoreSite.setVisibility(false)
	swapKml(kml);
	}
	
}


function playVideo(which) {


if (which == 'videoPlayer') { document.getElementById('videoPlayer').innerHTML = '<center><embed src="flv/iphone_large.swf" height="300"  width="600" type="application/x-shockwave-flash" play="true" loop="false" menu="false"></center>'; }
if (which == 'pantages1') {document.getElementById('pantages1').innerHTML = '<center><embed src="flv/pantages.swf" height="300"  width="600" type="application/x-shockwave-flash" play="true" loop="false" menu="false"></center>'; }
if (which == 'pantages2') {document.getElementById('pantages2').innerHTML = '<center><embed src="flv/pantages.swf" height="300"  width="600" type="application/x-shockwave-flash" play="true" loop="false" menu="false"></center>'; }
if (which == 'pantages3') {document.getElementById('pantages3').innerHTML = '<center><embed src="flv/pantages.swf" height="300"  width="600" type="application/x-shockwave-flash" play="true" loop="false" menu="false"></center>'; }


playing = 1;
videoSearch();
}

function checkVideo(which) {
	var which;
	var videoElement = document.getElementById("videoPlayer");
	
	//var pantages1 = document.getElementById("pantages1");
	//var pantages2 = document.getElementById("pantages2");
	//var pantages3 = document.getElementById("pantages3");
	
	//if (videoElement != null || pantages1 != null || pantages2 != null || pantages3 != null) {
	if (videoElement != null) {		
		if (playing != 1) {
		videoControls("on")
		if (videoElement != null ) { playVideo('videoPlayer'); }
		//if (pantages1 != null ) { playVideo('pantages1'); }
		//if (pantages2 != null ) { playVideo('pantages2'); }
		//if (pantages3 != null ) { playVideo('pantages3'); }
		resetVideo();
		}
	}
	else {
	resetVideo();
	videoSearch();
	videoControls("off");
	}
}

function videoSearch() {
	vid = setTimeout("checkVideo()", 500);
	
}

function resetVideo() {
	clearTimeout(vid);
	playing = 0;
 
	}
	
	
function videoControls(state) {
	if (state == "on") {
	// hide overheadControl, show videoControl
		hide('overheadControl');
		show('videoControl');
		}
	else {
		// hide videoControl , show overheadControl
		hide('videoControl');
		show('overheadControl');	
		}
	}
	
	
	function selectModelValue(val) {
		if (val == 'medium') {
		document.getElementById('complexity2').selected = true;
		}
	}
	
	
	function updateVideo() {
    encoreVideo.setVisibility(document.options.videos.checked);
	extraContent("video");
	
}


	function startAudio(which) {
if (which == 'site_visit') { 
document.getElementById('audio').innerHTML = '<embed src="flv/site_visit_audio.swf" height="1"  volume="50" width="1" type="application/x-shockwave-flash" play="true" loop="false" menu="false" style="visibility: none;">'; 
}
	}
	
	function resetAudio() {
	document.getElementById('audio').innerHTML = '';
	}
	
	
	
	function ie6checker() {
		var isIE6  = (navigator.userAgent.indexOf("MSIE 6") != -1) ? true : false;
		if( isIE6 == true ) {
		// do IE6 stuff
		document.getElementById('extraContent').innerHTML = "<br><br><b>You seem to be using Internet Explorer 6.  If you are seeing an empty white box above the controls, press the F11 key on your keyboard.</b>";
		}
}


function helpWindow() {
var load = window.open('where_on_earth_help.php','','scrollbars=no,menubar=no,height=500,width=842,resizable=no,toolbar=no,location=no,status=no');
}

function fullscreenConfirm(answer) {
	if (answer == "no") {
document.getElementById('fullscreenConfirm').style.display = 'none';	
	}
	else {
	Effect.Appear('fullscreenConfirm');	

	}
}
