// Written by Edward G. Muesch, Jr.
// Copyright 2006-2007 - NecessiSoft, Inc. - All Rights Reserved.
//

Array.prototype.sum = function(){
	for(var i=0,sum=0;i<this.length;sum+=this[i++]);
	return sum;
}
Array.prototype.max = function(){
	return Math.max.apply({},this);
}
Array.prototype.min = function(){
	return Math.min.apply({},this);
}
//---------------------------------------------------------------------------
// Waypoints
//---------------------------------------------------------------------------
function nsWaypoint( desc, filename, thumbnail, thumbdesc ) {
	this.setDesc(desc);
	this.setKMZ(filename);
	this.setThumbPic(thumbnail);
	this.setThumbDesc(thumbdesc);
};
nsWaypoint.prototype.getDesc = function() {
	return this.desc;
};
nsWaypoint.prototype.getLat = function() {
	return this.latitude;
};
nsWaypoint.prototype.getLng = function() {
	return this.longitude;
};
nsWaypoint.prototype.getKMZ = function() {
	return this.kmzName;
};
nsWaypoint.prototype.getThumbPic = function() {
	return this.thumbpic;
};
nsWaypoint.prototype.getThumbDesc = function() {
	return this.thumbdesc;
};
nsWaypoint.prototype.getMarker = function() {
	return this.marker;
};
nsWaypoint.prototype.setDesc = function(description) {
	this.desc=description;
};
nsWaypoint.prototype.setLat = function(lat) {
	this.latitude=isNaN(lat)?0:lat;
};
nsWaypoint.prototype.setLng = function(lng) {
	this.longitude=isNaN(lng)?0:lng;
};
nsWaypoint.prototype.setKMZ = function(filename) {
	this.kmzName=filename;
};
nsWaypoint.prototype.setThumbPic = function(pic) {
	this.thumbpic=pic;
};
nsWaypoint.prototype.setThumbDesc = function(desc) {
	this.thumbdesc=desc;
};
nsWaypoint.prototype.setMarker = function(mrkr) {
	this.marker=mrkr;
};

nsWaypoint.prototype.getFilename = function() {
//	debugger;
	return (this.server+this.kmzName);
};

nsWaypoint.prototype.index;
nsWaypoint.prototype.desc;
nsWaypoint.prototype.latitude;
nsWaypoint.prototype.longitude;
nsWaypoint.prototype.kmzName;
nsWaypoint.prototype.thumbpic;
nsWaypoint.prototype.thumbdesc;
nsWaypoint.prototype.marker;
nsWaypoint.prototype.server="http://www.svtahlequah.com/Locations/";

//---------------------------------------------------------------------------
// Waypoint Manager
//---------------------------------------------------------------------------
function nsMgrWaypts(){
	this.waypts = new Array((GEDest.length));
	for(i=0;i<GEDest.length;i++){
		var obj = GEDest[i];
		this.waypts[i] = new nsWaypoint( obj.id, obj.KMZ, obj.thumbname, obj.thumbpic );
	};
	this.setPauseMSecs(1000);	// up to x seconds to view after 100% streamed and then on to the next. Needs to be long enough to allow streaming to go below 100% (at least 2 secs, 2000)
	this.aVisitKMLFiles = new Array();	// holds all filenames currently loaded as waypoints
	this.aAllKMLFiles = new Array();		// holds filenames currently loaded as waypoints
	this.aVisitMarkers = new Array();	// holds loaded waypoint markers
	this.aAllMarkers = new Array();		// holds all available (loaded-so-far-during-session) waypoint markers 
	this.play_index=0;						// What # waypoint are we playing
	this.fullscreen=false;
	this.nAutoPilotSpeed=0.12;
	this.alerted2install=0;
	this.nLastLeg2IgnoreFx=7;
	this.secs2PauseWhilePlay=2000;
	this.nWaypoints2Disp=0;
	this.markersToTrail=0;
	if ((screen.width>=1600) && (screen.height>=1200)){
		this.markersToTrail=5;
		this.nWaypoints2Disp=31;
	}
	else if ((screen.width>=1280) && (screen.height>=1024)){
		this.markersToTrail=4;
		this.nWaypoints2Disp=23;
	}
	else if ((screen.width>=1024) && (screen.height>=768)){
		this.markersToTrail=3;
		this.nWaypoints2Disp=15;
	}
	else{
		this.markersToTrail=3;
		this.nWaypoints2Disp=14;
	}
	this.zoom_min=2;
	this.zoom_max=12;
	this.logging_now=0;
	this.nTeleportSpeed=5.0;
   this.click2cruise=0;
	this.homelat="37.0000";
	this.homelng="27.1600";
	this.homezoom=4;
	this.demo_mode=0;
	this.playing_now=0;
	this.nlastLat=0;
	this.nlastLon=0;
	this.nlastVisitLat=0;	// location of last (not current) marker
	this.nlastVisitLon=0;	// location of last (not current) marker
	this.point_index=0;	// used to keep track as we add markers to the 'visited places' array
};
nsMgrWaypts.prototype.setLastLat = function(lat) {
	this.nlastLat=isNaN(lat)?0:lat;
};
nsMgrWaypts.prototype.setLastLng = function(lng) {
	this.nlastLon=isNaN(lng)?0:lng;
};
nsMgrWaypts.prototype.setLastVisitLat = function(lat) {
	this.nlastVisitLat=isNaN(lat)?0:lat;
};
nsMgrWaypts.prototype.setLastVisitLng = function(lng) {
	this.nlastVisitLon=isNaN(lng)?0:lng;
};
nsMgrWaypts.prototype.setPlayIndex = function(indexptr) {
	this.play_index=(isNaN(indexptr)||indexptr<1)?0:indexptr;
};
nsMgrWaypts.prototype.getPlayIndex = function() {
	return isNaN(this.play_index)?0:this.play_index;
};
nsMgrWaypts.prototype.setPointIndex = function(indexptr) {
	this.point_index=(isNaN(indexptr)||indexptr<1)?0:indexptr;
};
nsMgrWaypts.prototype.getPointIndex = function() {
	return isNaN(this.point_index)?0:this.point_index;
};
nsMgrWaypts.prototype.getLastLat = function() {
	return isNaN(this.nlastLat)?0:this.nlastLat;
};
nsMgrWaypts.prototype.getLastLng = function() {
	return isNaN(this.nlastLon)?0:this.nlastLon;
};
nsMgrWaypts.prototype.getLastVisitLat = function() {
	return isNaN(this.nlastVisitLat)?0:this.nlastVisitLat;
};
nsMgrWaypts.prototype.getLastVisitLng = function() {
	return isNaN(this.nlastVisitLon)?0:this.nlastVisitLon;
};
nsMgrWaypts.prototype.getHomeLat = function(){
	return isNaN(this.homelat)?0:this.homelat;
};
nsMgrWaypts.prototype.getHomeLng = function(){
	return isNaN(this.homelng)?0:this.homelng;
};
nsMgrWaypts.prototype.getHomeZoom = function(){
	return isNaN(this.homezoom)?0:this.homezoom;
};
nsMgrWaypts.prototype.markersLoaded = function(){
	return isNaN(this.aVisitMarkers.length)?0:this.aVisitMarkers.length;
};
nsMgrWaypts.prototype.KMLfilesLoaded = function(){
	return isNaN(this.aVisitKMLFiles.length)?0:this.aVisitKMLFiles.length;
};
nsMgrWaypts.prototype.waypts;
nsMgrWaypts.prototype.bounds;
nsMgrWaypts.prototype.ovcontrol;
nsMgrWaypts.prototype.lmcontrol;
nsMgrWaypts.prototype.mtcontrol;
nsMgrWaypts.prototype.sccontrol;
nsMgrWaypts.prototype.mgcontrol;
nsMgrWaypts.prototype.magnifier;
nsMgrWaypts.prototype.fullscreen;
nsMgrWaypts.prototype.alerted2install;
nsMgrWaypts.prototype.nLastLeg2IgnoreFx;
nsMgrWaypts.prototype.map;
nsMgrWaypts.prototype.baseIcon;	// used for custom PDMarker icons
nsMgrWaypts.prototype.nWaypoints2Disp;
nsMgrWaypts.prototype.markersToTrail;

nsMgrWaypts.prototype.logThis = function(msg){
	var zyz=(this.logging_now)?GLog.write(msg):"";
};
nsMgrWaypts.prototype.getPauseMSecs = function(){
	return isNaN(this.secs2PauseWhilePlay)?0:this.secs2PauseWhilePlay;
};
nsMgrWaypts.prototype.setPauseMSecs = function(mSecs2pause){
	this.secs2PauseWhilePlay=isNaN(mSecs2pause)?1000:mSecs2pause;
};
nsMgrWaypts.prototype.getAutoPilotSpeed = function(){
	return isNaN(this.nAutoPilotSpeed)?0:this.nAutoPilotSpeed;
};
nsMgrWaypts.prototype.setAutoPilotSpeed = function(speed){
	this.nAutoPilotSpeed=isNaN(speed)?0:speed;
};
nsMgrWaypts.prototype.isDemoRunning = function(){
	return isNaN(this.demo_mode)?0:this.demo_mode;
};
nsMgrWaypts.prototype.setDemoMode = function(demomode){
	if(isNaN(demomode) || demomode<1){
		this.demo_mode=0;
	}else{
		this.demo_mode=1;
	}
};
nsMgrWaypts.prototype.isCruising = function(){
	return isNaN(this.click2cruise)?0:this.click2cruise;
};
nsMgrWaypts.prototype.setCruiseMode = function(cruisemode){
	if(isNaN(cruisemode) || cruisemode<1){
		this.click2cruise=0;
	}else{
		this.click2cruise=1;
	}
};
nsMgrWaypts.prototype.isPlaying = function(){
	return isNaN(this.playing_now)||!this.playing_now?0:1;
};
nsMgrWaypts.prototype.setPlayMode = function(playmode){
//debugger;
if(isNaN(playmode) || playmode<1){
		this.playing_now=0;
	}else{
		this.playing_now=1;
	}
};
nsMgrWaypts.prototype.getTeleportSpeed = function(){
	return (isNaN(this.nTeleportSpeed)?0:this.nTeleportSpeed);
};
nsMgrWaypts.prototype.setTeleportSpeed = function(speed){
	if(isNaN(speed)){
		this.nTeleportSpeed=0;
	}else{
		this.nTeleportSpeed=speed;
	}
};
nsMgrWaypts.prototype.getZoomMin = function(){
	return (isNaN(this.zoom_min)?this.getHomeZoom():this.zoom_min);
};
nsMgrWaypts.prototype.setZoomMin = function(level){
	if(isNaN(level) || level<1 || level>20){
		this.zoom_min=this.getHomeZoom();
	}else{
		this.zoom_min=level;
	}
};
nsMgrWaypts.prototype.getZoomMax = function(){
	return (isNaN(this.zoom_max)?this.getHomeZoom():this.zoom_max);
};
nsMgrWaypts.prototype.setZoomMax = function(level){
	if(isNaN(level)){ // || level<1 || level>20){
		this.zoom_max=this.getHomeZoom();
	}else{
		this.zoom_max=level;
	}
};
// ??? add markersToTrail and aVisitMarkers to prototype
nsMgrWaypts.prototype.setBounds = function(mapMap, nIndex, pPoint){
	bBounds=new GLatLngBounds();
	if(nIndex<2){
		this.logThis("setBounds - PASSED (getPointIndex()<2)");
		this.logThis("setBounds - Clearing Map Overlays (Markers, etc.)");
		mapMap.clearOverlays();
		mapMap.setCenter(pPoint, 3, G_HYBRID_MAP);
	}else{
	}
	
	this.logThis("setBounds - Extending Bounds for this Marker");
	bBounds.extend(pPoint);
	var indexOffset=1;
	var pinOffset=0;
	for(i=1;((nIndex-pinOffset-indexOffset-(i))>=0 && i<=this.markersToTrail);i++){
		this.logThis("setBounds - Extending Bounds for last "+i+" Marker");
		bBounds.extend(this.aVisitMarkers[nIndex-pinOffset-indexOffset-(i)].getPoint());
		if(i>0 && nIndex-((i+1)+indexOffset+pinOffset)>=0){
			var lastDistance = pPoint.distanceFrom( this.aVisitMarkers[ nIndex-1-indexOffset-pinOffset ].getPoint() ); // last distance
			var nextLastDistance = this.aVisitMarkers[ nIndex-((i+1)+indexOffset+pinOffset) ].getPoint().distanceFrom( pPoint ); //before last
			if( (lastDistance*this.nLastLeg2IgnoreFx) < (nextLastDistance)){
				break;	
			}
		}
	}
	return bBounds;
}

nsMgrWaypts.prototype.loadkml = function(kml){
	if(this.isDemoRunning()){
		mgrView.say_cruising_ge();
	}else{
//		debugger;
		mgrView.say_now_playing_waypoint();
	}
	if(!this.isPlaying() && !this.isDemoRunning()){
		document.myform.but_reset_waypoints.disabled=false;
		document.myform.but_start_play.disabled=false;
		document.getElementById('MapShowNow').innerHTML="<font size=-2><div align=center><b><font color=\"red\">"+((this.isCruising())?"Cruising to":"Loading")+" Waypoint: \""+kml.replace("http://www.svtahlequah.com/Locations/","").replace(".kmz","")+"\" ("+(this.getPointIndex())+" of "+(this.KMLfilesLoaded()+1)+")</font><br /></b></div></font>";
	}
	document.getElementById('ShowNow').innerHTML="<font size=-2><div align=center style=\"border-style: outset; border-width: 3px\"><b><font color=\"red\">Loading:</font><br /> "+kml.replace("http://www.svtahlequah.com/Locations/","").replace(".kmz","")+"</b><br /><img width='60' height='50' style=\"border-style: outset; border-width: 3px\" src='"+kml.replace(".kmz",".jpg")+"'><br /><br /></div></font>";
	window.location.hash="#TopView";
	geOpenFile(kml);
	geSetAutoPilotSpeed(ApplicationGE, this.getAutoPilotSpeed());
	document.getElementById('ShowNow').innerHTML="<font size=-2><div align=center style=\"border-style: outset; border-width: 3px\"><b><font color=\"green\">Destination:</font><br /> "+kml.replace("http://www.svtahlequah.com/Locations/", "").replace(".kmz","")+"</b><br /><img width='60' height='50' style=\"border-style: outset; border-width: 3px\" src='"+kml.replace(".kmz",".jpg")+"'><br /><br /></div></font>";
//	window.location.hash="#TopView";
	if((!this.isCruising()) && (!this.isPlaying())){	// || this.demo_mode)){
		this.aVisitKMLFiles.push(kml);
		clearInterval(mgrView.timerID);
		if(!this.isDemoRunning()){
			// long enough to unwind this stack and start to process GEX so syncMap knows we're moving and we don't place the marker from the starting point
			mgrView.timerID=setInterval("mgrView.syncMap()", (this.getPauseMSecs()));	
		}
	}else if(this.isCruising()){
	}
};

nsMgrWaypts.prototype.reset_waypoints = function(){
	document.myform.but_reset_waypoints.disabled=true;
	document.myform.but_start_play.disabled=true;
	this.setPointIndex(0);
	this.setPlayIndex(0);
	this.aVisitKMLFiles=new Array();
	this.aVisitMarkers=new Array();
	this.map.clearOverlays();
	this.bounds=new GLatLngBounds();
	// returns immediately when this.isPlaying()==1 if not this.isDemoRunning()
	mgrView.syncMap();
	mgrView.drawRightMapControls();
	mgrView.drawRightControls();
};

nsMgrWaypts.prototype.start_play = function(){
	clearInterval(mgrView.timerID);
	document.myform.but_reset_waypoints.disabled=true;
	document.myform.but_start_play.disabled=true;
	document.myform.but_stop_play.disabled=false;
	document.myform.but_start_demo.disabled=true;
	document.myform.but_stop_demo.disabled=true;
	this.setPlayMode(1);
	this.setPlayIndex(0);
//	try{
	if(this.markersLoaded()){
		this.map.getNthMarker(this.markersLoaded()).blink(false,0);
//		if(this.map.getNthMarker(this.markersLoaded()).getMouseOutEnabled()){
		this.map.getNthMarker(this.markersLoaded()).restoreMarkerZIndex();
		this.map.getNthMarker(this.markersLoaded()).resetTooltipClass(); // change css class
	}
//	}catch(e){}
	this.map.showControls();
	mgrView.timerID=setInterval("mgrView.play_kml()", 10);
};

nsMgrWaypts.prototype.stop_play = function(){
	document.myform.but_stop_play.disabled=true;
	document.myform.but_start_demo.disabled=false;
	document.myform.but_stop_demo.disabled=true;
	this.setPlayMode(0);
	mgrView.play_kml();
	this.map.showControls();
};

nsMgrWaypts.prototype.start_demo = function(){
	this.setDemoMode(1);
	this.setPointIndex(0);
	this.aVisitMarkers = new Array();
	this.aVisitKMLFiles = new Array();	// holds all filenames currently loaded as waypoints
	this.aVisitKMLFiles = this.aAllKMLFiles.slice();
	this.start_play();
	document.myform.but_stop_play.disabled=true;
	document.myform.but_start_demo.disabled=true;
	document.myform.but_stop_demo.disabled=false;
}

nsMgrWaypts.prototype.stop_demo = function(){
	this.aVisitKMLFiles = this.aVisitKMLFiles.slice(0, this.getPlayIndex());
	this.stop_play();
	// Only keep those waypoints loaded on screen (already visited as part of demo)
	if(this.getPlayIndex() > 0){
		document.myform.but_reset_waypoints.disabled=false;
		document.myform.but_start_play.disabled=false;
	}
	document.myform.but_start_demo.disabled=false;
	document.myform.but_stop_demo.disabled=true;
	this.setDemoMode(0);
};

// ??? don't access global bounds directly and pass this.aVisitMarkers.
nsMgrWaypts.prototype.redisplayMarker = function(mapMap, nIndex, pPoint){
	this.bounds=new GLatLngBounds();
	if(nIndex > 0){
		this.aVisitMarkers[nIndex-1].blink(true,500);
		this.aVisitMarkers[nIndex-1].topMarkerZIndex(); // bring marker to top
		this.aVisitMarkers[nIndex-1].setOpacity(100); 
		this.aVisitMarkers[nIndex-1].setTooltipClass("markerTooltip2"); // change css class
		this.aVisitMarkers[nIndex-1].redraw(true);
		// if the marker is 'featured' (clicked) then we want it to stay in the foreground
		if(nIndex > 1){
			this.aVisitMarkers[nIndex-2].blink(false,0);
			this.aVisitMarkers[nIndex-2].setOpacity(70); 
			if(this.aVisitMarkers[nIndex-2].getMouseOutEnabled()){
				this.aVisitMarkers[nIndex-2].restoreMarkerZIndex();
				this.aVisitMarkers[nIndex-2].resetTooltipClass(); // change css class
			}
			this.aVisitMarkers[nIndex-2].redraw(true);
		}
	}

	for(i=1;((nIndex-i)>=0 && i<=this.markersToTrail);i++){
		this.bounds.extend(this.aVisitMarkers[nIndex-i].getPoint());
		if(i>1 && nIndex-(i+2)>=0){
			var lastDistance = this.aVisitMarkers[nIndex-1].getPoint().distanceFrom( this.aVisitMarkers[nIndex-2].getPoint() ); // last distance
			var nextLastDistance = this.aVisitMarkers[nIndex-(i+1)].getPoint().distanceFrom( this.aVisitMarkers[nIndex-(1)].getPoint() ); //before last
//						// if the third-last marker is more than 8x the siatance, stop adding markers to bounds
			if( (lastDistance*this.nLastLeg2IgnoreFx) < (nextLastDistance)){
				break;	
			}
		}
	}
//				bounds.extend(this.aVisitMarkers[this.getPlayIndex()-1].getPoint());
	mapMap.setCenter(this.bounds.getCenter(), Math.max(Math.min(this.map.getBoundsZoomLevel(this.bounds),this.getZoomMax()),this.getZoomMin()), G_HYBRID_MAP);			
	mapMap.setFocus();
	if(this.isPlaying() && this.getPlayIndex() && this.markersLoaded()){
		mapMap.panTo(this.aVisitMarkers[this.getPlayIndex()-((this.isCruising())?1:1)].getPoint());
		mapMap.setFocus();
	}

};
// ??? add mapMap to prototype
nsMgrWaypts.prototype.addMarker = function(nIndex, pPoint){
	var icon = new GIcon(this.baseIcon);
	var number = ((((nIndex-1)%100)<10)?"0":"") + String((nIndex-1)%100);
	icon.image = "images/nicon" + number + ".png";
	var pdmkr_style={draggable: true, icon: icon, bouncy: true, bounceGravity: 0.1};
	marker = new PdMarker(pPoint, pdmkr_style);

	var restOfTitle="S/V Tahlequah - Google Cruising";
	try{
		restOfTitle = "<font size=-1>S/V Tahlequah<br />(" + number + ") " + this.aVisitKMLFiles[nIndex-2].replace("http://www.svtahlequah.com/Locations/", "").replace(".kmz","")+"<br /><a href='javascript:top.document.frames\[0\].mgrView.click2Cruise(\""+this.aVisitKMLFiles[nIndex-2].replace("http://www.svtahlequah.com/", "")+"\");' ><em>Click-2-Cruise<\/em><\/a><\/font><\/font>";
	}
	catch(e){
	}
	
	// Our info window content
	var infoTabs = [
	  new GInfoWindowTab("Info", '<div class="tooltip"><font size=-2>S/V Tahlequah'+restOfTitle+'<\/font><\/div>'),
	  new GInfoWindowTab("Updates", "Coming Soon... Direct link to related Updates."),
	  new GInfoWindowTab("Pictures", "Coming Soon... Direct link to related pics in Picture Gallery.")
	];
	
	var html="S/V Tahlequah - Google Cruising";
	if(nIndex > 1 && this.KMLfilesLoaded() >= (nIndex-1)){
		html = "<font size=-2><div align=center><b><font color=\"green\">Waypoint \""+this.aVisitKMLFiles[(nIndex-2)].replace("http://www.svtahlequah.com/Locations/","").replace(".kmz","")+"\"<\/font><br /><\/b><\/div><\/font>";
//						html="Waypoint "+this.aVisitKMLFiles[(nIndex-2)].replace("http://www.svtahlequah.com/Locations/","").replace(".kmz","");
	}
	// Set the initial (and restorable) z-index of the object
	marker.zIndex= nIndex;
	marker.oldZIndex= nIndex;
	marker.indexSaved= true;
	marker.setId(nIndex); 
	marker.enableDragging();
	marker.setTooltip("<font size =-2 color=\"yellow\">(information unavailable...)<\/font>");
	if(nIndex > 1 && this.KMLfilesLoaded() >= (nIndex-1)){
//		debugger;
		var cMarkerTooltip = ""+number+" "+(this.aVisitKMLFiles[(nIndex-2)].replace("http://www.svtahlequah.com/Locations/","").replace(".kmz","").replace("<br />"," ").replace("<br />"," ").replace("<br />"," "))+"";
		if(nIndex > 2){
			var lastPoint = new GLatLng(this.getLastVisitLat(),this.getLastVisitLng());
			var polyline = new GPolyline([lastPoint, pPoint], "#ff0000", 5);
			this.map.addOverlay(polyline);
			polyline.redraw(true);
		}
	}else{
		this.setLastVisitLat(nLat);
		this.setLastVisitLng(nLon);
	}
	
	marker.setTooltip(cMarkerTooltip);
	marker.setOpacity(70); 
	marker.setTooltipHiding(false); 
	marker.setCursor("help");
	this.addMarkerEvents(marker);
//	try{
//		var lastPoint = new GLatLng(this.getLastVisitLat(),this.getLastVisitLng());
//	}
//	catch(e){
//		this.setLastVisitLat(nLat);
//		this.setLastVisitLng(nLon);
//	}
//	var polyline = new GPolyline([lastPoint, pPoint], "#ff0000", 5);
//	this.map.addOverlay(polyline);
//	polyline.redraw(true);
	this.map.addOverlay(marker);
	// store original location so we can draw a line back to it after dragging marker
	marker.setUserData(new GLatLng(marker.getPoint().lat(),marker.getPoint().lng()));
	marker.setUserData2("");
	marker.allowLeftTooltips(true); // allways allow left side for ALL markers
	// warning: lots of blinking markers will slow your page
	marker.blink(true,500); // make this marker blink every 1/2 second	// ??? error - marker undefined?
	marker.setMouseOutEnabled(false); // hide after hover
	marker.showTooltip(); // force tooltip to appear
	// Now reset last marker to 'already shown' mode, while respecting current clicked-state
	if(nIndex-3 >= 0){
		// The user may have already clicked and reset this, so we don't change setMuoseOutEnabled()
//						this.aVisitMarkers[this.getPointIndex()-3].setMouseOutEnabled(false); // hide after hover
		this.aVisitMarkers[nIndex-3].blink(false,0); // stop blinking
		this.aVisitMarkers[nIndex-3].setTooltipClass("markerTooltip2"); // change css class
		this.aVisitMarkers[nIndex-3].restoreMarkerZIndex(); // change css class
		this.aVisitMarkers[nIndex-3].redraw(true); // force redraw of marker
	}
	// reset all prior markers to force tooltip reposition and redraw (except where already manually clicked/reset)
	for(i=0;i<this.markersLoaded()-1;i++){
		// change (reset) the class to 'featured' (forces proper redraw on call to redraw()
		this.aVisitMarkers[i].resetTooltipClass();
		// if we have a marker manually set to be 'featured' (via click) then we don't set it's class to 'not featured'
		if(!this.aVisitMarkers[i].getMouseOutEnabled()){
			this.aVisitMarkers[i].setTooltipClass("markerTooltip2"); // change css class to non'featured'
		}
		this.aVisitMarkers[i].restoreMarkerZIndex(); // change css z-index (back/front)
		this.aVisitMarkers[i].redraw(true); // force redraw of markers in order of placement (chronological trip)
	}
	marker.topMarkerZIndex(); // bring marker to top
	marker.redraw(true);	// force redraw of 'current' marker *after* 'last' marker has redrawn
	try{
		this.aVisitMarkers[nIndex-2]=marker;
	}
	catch(e){
	}
	return marker;
};

nsMgrWaypts.prototype.addMarkerEvents = function(markerMarker){
	GEvent.addListener(markerMarker, "click", function() {
		if (this.getMouseOutEnabled()){
			// don't hide on hover, disable setImage, restoreImage
			this.setMouseOutEnabled(false);
			this.setOpacity(100); // not transparent
			this.setTooltipClass("markerTooltip2"); // change css class
		}
		else{
			this.setMouseOutEnabled(true); // hide after hover
			this.setOpacity(100); // 0% transparent
			this.resetTooltipClass(); // restore default css class
		}
		this.redraw(true);
		}
	);
	
	GEvent.addListener(markerMarker, "dragstart", function() {
	  this.map.closeInfoWindow();
	  });
	  
	GEvent.addListener(markerMarker, "dragend", function() {
		// we need to draw a line between the new markerMarker point and the original one
		var polyline = new GPolyline([this.getUserData(), this.getPoint()], "#FFFFFF", 2);	// WHite 2px line
		// UserData2 holds the PolyLine we're using to connect this markerMarker to it's original location after being dragged
//						if(this.getUserData2()){
		// If we already have a line drawn then we'll remove it
		var oldPolyline = this.getUserData2();
		this.map.removeOverlay(oldPolyline);
//		oldPolyline.remove();
		this.setUserData2("");
		this.map.addOverlay(polyline);
		// now we'll save a ref to the the new one so we can destroy it  we need to redraw it again
		this.setUserData2(polyline);
		// change (reset) the class to 'featured' (forces proper redraw on call to redraw()
		this.resetTooltipClass();
		// if we have a markerMarker manually set to be 'featured' then we don't set it's class to 'not featured'
		if(!this.getMouseOutEnabled()){
			this.setTooltipClass("markerTooltip2"); // change css class to non'featured'
			this.restoreMarkerZIndex();
		}
		this.redraw(true);
		}
	);
	
	GEvent.addListener(markerMarker, "dblclick", function() {
		//          	markerMarker.openInfoWindowTabsHtml([new GInfoWindowTab("Location","<img src=file:///C|/Dev/Tahlequah/%22%22+this.aVisitKMLFiles%5B(this.getPointIndex()-2)%5D.replace(%22.kmz%22,%22.jpg%22)+%22/%22 /> <img src=file:///C|/Dev/Tahlequah/%22%22+icon.image+%22/%22 /> "+cMarkerTooltip), new GInfoWindowTab("Click2Cruise",restOfTitle), new GInfoWindowTab("Load KMZ","<font size =-1><a href=\""+this.aVisitKMLFiles[(this.getPointIndex()-2)]+"\">"+this.aVisitKMLFiles[(this.getPointIndex()-2)].replace("http://www.svtahlequah.com/Locations/","").replace(".kmz","").replace("<br />"," - ")+"<\/a><\/font>")]);
		this.showMapBlowup();
//						this.redraw(true);
		}
	);

	GEvent.addListener(markerMarker, "mouseover", function() {
//						this.setImage(this.getIcon().image); // change graphic
		this.blink(false,0); // in case it's blkinking then stop so we can begin to drag
		this.topMarkerZIndex(); // bring markerMarker to top
		this.setOpacity(100); 
		this.redraw(true);
		}
	); 

	GEvent.addListener(markerMarker, "mouseout", function() {
		this.setOpacity(70); 
//						this.restoreImage();
		// if the markerMarker is 'featured' then we want it to stay in the foreground
		if(this.getMouseOutEnabled()){
			this.restoreMarkerZIndex();
			}
		this.redraw(true);
		}
	);
};
//nsMgrWaypts.prototype.getHomeLat = function(){
//	return this.homelat;
//};
//nsMgrWaypts.prototype.getHomeLng = function(){
//	return this.homelng;
//};
nsMgrWaypts.prototype.doCalculateDecDeg = function(nVar,nMode)
{
	// nMode = 1 for Lat, 2 for Lon otherwise don't return NWSE
	var degrees = 0;
	var degreesTemp = 0.0;
	var minutes = 0;
	var minutesTemp = 0.0;
	var seconds = 0;
	var secondsTemp = 0.0;
	var message = '';

	degreesTemp = parseFloat(nVar);
	degrees     = Math.floor(degreesTemp);

	minutesTemp = degreesTemp - degrees;
	minutesTemp = 60.0 * minutesTemp;
	minutes     = Math.floor(minutesTemp);

	secondsTemp = minutesTemp - minutes;
	secondsTemp = 60.0 * secondsTemp;
	seconds     = Math.round(secondsTemp);

	message  = '' + parseInt(degrees) + ' ';
	message += '' + parseInt(minutes) + '\'';
	message += '' + parseInt(seconds) + '"';

	if(nMode==1) message += (degrees>0)?"N":"S";
	if(nMode==2) message += (degrees>0)?"E":"W";

	return message;
}


//---------------------------------------------------------------------------
// View Manager
//---------------------------------------------------------------------------
function nsMgrView(mgrWaypoints){
	this.mgrWaypnts=mgrWaypoints;
	this.setInstructions();
//	this.timerID=0;
//	this.timerID2=0;
};
nsMgrView.prototype.mgrWaypnts;
nsMgrView.prototype.teleportSpeed=5.0;
nsMgrView.prototype.instructions='';
nsMgrView.prototype.timerID=0; // for GMap sync
nsMgrView.prototype.timerID2=0; // for GMap sync
nsMgrView.prototype.zoom_effect=0; // for "CTU-style" boxes on zoom-change

nsMgrView.prototype.getTeleportSpeed = function() {
	return this.teleportSpeed;
};
nsMgrView.prototype.setTeleportSpeed = function(speed) {
	this.teleportSpeed=speed;
};
nsMgrView.prototype.getInstructions = function() {
	return this.instructions
};
nsMgrView.prototype.drawInstructions = function() {
	return document.write(this.getInstructions())
};
nsMgrView.prototype.setInstructions = function() {
	var s='';
		s+='<table width="100%"  border="0" cellspacing="1" cellpadding="1">';
		s+='<tr>';
			s+='<td width="50%"><font color=\"red\" size=-1>If the above Google Earth 4 player does not load then please do the following;</font></td>';
			s+='<td>&nbsp;</td>';
		s+='</tr>';
		s+='<tr>';
			s+='<td width="50%" class="softwareInstructions"><div id="geactivex"><br /><a target="new" href="http://earth.google.com/download-earth.html"> 1. Download and install Google Earth 4 if you have not already done so.<br /><img border="0" src="http://www.svtahlequah.com/Locations/download_earth.gif" /> </a></div></td>';
			s+='<td class="softwareInstructions" rowspan="1"><div align="center"><img src="http://www.svtahlequah.com/images/googleearth.gif" alt="Google Earth" width="150" height="53" /><img src="http://www.svtahlequah.com/images/google%20earth%20art.gif" alt="Google Earth" width="143" height="53" /></div></td>';
		s+='</tr>';
		s+='<tr>';
			s+='<td class="softwareInstructions"><a href="http://www.svtahlequah.com/Locations/setup.exe">2. Click here to download the required ActiveX control (Internet Explorer 6+ or Firefox 1.5+ required) and click Run when the Run/Save/Cancel dialog appears.<br /><img border="0" src="http://www.svtahlequah.com/images/downloadgeplugin.jpg" />  Follow all prompts to install and then restart Internet Explorer). </a><b><em> v2 updated 03/09/2007</em></b></td>';
			s+='<td class="softwareInstructions" rowspan="1"><div align="center"></div></td>';
		s+='</tr>';
		s+='<tr>';
			s+='<td class="softwareInstructions"><em>Thanks to <a href="http://www.googleearthairlines.com/" target="_blank">Google Earth Airlines</a> for the Google Earth ActiveX control</em></td>';
			s+='<td>&nbsp;</td>';
		s+='</tr>';
	s+='</table>';
	this.instructions=s;
};

nsMgrView.prototype.drawRightControls = function(){
	this.mgrWaypnts.logThis("drawRightControls - Re-drawing Right Controls");
	var sVar = '';
	var sOrigVar = '';
	try{
		sOrigVar = document.getElementById('ShowNow').innerHTML;
	}catch(e){
		sOrigVar = '';
	}
	
	sVar +='<table width="100%" border="0" cellpadding="0" cellspacing="0">';
	sVar +='<tr width="100%" valign="top">';
	sVar +='<td width="100%" class="sectionBanner">Locations ('+this.mgrWaypnts.waypts.length+')<\/td>';
	sVar +='</tr>';
	sVar +='<tr>';
	
	sVar +='<td valign="top">';
	sVar +='<select id="cancionGE" onchange="mgrWaypts.loadkml(document.getElementById(\'cancionGE\').value)" size="1" name="cancionGE" class="options_1" style="width: 100%">';
	
	sVar +='<option value="">=~= Select Location =~=</option>';
//	debugger;
	for(i=0;i<(this.mgrWaypnts.waypts.length);i++){
		sVar +='<option value="'+this.mgrWaypnts.waypts[i].getFilename()+'">'+this.mgrWaypnts.waypts[i].getDesc()+'</option>';
	};
	sVar +='</select><br /></td></tr>';
	sVar +='<tr>';
	sVar +='<td><center><a name="ShowNow" class="style5" id="ShowNow">'+sOrigVar+'</a>';
	sVar +='</center></td>';
	sVar +='</tr>';

	sVar +='<tr width="100%">';
	sVar +='<td width="100%" class="sectionBanner">All Waypoints ('+this.mgrWaypnts.markersLoaded()+')<\/td>';
	sVar +='</tr>';
	sVar +='<tr>';
	
	sVar +='<td valign="top">';
//	sVar +='<select id="visitedGE2" onchange="mgrWaypts.loadkml(document.getElementById(\'visitedGE2\').value)" size="1" name="visitedGE2" class="options_1" style="width: 100%">';
	sVar +='<select id="visitedGE2" onchange="mgrView.click2Cruise(document.getElementById(\'visitedGE2\').value)" size="1" name="visitedGE2" class="options_1" style="width: 100%">';
	
	sVar +='<option value="">=~= Select Waypoint =~=</option>';
//	debugger;
	for(i=0;i<this.mgrWaypnts.markersLoaded();i++){
		sVar +='<option value="'+this.mgrWaypnts.waypts[i].getFilename()+'">'+((((i+1)%100)<10)?"0":"") + String((i+1)%100)+"-"+this.mgrWaypnts.waypts[i].getDesc()+'</option>';
	};
	sVar +='</select>';
	sVar +='<br /><hr /></td></tr>';
	sVar +='</table>';
	document.getElementById("rightarea").innerHTML=sVar;
};

nsMgrView.prototype.drawRightMapControls = function(){
	this.mgrWaypnts.logThis("syncMap - Re-drawing Right Map Controls");
	var sVar = '';
	sVar +='<table nowrap width="100%" border="0" cellpadding="0" cellspacing="0">';
	sVar +='<tr width="100%">';
	sVar +='<td colspan="3" width="100%" style="font-size:9pt; text-align: center" >Recent Waypoints ('+Math.min(this.mgrWaypnts.markersLoaded(),this.mgrWaypnts.nWaypoints2Disp)+')<\/td>';
	sVar +='</tr>';
	for(i=this.mgrWaypnts.markersLoaded()-1;(i>=0 && i >= (this.mgrWaypnts.markersLoaded()-this.mgrWaypnts.nWaypoints2Disp));i--){
		sVar +='<tr><td style="font-size:6pt; text-align: left" width="*">';
		sVar +='<a title="Click here to travel to ==> '+this.mgrWaypnts.waypts[i].getDesc()+'  @ Lat: '+this.mgrWaypnts.doCalculateDecDeg(this.mgrWaypnts.aVisitMarkers[i].getPoint().lat(),1).replace('"',"&quot;")+' / lng: '+this.mgrWaypnts.doCalculateDecDeg(this.mgrWaypnts.aVisitMarkers[i].getPoint().lng(),2).replace('"',"&quot;")+'." href="javascript:mgrView.click2Cruise(\'http://www.svtahlequah.com/Locations/'+this.mgrWaypnts.waypts[i].getKMZ()+'\')">'+((((i+1)%100)<10)?"0":"") + String((i+1)%100)+"-"+this.mgrWaypnts.waypts[i].getDesc()+'</a>';
		sVar +='</td><td nowrap style="font-size:5pt; text-align: left;"><font color="'+((parseFloat(this.mgrWaypnts.aVisitMarkers[i].getPoint().lat())<0)?'red':'blue')+'">'+this.mgrWaypnts.doCalculateDecDeg(this.mgrWaypnts.aVisitMarkers[i].getPoint().lat(),1)+'</font></td><td nowrap style="font-size:5pt; text-align: left;" >';
		sVar +='<font color="'+((parseFloat(this.mgrWaypnts.aVisitMarkers[i].getPoint().lng())<0)?'red':'blue')+'">'+this.mgrWaypnts.doCalculateDecDeg(this.mgrWaypnts.aVisitMarkers[i].getPoint().lng(),2)+'</font>';
		sVar +='</td></tr>';
	};
	sVar +='</table>';
	try{
		document.getElementById("rightareaMap").innerHTML=sVar;
	}catch(e){}

	sVar ='';
	sVar +='<select id="visitedGE" onchange="mgrWaypts.loadkml(document.getElementById(\'visitedGE\').value)" size="1" name="visitedGE" class="options_1" style="width: 100%">';
	sVar +='<option value="">=~= Older Waypoints  ('+Math.max((this.mgrWaypnts.markersLoaded()-this.mgrWaypnts.nWaypoints2Disp),0)+') =~=</option>';
	
	for(i=(this.mgrWaypnts.markersLoaded()-this.mgrWaypnts.nWaypoints2Disp-1);i>=0;i--){
//		var obj = GEDest[i];
		sVar +='<option value="'+this.mgrWaypnts.waypts[i].getFilename()+'">'+((((i+1)%100)<10)?"0":"") + String((i+1)%100)+"-"+this.mgrWaypnts.waypts[i].getDesc()+'</option>';
	};
	sVar +='</select>';
	try{
		document.getElementById("rightareaMapLower").innerHTML=sVar;
	}catch(e){}

};

nsMgrView.prototype.drawBody = function(){
	var nHeight=0;
	var nWidth=0;
	var nLeftWidth=200;
	var nRightWidth=200;
	
	if ((screen.width>=1600) && (screen.height>=1200)){
		nHeight=625;
		nWidth=1200;
	}
	else if ((screen.width>=1280) && (screen.height>=1024)){
		nHeight=525;
		nWidth=950;
	}
	else if ((screen.width>=1024) && (screen.height>=768)){
		nHeight=375;
		nWidth=800;
	}
	else{
		nLeftWidth=150;
		nRightWidth=150;
		nHeight=275;
		nWidth=500;
	}
	document.write('<table width="100%" cellpadding="3" cellspacing="3" style="background-color: #000088; border-style: outset; border-width: 1px" height="'+nHeight+'px"><tr><td width="'+nLeftWidth+'px" height="'+nHeight+'px">');
	document.write('<div id="leftarea" name="leftarea" class="leftarea">');
	this.drawLeftControls();
	document.write(' </div>');
	document.write('</td><td id="centerarea" name="centerarea" class="centerarea" align="center" width="*" height="'+nHeight+'px">');
	document.write('<div id="ieDiv" name="ieDiv" class="ieDiv" height="100%" width="100%">');
	document.write('<div id="ieContainer" name="ieContainer" class="ieContainer" height="100%" width="100%">');
	document.write('</div></div>');
	document.write('</td><td width="'+nRightWidth+'px">');
	document.write('<div id="rightarea" name="rightarea" class="rightarea" >');
	document.write(' </div>');
	this.drawRightControls();
	document.write('</td></tr>');
	document.write('<tr><td colspan="3">');
	document.write('<div id="content" name="content"> </div>');
	document.write('</td></tr></table>');		
	document.write('<span class="booklink">Please note: This page is not cartographic and should not be used for navigational purposes.</span>');
	this.drawRightMapControls();
	doResize();
	ApplicationGE.Plugin("ieContainer");
	window.location.hash="#TopView";
	geOpenFile("http://www.svtahlequah.com/Locations/Home.kmz", 0);  // 0 unused param 
	geSetAutoPilotSpeed(ApplicationGE, this.mgrWaypnts.getAutoPilotSpeed());

};
// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
nsMgrView.prototype.setCheckedValue = function(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
};
// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
nsMgrView.prototype.getCheckedValue = function(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
};
nsMgrView.prototype.say_finished_playing = function (){
	try{
		var ls_msg='<font size=-2><div align=center><b><font color="green">Player Finished!  Now Viewing Waypoint: "'+this.mgrWaypnts.aVisitKMLFiles[this.mgrWaypnts.getPlayIndex()-1].replace("http://www.svtahlequah.com/Locations/","").replace(".kmz","")+'" '+' ('+(this.mgrWaypnts.getPlayIndex())+" of "+this.mgrWaypnts.KMLfilesLoaded()+")!<br /><\/font><\/b><\/div><\/font>";
		this.say_it_avec_marquee('MapShowNow',ls_msg);
	}catch(e){}
};
nsMgrView.prototype.say_playing_waypoint = function (){
	try{
		var ls_msg="<font size=-2><div align=center><b><font color=\"green\">Playing Waypoint: \""+this.mgrWaypnts.aVisitKMLFiles[this.mgrWaypnts.getPlayIndex()-1].replace("http://www.svtahlequah.com/Locations/","").replace(".kmz","")+"\" --> ("+(this.mgrWaypnts.getPlayIndex())+" of "+this.mgrWaypnts.KMLfilesLoaded()+")<\/font><br /><\/b><\/div><\/font>";
		this.say_it_avec_marquee('MapShowNow',ls_msg);
	}catch(e){}
};
nsMgrView.prototype.say_now_playing_waypoint = function (){
	try{
		var ls_msg="<font size=-2><div align=center><b><font color=\"green\">Now Playing Waypoint: \""+this.mgrWaypnts.aVisitKMLFiles[this.mgrWaypnts.getPlayIndex()].replace("http://www.svtahlequah.com/Locations/","").replace(".kmz","")+"\" --> ("+(this.mgrWaypnts.getPlayIndex()+1)+" of "+this.mgrWaypnts.KMLfilesLoaded()+")!<\/font><br /><\/b><\/div><\/font>";
		this.say_it_avec_marquee('MapShowNow',ls_msg);
	}catch(e){}
};
nsMgrView.prototype.say_loading_maps = function (){
	try{
		var ls_msg="<font size=-2><div align=center><b><font color=\"green\">Loading GoogleMaps Waypoint: \""+this.mgrWaypnts.aVisitKMLFiles[this.mgrWaypnts.getPlayIndex()-1].replace("http://www.svtahlequah.com/Locations/","").replace(".kmz","")+"\" --> ("+(this.mgrWaypnts.getPlayIndex())+" of "+this.mgrWaypnts.KMLfilesLoaded()+")<\/font><br /><\/b><\/div><\/font>";	
		this.say_it_avec_marquee('MapShowNow',ls_msg);
	}catch(e){}
};
nsMgrView.prototype.say_cruising_ge = function (){
	try{
		var ls_msg="<font size=-2><div align=center><b><font color=\"green\">Now Cruising to GoogleEarth Waypoint: \""+this.mgrWaypnts.aVisitKMLFiles[this.mgrWaypnts.getPlayIndex()].replace("http://www.svtahlequah.com/Locations/","").replace(".kmz","")+"\" --> ("+(this.mgrWaypnts.getPlayIndex()+1)+" of "+this.mgrWaypnts.KMLfilesLoaded()+")!<\/font><br /><\/b><\/div><\/font>"; 
		this.say_it_avec_marquee('MapShowNow',ls_msg);
	}catch(e){}
};
nsMgrView.prototype.say_start = function (){
	try{
		var ls_msg="<font size=-2><div align=center><b><font color=\"green\">Select Location or click [Start Demo] to visit pre-loaded Waypoints!<\/font><br /><\/b><\/div><\/font>";
	}catch(e){}
		this.say_it_avec_marquee('MapShowNow',ls_msg);
};
nsMgrView.prototype.say_just_loaded_as = function (){
	try{
		this.mgrWaypnts.logThis("Just Loaded Waypoint");
		var ls_msg="<font size=-2><div align=center><b><font color=\"green\">Waypoint \""+this.mgrWaypnts.aVisitKMLFiles[this.mgrWaypnts.getPointIndex()-2].replace("http://www.svtahlequah.com/Locations/","").replace(".kmz","")+"\" Loaded as "+((((this.mgrWaypnts.getPointIndex()-1)%100)<10)?"0":"") + String((this.mgrWaypnts.getPointIndex()-1)%100)+" "+" ("+(this.mgrWaypnts.getPointIndex()-1)+(this.mgrWaypnts.isDemoRunning())?" of "+aKMLFiles.length:" so far)"+"<\/font><br /><\/b><\/div><\/font>";
		this.say_it_avec_marquee('MapShowNow',ls_msg);
	}
	catch(e){
		this.mgrWaypnts.logThis("syncMap - Catch(e) - Just Loaded Waypoint");
	}
};
nsMgrView.prototype.say_it_avec_marquee = function (elem,msg){
	var ls_tag_begin = "<MARQUEE height=14px behavior=slide direction=up>";
	var ls_tag_end   = "</MARQUEE>";
	var ls_orig_msg  = document.getElementById(elem).innerHTML;
	try{
		if(ls_orig_msg != msg && (ls_orig_msg != ls_tag_begin+msg+ls_tag_end)){
			document.getElementById(elem).innerHTML=ls_tag_begin+msg+ls_tag_end;
			this.mgrWaypnts.logThis("syncMap - Just Loaded Waypoint");
		}
	}catch(e){
		this.mgrWaypnts.logThis("syncMap - CATCH(e) Just Loaded Waypoint");
	}
};
nsMgrView.prototype.play_kml = function (){
	if(this.mgrWaypnts.getPlayIndex()>=(this.mgrWaypnts.KMLfilesLoaded()) || (!this.mgrWaypnts.isPlaying()))	{
		clearInterval(this.timerID);
		this.syncMap();
		this.say_finished_playing();
		this.mgrWaypnts.setDemoMode(0);
		if(this.mgrWaypnts.KMLfilesLoaded()>0){
			document.myform.but_reset_waypoints.disabled=false;
			document.myform.but_start_play.disabled=false;
		}
		document.myform.but_stop_play.disabled=true;
		document.myform.but_start_demo.disabled=false;
		document.myform.but_stop_demo.disabled=true;
		return 0;
	}
	if (!geIsReady(ApplicationGE)){ 
		clearInterval(this.timerID);
		this.timerID=setInterval("mgrView.play_kml()", this.mgrWaypnts.getPauseMSecs()*(this.mgrWaypnts.isDemoRunning()?2:3));
		if(this.mgrWaypnts.isDemoRunning()){
		}else{
			this.say_playing_waypoint();
		}
	}else{
		this.say_loading_maps();
		if(this.mgrWaypnts.isDemoRunning()){
			clearInterval(this.timerID);
//			this.say_cruising_ge();
			this.mgrWaypnts.map.setFocus();
			this.mgrWaypnts.loadkml(this.mgrWaypnts.aVisitKMLFiles[this.mgrWaypnts.getPlayIndex()]);
			this.mgrWaypnts.setPlayIndex(this.mgrWaypnts.getPlayIndex()+1);
			this.syncMap();
			this.mgrWaypnts.map.setFocus();
			clearInterval(this.timerID);
			this.timerID=setInterval("mgrView.play_kml()", (this.mgrWaypnts.getPauseMSecs()*4));
		}else{
			this.mgrWaypnts.map.setFocus();
			this.say_now_playing_waypoint();
			this.mgrWaypnts.loadkml(this.mgrWaypnts.aVisitKMLFiles[this.mgrWaypnts.getPlayIndex()]);
			this.mgrWaypnts.setPlayIndex(this.mgrWaypnts.getPlayIndex()+1);
			this.syncMap();
			this.mgrWaypnts.map.setFocus();
			clearInterval(this.timerID);
			this.timerID=setInterval("mgrView.play_kml()", (this.mgrWaypnts.getPauseMSecs()*3));
		}
	}
};
nsMgrView.prototype.drawPage = function(){
	// Quote (in it's own table)
	document.write('<table width="98%"  border="0" cellpadding="1" cellspacing="1" class="Tahlequah">');
	document.write('<tr><td colspan="2"><span class="HomeQuote">"Eppur si muove" ("but it [the Earth] moves<span class="style2">"<\/span>) <\/span><\/td><\/tr><tr><td><\/td><td valign="top" align="left" class="UpdateLink"><em>- Galileo, rumored to have murmured while leaving the room after recanting before the inquisition<\/em><\/td><\/tr><\/table>');
	// Google Cruising logo
	document.write('<img src="http://www.svtahlequah.com/images/googleballs215x25.gif" alt="Google Cruises" />S/V Tahlequah <em>Google Cruising<\/em>... <font size=-2><em>no gyros here.<\/em><\/font><font class="style7" size=-1><strong><em>(Thanks to <a href="http://www.googleearthairlines.com/">Google Earth Airlines<\/a> for the Google Earth ActiveX control)<\/em><\/strong><\/font>');
	// Start Main Page
	document.write('<table valign="top" width="100%"  border="0" cellspacing="1" cellpadding="1" align="center">');
	document.write('<tr valign="top">');
	document.write('<td id="TopView" name="TopView" align="center" colspan="2" class="sectionBanner"><strong><div class="centerarea">"The Route" &agrave; la Google Maps &amp; Google Earth<\/div>');
	try{
		this.drawMap();
	}catch(e){}
	document.write('<\/strong>');
	document.write('<\/td>');
	document.write('<\/tr>');
	document.write('<tr align="center" valign="top" class="booklink">');
	document.write('<td colspan="2" align="left" valign="top"><span id="iePlugX" name="iePlugX">');
	try{
		this.drawBody();
	}catch(e){}
	finally{
		this.drawInstructions();
	}
	document.write('<\/span><\/td>');
	document.write('<\/tr>');
	document.write('<tr valign="top" align="center">');
	document.write('<td colspan="2" width="*" class="booklink"><a href="javascript:alert(\'Your screen-resolution is currently set to \'+screen.width+\' (width) x \'+screen.height+\' (height).\');" class="booklink">Click here for your screen resolution<\/a>  <em><font color=\"green\">&nbsp;&nbsp;&nbsp;(Press F11 to Maximize Screen Area for this page)&nbsp;<\/font><\/em><\/td>');
	document.write('<\/tr>');
	
	document.write('<tr>');
	document.write('<td align="left" colspan="2">');
};

nsMgrView.prototype.syncMap = function(){
	this.mgrWaypnts.logThis("syncMap ENTERED");
	// ??? REVISIT THIS CONDITION
	if(GBrowserIsCompatible()==false || isGEActXBAD()){
		this.mgrWaypnts.logThis("GBrowserIsCompatible() "+((GBrowserIsCompatible())?"True":"False"));
		this.mgrWaypnts.logThis("isGEActXBAD() "+((isGEActXBAD())?"True":"False"));
		this.mgrWaypnts.logThis("syncMap EXITED");
		return;
	}
	if (!this.mgrWaypnts.isPlaying() || this.mgrWaypnts.isDemoRunning()) {
		this.mgrWaypnts.logThis("syncMap PASSED (GBrowserIsCompatible() && !isGEActXBAD() && (!this.mgrWaypnts.isPlaying() || this.mgrWaypnts.isDemoRunning()))");
		var nLat = geGetLatitude(ApplicationGE);
		var nLon = geGetLongitude(ApplicationGE);
		var point = new GLatLng(nLat,nLon);
		this.mgrWaypnts.logThis("syncMap Lat: "+nLat+" Long: "+nLon+"");
		this.mgrWaypnts.logThis("syncMap lastLat: "+this.mgrWaypnts.getLastLat()+" lastLong: "+this.mgrWaypnts.getLastLng()+"");
		// If we're finished (or at least just getting more detail)
		if (!geIsReady(ApplicationGE) && !this.mgrWaypnts.isDemoRunning()){
			// update last lat/lon
			this.mgrWaypnts.logThis("syncMap PASSED (!geIsReady(ApplicationGE) && !this.mgrWaypnts.isDemoRunning())");
			this.mgrWaypnts.logThis("geIsReady(ApplicationGE) "+((geIsReady(ApplicationGE))?"True":"False"));
			this.mgrWaypnts.logThis("this.mgrWaypnts.isDemoRunning() "+((this.mgrWaypnts.isDemoRunning())?"True":"False"));
			this.mgrWaypnts.setLastLat(nLat);
			this.mgrWaypnts.setLastLng(nLon);
			clearInterval(this.timerID);
			this.mgrWaypnts.map.setFocus();
			this.timerID=setInterval("mgrView.syncMap()", this.mgrWaypnts.getPauseMSecs());
		}else{
			this.mgrWaypnts.logThis("syncMap FAILED (!geIsReady(ApplicationGE) && !this.mgrWaypnts.isDemoRunning())");
			clearInterval(this.timerID);
			this.mgrWaypnts.bounds = this.mgrWaypnts.setBounds(this.mgrWaypnts.map, this.mgrWaypnts.getPointIndex(), point);
			var zoomlvl = Math.min(Math.max(this.mgrWaypnts.map.getBoundsZoomLevel(this.mgrWaypnts.bounds)-((this.mgrWaypnts.isDemoRunning())?0:1),this.mgrWaypnts.getZoomMin()),this.mgrWaypnts.getZoomMax());
			this.mgrWaypnts.logThis("Setting Map Boundaries and Zoom-level.");
			this.mgrWaypnts.map.setCenter(this.mgrWaypnts.bounds.getCenter(), zoomlvl, G_HYBRID_MAP);
			
			// If looking at full Earth View, then show this.mgrWaypnts.map at similar zoom level, not at tightest possible for single center point
			if((nLat==0 || nLon==0)||(geGetRange(ApplicationGE)>10000000)||(this.mgrWaypnts.isDemoRunning()&&(this.mgrWaypnts.getPointIndex()<1))){
				this.mgrWaypnts.logThis("syncMap PASSED if((nLat==0 || nLon==0)||(kl.range>10000000)||(this.mgrWaypnts.isDemoRunning()&&(this.mgrWaypnts.getPointIndex()<1)))");
				zoomlvl = this.mgrWaypnts.getZoomMin();
				this.mgrWaypnts.logThis("Setting INITIAL Map Screen Coordinates.");
				this.mgrWaypnts.map.setCenter(new GLatLng(this.mgrWaypnts.getHomeLat(), this.mgrWaypnts.getHomeLng()), this.mgrWaypnts.getHomeZoom(), G_HYBRID_MAP);
			}else{
				this.mgrWaypnts.logThis("syncMap FAILED if((nLat==0 || nLon==0)||(kl.range>10000000)||(this.mgrWaypnts.isDemoRunning()&&(this.mgrWaypnts.getPointIndex()<1)))");
				this.mgrWaypnts.logThis("Setting initial map coordinates and zoom");
				this.mgrWaypnts.map.setCenter(this.mgrWaypnts.bounds.getCenter(), zoomlvl, G_HYBRID_MAP);
			}
			if(nLat!=0 && nLon!=0){
				this.mgrWaypnts.logThis("syncMap PASSED (nLat!=0 && nLon!=0)");
				if(this.mgrWaypnts.getPointIndex()){ 
					this.mgrWaypnts.setPointIndex(this.mgrWaypnts.getPointIndex()+1)
					this.mgrWaypnts.logThis("syncMap PASSED (this.mgrWaypnts.point_index++)");
					var marker = new Object(this.mgrWaypnts.addMarker(this.mgrWaypnts.getPointIndex(), point));
					this.drawRightControls();
					this.drawRightMapControls();
					try{
						enableTooltips("rightareaMap");
					}catch(e){}
					this.say_just_loaded_as();
					this.mgrWaypnts.setLastVisitLat(nLat);
					this.mgrWaypnts.setLastVisitLng(nLon);
				}else{
					this.mgrWaypnts.setPointIndex(this.mgrWaypnts.getPointIndex()+1)
					this.mgrWaypnts.logThis("syncMap FAILED (this.mgrWaypnts.point_index++) - NO MARKER");
					if(!this.mgrWaypnts.isDemoRunning()){
						this.say_start();
					}
				}
			}else{
				this.mgrWaypnts.logThis("syncMap FAILED (nLat!=0 && nLon!=0) - NONE SELECTED");
				this.say_start();
			}
		}
	}else{
	   if(this.mgrWaypnts.isPlaying()){
			this.mgrWaypnts.map.setFocus();
			this.mgrWaypnts.redisplayMarker(this.mgrWaypnts.map, this.mgrWaypnts.getPlayIndex());
		}
		this.mgrWaypnts.logThis("syncMap FAILED (GBrowserIsCompatible() && !isGEActXBAD() && (!this.mgrWaypnts.isPlaying() || this.mgrWaypnts.isDemoRunning()))");
	}
	this.mgrWaypnts.logThis("syncMap EXITED");
};

nsMgrView.prototype.drawMap = function(){
	var cWidth="900";
	var cHeight="375";
	var nLeftWidth=200;
	var nRightWidth=200;
	
	if ((screen.width>=1600) && (screen.height>=1200)){
		cWidth="900";
		cHeight="400";
	}
	else if ((screen.width>=1280) && (screen.height>=1024)){
		cWidth="750";
		cHeight="300";
	}
	else if ((screen.width>=1024) && (screen.height>=768)){
		cWidth="500";
		cHeight="200";
	}
	else{
		nLeftWidth=150;
		nRightWidth=150;
		cWidth="400";
		cHeight="175";
	}
	document.write('<table width="100%"><tr><td width="'+nLeftWidth+'px" class="leftareaMap"><div id="sidebar" style="text-align: right; width: '+nLeftWidth+'px; height: 150px">');
	document.write('<form name="myform">');
	//			document.write('<input type="button" name="but1" value="Add Waypoint! (from below)" onclick="syncMap()">');
	document.write('<a title="Demo Mode: Plays all 144 network-stored locations, in order, and places numbered Waypoint Markers on each destination as it travels."><input type="button" name="but_start_demo" disabled="true" style="width: 130px" value="Start Demo!" onclick="mgrWaypts.start_demo()";></a><br />');
	document.write('<a title="Stop Demo: Stops travelling to network-stored destinations and leaves all currently placed markers on the map for Play Mode."><input type="button" name="but_stop_demo" disabled="true" style="width: 130px" value="Stop Demo!" onclick="mgrWaypts.stop_demo()"></a>');
	document.write('<a title="Play Waypoints: Plays (travels to) all waypoint locations in order of numbered markers already on the map."><input type="button" name="but_start_play" disabled="true" style="width: 130px" value="Play Waypoints!" onclick="mgrWaypts.start_play()"></a><br />');
	document.write('<a title="Stop Play: Stops playing (travelling to) waypoints and leaves all currently placed markers on the map for additional Play Mode."><input type="button" name="but_stop_play" disabled="true" style="width: 130px" value="Stop Play!" onclick="mgrWaypts.stop_play()"></a><br />');
	document.write('<a title="Clear Waypoints: Clears all numbered markers currently on the map."><input type="button" name="but_reset_waypoints" disabled="true" style="width: 130px" value="Clear Waypoints!" onclick="mgrWaypts.reset_waypoints()"></a><br />');
	document.write('<\/FORM><\/div>');
	var sVar='';
	sVar += '<form name="radioGMapConfigForm" class="gm_settings" style="text-align: right; font-size: small" method="get" action="" onSubmit="return false;">';
	sVar += '</form>';
	document.write(sVar);
	document.write('<\/td>');
	document.write('<td align="left" width="'+(cWidth)+'px">');
	document.write('<div id="map" name="map" class="map" style="text-align: left; width: '+cWidth+'px; height: '+cHeight+'px" align="left"> <\/div><\/td><td class="rightareaMap" id="rightareaMap" name="rightareaMap" width="'+nRightWidth+'px"> <\/td><\/tr>');
	document.write('<tr valign="middle"><td><div name="pdmarkerwork" id="pdmarkerwork"><\/div><\/td><td class="centerareaMap"><div align="center" height="100%" width="100%" id="MapShowNow" name="MapShowNow"><font size=-1 color=\"red\"><b>Currently Loading Map, please wait...<\/b><\/font><\/div><\/td><td> <div id="rightareaMapLower" name="rightareaMapLower"> </div><\/td><\/tr>');
	document.write('<\/table>');
};

nsMgrView.prototype.drawLeftControls = function(){
	var sVar='';
	sVar += '<table width="100%" border="0" valign="top" align="right" cellpadding="0" cellspacing="0">';
	sVar += '<tr><td class="sectionBanner">Controls</td>';
	sVar += '</tr>';
	sVar += '<tr>';
	sVar += '<td>';
	sVar += '<form name="radioGEXConfigForm" class="ge_settings" style="text-align: right; font-size: small" method="get" action="" onSubmit="return false;">';
	sVar += 'Speed: <font size=-2><input type="RADIO" name="speed" value="0.05" onclick="javascript:mgrWaypts.setAutoPilotSpeed(0.05)" />S<input type="RADIO" name="speed" checked value="0.12" onclick="javascript:mgrWaypts.setAutoPilotSpeed(0.12)" />M<input type="RADIO" name="speed" value="0.90" onclick="javascript:mgrWaypts.setAutoPilotSpeed(0.90)" />F<input type="RADIO" name="speed" value="mgrWaypts.getTeleportSpeed()" onclick="javascript:mgrWaypts.setAutoPilotSpeed(mgrWaypts.getTeleportSpeed())" />Teleport&nbsp;<br /></font>';
	sVar += 'Latency: <font size=-2><input type="RADIO" name="latency" value="1" checked onclick="javascript:mgrWaypts.setPauseMSecs(1000)" />1<input type="RADIO" name="latency" value="5" checked="yes" onclick="javascript:mgrWaypts.setPauseMSecs(2000)" />2<input type="RADIO" name="latency" value="6" onclick="javascript:mgrWaypts.setPauseMSecs(5000)" />5 secs&nbsp;<br /></font>';
	sVar += '</form>';
	sVar += '</td>';
	sVar += '</tr>';
	sVar +='<tr><td class="sectionBanner">Features</td>';
	sVar +='</tr>';
	sVar +='<tr>';
	sVar +='<td><div align="center"><font face="arial">';
	sVar +='<table><tr><td>';
	sVar +='<a style="font-size:8pt" alt="Click Here to add more Island Names to Google Earth viewer" href="javascript:geOpenFile(\'http://www.svtahlequah.com/Locations/265204-Islands_names.kmz\')"> <font face="arial">Add<br />Island Names<br />to Google Earth</font> </a><br /><img src="http://www.svtahlequah.com/images/gelogoicon.gif" /> </font>';
	sVar +='</td><td>';
	sVar +='<a style="font-size:8pt" alt="Click Here to add more Active Volcano Names to Google Earth viewer" href="javascript:geOpenFile(\'http://www.svtahlequah.com/Locations/29013-active_volcanos.kml\')"> <font face="arial">Add Active<br /> Volcano Names<br />to Google Earth</font> </a><br /><img src="http://www.svtahlequah.com/images/gelogoicon.gif" /> </font>';
	sVar +='</td></tr></table>';
	sVar +='</div><hr /></td>';
	sVar +='</tr></table>';
	document.write(sVar);
};

nsMgrView.prototype.mapSetup = function(){
	this.mgrWaypnts.map = new GMap2(document.getElementById("map"));
	this.mgrWaypnts.map.enableContinuousZoom(true); //allows continuous zoom via mouse-wheel on some browsers
	this.mgrWaypnts.map.enableDoubleClickZoom(true); // nuff' said...
	//		GLog.write("Log Started");
	new GKeyboardHandler(this.mgrWaypnts.map);
	if(screen.width>=1280){
		this.lmcontrol = this.mgrWaypnts.map.addControl(new GLargeMapControl());
	}else{
		this.lmcontrol = this.mgrWaypnts.map.addControl(new GSmallMapControl());
	//			lmcontrol = this.mgrWaypnts.map.addControl(new GSmallZoomControl());
	}
	this.mtcontrol = this.mgrWaypnts.map.addControl(new GMapTypeControl());
	this.sccontrol = this.mgrWaypnts.map.addControl(new GScaleControl());
	this.ovcontrol = this.mgrWaypnts.map.addControl(new GOverviewMapControl());

	GEvent.addListener(this.mgrWaypnts.map, "click", function(marker, point) {
		if (marker && !mgrWaypts.isPlaying() && !mgrWaypts.isDemoRunning()) {
		} else {
		}
	//			new GKeyboardHandler(this); 
	});
	
	GEvent.addListener(this.mgrWaypnts.map, "doubleclick", function(marker, point) {
	  if (marker && !mgrWaypts.isPlaying() && !mgrWaypts.isDemoRunning()) {
	//			 map.removeOverlay(marker);
			this.panTo(point);
	  } else {
	//			 map.addOverlay(new GMarker(point));
			this.panTo(point);
	  }
	});
	
	GEvent.addListener(this.mgrWaypnts.map, "mouseover", function(marker, point) {
			mgrWaypts.map.showControls();
	});
	GEvent.addListener(this.mgrWaypnts.map, "mouseout", function(marker, point) {
			mgrWaypts.map.hideControls();
	});
	
	this.mgrWaypnts.map.setCenter(new GLatLng(this.mgrWaypnts.getHomeLat(), this.mgrWaypnts.getHomeLng()), this.mgrWaypnts.getHomeZoom(), G_HYBRID_MAP);
	
	this.mgrWaypnts.baseIcon = new GIcon();
	this.mgrWaypnts.baseIcon.shadow = "http://www.svtahlequah.com/images/shadow50.png";
	this.mgrWaypnts.baseIcon.iconSize = new GSize(20, 34);
	this.mgrWaypnts.baseIcon.shadowSize = new GSize(37, 34);
	this.mgrWaypnts.baseIcon.iconAnchor = new GPoint(9, 34);
	this.mgrWaypnts.baseIcon.infoWindowAnchor = new GPoint(9, 2);
	this.mgrWaypnts.baseIcon.infoShadowAnchor = new GPoint(18, 25);
	
	this.mgrWaypnts.setPointIndex(0);
	this.mgrWaypnts.map.clearOverlays();
	this.mgrWaypnts.bounds = new GLatLngBounds();

};

nsMgrView.prototype.setInitLayers = function() {
	clearInterval(this.timerID2);
	if(geIsReady(ApplicationGE)){
//		setLayer('borders',1);
//		this.setCheckedValue(document.forms['radioLayersForm'].elements['borders'],"On");
//		setLayer('Terrain',1);
//		this.setCheckedValue(document.forms['radioLayersForm'].elements['Terrain'],"On");
//		setLayer('Populated Places',1);
//		this.setCheckedValue(document.forms['radioLayersForm'].elements['Populated'],"On");
//		setLayer('Geographic Features',1);
//		this.setCheckedValue(document.forms['radioLayersForm'].elements['Geographic'],"On");
//		setLayer('Alternative Place Names',0);
//		this.setCheckedValue(document.forms['radioLayersForm'].elements['Alternative'],"Off");
//		setLayer('Parks and Recreation Areas',0);
//		this.setCheckedValue(document.forms['radioLayersForm'].elements['Parks'],"Off");
//		setLayer('roads',0);
//		this.setCheckedValue(document.forms['radioLayersForm'].elements['roads'],"Off");
	}else{
		this.timerID2=setInterval("mgrView.setInitLayers()", this.mgrWaypnts.getPauseMSecs()/4);
	}
};

// Used in HTML used for GMap2 Map Pointers.
nsMgrView.prototype.click2Cruise = function(kml2use){
	if(!this.mgrWaypnts.isDemoRunning() && !this.mgrWaypnts.isPlaying()){	
		this.mgrWaypnts.setCruiseMode(1);
		this.mgrWaypnts.setPlayMode(1);
		var itemNumber;
		var origPlayIndex=this.mgrWaypnts.getPlayIndex();
		try{	// un-blink last set marker (if blinking)
		this.mgrWaypnts.map.getNthMarker(this.markersLoaded()+1).blink(false,0);
//		if(this.mgrWaypnts.map.getNthMarker(this.markersLoaded()).getMouseOutEnabled()){
			this.mgrWaypnts.map.getNthMarker(this.markersLoaded()+1).restoreMarkerZIndex();
			this.mgrWaypnts.map.getNthMarker(this.markersLoaded()+1).resetTooltipClass(); // change css class
//		}
		}catch(e){}

		this.mgrWaypnts.loadkml(kml2use);
//		debugger;
		for(i=0;i<this.mgrWaypnts.KMLfilesLoaded();i++){
			if(this.mgrWaypnts.waypts[i].getFilename()==kml2use || this.mgrWaypnts.waypts[i].getKMZ()==kml2use){
				this.mgrWaypnts.setPlayIndex((i+1));
				break;
			}
		};
		this.syncMap();
		this.mgrWaypnts.setPlayIndex(origPlayIndex);
		this.mgrWaypnts.setPlayMode(0);
		this.mgrWaypnts.setCruiseMode(0);
	}else{
		alert("Click [Stop Play] or [Stop Demo] to cruise to a loaded (i.e. previuosly visited) Waypoint.");
	}
};

//---------------------------------------------------------------------------
// Setup Waypoints, WaypointMgr and ViewMgr
//---------------------------------------------------------------------------
//var waypoints;
var mgrWaypts;
var mgrView;

// Create Waypoint Manager and pass to View Mgr
mgrView = new nsMgrView((mgrWaypts = new nsMgrWaypts()));

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// still need to Re-factor
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------

function resize(){
	doResize();
}
function geOpenFile(kmlFile){
	ApplicationGE.OpenKmlFile(kmlFile,0);
}
function setLayer(name,value){
	var GFBNVar=ApplicationGE.GetFeatureByName(name);
	try{
		GFBNVar.Visibility=((value)?1:0);
		ApplicationGE.SetFeatureView(GFBNVar,mgrWaypts.getTeleportSpeed()); 		
	}catch(e){
//		debugger;
	}
}
function getLayer(name){
	var GFBNVar=ApplicationGE.GetFeatureByName(name);
	var nRetVal=-1;
	try{
		nRetVal=GFBNVar.Visibility;
	}catch(e){
//		debugger;
	}
	return nRetVal;
}
function setViewParams(params){
	nVar=params.split(" ")
   var values=params.split(" ");
	ApplicationGE.SetCameraParams(values[0],values[1],values[2],values[3],values[4],values[5],values[6],values[7]);
}
function Confirm(){
   if (ApplicationGE.Confirm()){
   	  //alert('confirmed');
   }
}

function geGetParams(plugin, param) {
   var retVal;
	// ??? This needs to be consistant and grab GPOTFSC or GC based on add'l parm.
	if(param == "latitude") {
		retVal = plugin.GetPointOnTerrainFromScreenCoords(0,0).Latitude;
	}
	if(param == "longitude") {
		retVal = plugin.GetPointOnTerrainFromScreenCoords(0,0).Longitude;
	}
	if(param == "altitude") {
		retVal = plugin.GetPointOnTerrainFromScreenCoords(0,0).Altitude;
	}
	if(param == "altimode") {
		retVal = plugin.GetCamera(1).FocusPointAltitudeMode;
	}
	if(param == "range") {
		retVal = plugin.GetCamera(1).Range;
	}
	if(param == "tilt") {
		retVal = plugin.GetCamera(1).Tilt;
	}
	if(param == "azimuth") {
		retVal = plugin.GetCamera(1).Azimuth;
	}

	return retVal;
}

function geIsReady(plugin) {
	var nVar=false;
	if(plugin.IsInitialized() && plugin.IsOnline()){
		nVar=(geGetSPP(plugin)==100);
	}
	return nVar?nVar:false;
}

function geGetLatitude(plugin) {
	var nVar = geGetParams(plugin, "latitude");
	return nVar?nVar:0;
}

function geGetLongitude(plugin) {
	var nVar = geGetParams(plugin, "longitude");
	return nVar?nVar:0;
}

function geGetAltitude(plugin) {
	var nVar =  geGetParams(plugin, "altitude");
	return nVar?nVar:0;
}

function geGetRange(plugin) {
	var nVar =  geGetParams(plugin, "range");
	return nVar?nVar:0;
}

function geGetTilt(plugin) {
	var nVar =  geGetParams(plugin, "tilt");
	return nVar?nVar:0;
}

function geGetAzimuth(plugin) {
	var nVar =  geGetParams(plugin, "azimuth");
	return nVar?nVar:0;
}

// ??? finish this func
function geSetParams(plugin, params) {
   var values=params.split(" ");
	plugin.SetCameraParams(values[0],values[1],values[2],values[3],values[4],values[5],values[6],values[7]);

}

function geSetLatitude(plugin) {
	var nVar = geSetParams(plugin, "latitude");
	return nVar?nVar:0;
}

function geSetLongitude(plugin) {
	var nVar = geSetParams(plugin, "longitude");
	return nVar?nVar:0;
}

function geSetAltitude(plugin) {
	var nVar =  geSetParams(plugin, "altitude");
	return nVar?nVar:0;
}

function geSetRange(plugin) {
	var nVar =  geSetParams(plugin, "range");
	return nVar?nVar:0;
}

function geSetTilt(plugin) {
	var nVar =  geSetParams(plugin, "tilt");
	return nVar?nVar:0;
}

function geSetAzimuth(plugin) {
	var nVar =  geSetParams(plugin, "azimuth");
	return nVar?nVar:0;
}

function geGetSPP(plugin) {
	var nVar = plugin.Get_StreamingProgressPercentage();
	return nVar?nVar:0;
}

function geGetAutoPilotSpeed(plugin) {
	var nVar = plugin.Get_AutoPilotSpeed();
	return nVar?nVar:0;
}

function geSetAutoPilotSpeed(plugin, speed) {
	var nVar = plugin.Set_AutoPilotSpeed(speed);
	return nVar?nVar:0;
}

function isGEActXBAD(){
return 0;
//try{
//	var form;
//	if (document.all) {
//		form=document.all['iePlug'];
//	}else {
//		form = document.getElementById('iePlug');
//	}
//   var kh=form.Viewer;
//	return 0;
//	}
//catch(e){
////   alert("Bad");
//	return 1;
//	}
}

function checkAssociation( sFileExt, sMimeType ){
	document.write("<a href='http://www.svtahlequah.com/Test."+sFileExt+"' name='TestLink' id='TestLink'></a>");
   WindowsFileType = document.all.TestLink.mimeType;
	if (WindowsFileType == sMimeType){
		return 1;
	}
	else {
		return 0;
	}
}

function check() { 
   for (i=0;i<monitor.length;i++) { 
     if (monitor[i]!=null) { 
       obj = document.getElementById('test_object'+i); 
       if (obj) { 
        if (obj.readyState!=0) { 
		     return 1;
//           alert("'"+monitor[i]+"' is on this machine"); 
        }else
		     return 0; 
        monitor[i] = null; 
       } 
     } 
   } 
}               

function checkApplication(clsId, name) { 
   s = '<object id="test_object'+monitor.length+'" '+'classid="clsid:'+clsId+'" ' +'codebase="view-source:about:blank"> </object>'; 
   document.writeln(s); 
   monitor[monitor.length] = name; 
	return check();
} 

function GEUnload(){
	if(ApplicationGE){
		if(ApplicationGE.IsInitialized() && ApplicationGE.IsOnline()){
			ApplicationGE.Logout();
		}
	}
}

