var ge;
var placemark;
var currentKmlObject = null;
var tourArray = new Array();
var allownewtour = true;
var waittime = 28000;
var popuphold = 14000;
var tourstop = new Array();
var tourstopcount = 0;
var tourstopexpect = 0;
var manualpopup = 0;
var idleid = 0;
var google_type = 0; // 0 = earth, 1 = map
var map;

// popup html
var arcticspan = '<iframe style="border: 0px;" width="100%" height="300" src="/content/includes/globes/popup/arcticspan.html"></iframe>';

var brasilspan = '<iframe style="border: 0px;" width="100%" height="300" src="/content/includes/globes/popup/brasilspan.html"></iframe>';
  	  
var caribespan = '<iframe style="border: 0px;" width="100%" height="300" src="/content/includes/globes/popup/caribespan.html"></iframe>';
  	  
var colombiaspan = '<iframe style="border: 0px;" width="100%" height="300" src="/content/includes/globes/popup/colombiaspan.html"></iframe>';
  	  
var waspan = '<iframe style="border: 0px;" width="100%" height="300" src="/content/includes/globes/popup/waspan.html"></iframe>';

var gulfspan = '<iframe style="border: 0px;" width="100%" height="300" src="/content/includes/globes/popup/gulfspan.html"></iframe>';

var indiaspan = '<iframe style="border: 0px;" width="100%" height="300" src="/content/includes/globes/popup/indiaspan.html"></iframe>';
  	  
var javaspan = '<iframe style="border: 0px;" width="100%" height="300" src="/content/includes/globes/popup/javaspan.html"></iframe>';

var easpan = '<iframe style="border: 0px;" width="100%" height="300" src="/content/includes/globes/popup/easpan.html"></iframe>';
		
var neatlanticspan = '<iframe style="border: 0px;" width="100%" height="300" src="/content/includes/globes/popup/neatlanticspan.html"></iframe>';
  	  
var novaspan = '<iframe style="border: 0px;" width="100%" height="300" src="/content/includes/globes/popup/novaspan.html"></iframe>';

var beaufort2 = '<a href="javascript: parent.ge.setBalloon(null);"><img src="/content/includes/globes/images/close.gif" width="10" height="10" style="border:0px; float: right;"/></a><img src="/content/includes/globes/images/featured_line_title.gif" width="200" height="21" style="margin: 0px 0px 5px 5px;" /><hr style="color: #8CC242; height: 2px; margin-top: 0px;">' +
  	  '<div style="margin:5px;"><p style="margin-top: 5px;"><a href="#" onClick="window.open(' +
  	  "'/content/includes/globes/sdisplay.asp?span=SPANS_ArcticSPAN_Beaufort2.jpg&w=1000&h=202','spanwindow11','width=1000,height=202,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes'); void('');" +
  	  '">Beaufort 2</a></p></div><hr style="color: #8CC242; height: 2px; margin-top: 0px;">';

var beaufort1 = '<a href="javascript: parent.ge.setBalloon(null);"><img src="/content/includes/globes/images/close.gif" width="10" height="10" style="border:0px; float: right;"/></a><img src="/content/includes/globes/images/featured_line_title.gif" width="200" height="21" style="margin: 0px 0px 5px 5px;" /><hr style="color: #8CC242; height: 2px; margin-top: 0px;">' +
  	  '<div style="margin:5px;"><p style="margin-top: 5px;"><a href="#" onClick="window.open(' +
  	  "'/content/includes/globes/sdisplay.asp?span=SPANS_ArcticSPAN_Beaufort_Data_WM.jpg&w=1000&h=283','spanwindow12','width=1000,height=283,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes'); void('');" +
  	  '">Beaufort 1</a></p></div><hr style="color: #8CC242; height: 2px; margin-top: 0px;">';

var chuckchi = '<a href="javascript: parent.ge.setBalloon(null);"><img src="/content/includes/globes/images/close.gif" width="10" height="10" style="border:0px; float: right;"/></a><img src="/content/includes/globes/images/featured_line_title.gif" width="200" height="21" style="margin: 0px 0px 5px 5px;" /><hr style="color: #8CC242; height: 2px; margin-top: 0px;">' +
  	  '<div style="margin:5px;"><p style="margin-top: 5px;"><a href="#" onClick="window.open(' +
  	  "'/content/includes/globes/sdisplay.asp?span=SPANS_ArcticSPAN_Chukchi_Data_WM.jpg&w=1000&h=202','spanwindow13','width=1000,height=202,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes'); void('');" +
  	  '">Chukchi</a></p></div><hr style="color: #8CC242; height: 2px; margin-top: 0px;">';

var brasil = '<a href="javascript: parent.ge.setBalloon(null);"><img src="/content/includes/globes/images/close.gif" width="10" height="10" style="border:0px; float: right;"/></a><img src="/content/includes/globes/images/featured_line_title.gif" width="200" height="21" style="margin: 0px 0px 5px 5px;" /><hr style="color: #8CC242; height: 2px; margin-top: 0px;">' +
  	  '<div style="margin:5px;"><p style="margin-top: 5px;"><a href="#" onClick="window.open(' +
  	  "'/content/includes/globes/sdisplay.asp?span=SPANS_BrasilSPAN_Data_WM.jpg&w=1000&h=202','spanwindow14','width=1000,height=202,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes'); void('');" +
  	  '">BrasilSPAN</a></p></div><hr style="color: #8CC242; height: 2px; margin-top: 0px;">';

var caribe = '<a href="javascript: parent.ge.setBalloon(null);"><img src="/content/includes/globes/images/close.gif" width="10" height="10" style="border:0px; float: right;"/></a><img src="/content/includes/globes/images/featured_line_title.gif" width="200" height="21" style="margin: 0px 0px 5px 5px;" /><hr style="color: #8CC242; height: 2px; margin-top: 0px;">' +
  	  '<div style="margin:5px;"><p style="margin-top: 5px;"><a href="#" onClick="window.open(' +
  	  "'/content/includes/globes/sdisplay.asp?span=SPANS_CaribeSPAN_Data_WM.jpg&w=1000&h=202','spanwindow15','width=1000,height=202,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes'); void('');" +
  	  '">CaribeSPAN</a></p></div><hr style="color: #8CC242; height: 2px; margin-top: 0px;">';

var colombia = '<a href="javascript: parent.ge.setBalloon(null);"><img src="/content/includes/globes/images/close.gif" width="10" height="10" style="border:0px; float: right;"/></a><img src="/content/includes/globes/images/featured_line_title.gif" width="200" height="21" style="margin: 0px 0px 5px 5px;" /><hr style="color: #8CC242; height: 2px; margin-top: 0px;">' +
  	  '<div style="margin:5px;"><p style="margin-top: 5px;"><a href="#" onClick="window.open(' +
  	  "'/content/includes/globes/sdisplay.asp?span=SPANS_ColombiaSPAN_Data_WM.jpg&w=1000&h=202','spanwindow16','width=1000,height=202,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes'); void('');" +
  	  '">ColombiaSPAN</a></p></div><hr style="color: #8CC242; height: 2px; margin-top: 0px;">';

var equator = '<a href="javascript: parent.ge.setBalloon(null);"><img src="/content/includes/globes/images/close.gif" width="10" height="10" style="border:0px; float: right;"/></a><img src="/content/includes/globes/images/featured_line_title.gif" width="200" height="21" style="margin: 0px 0px 5px 5px;" /><hr style="color: #8CC242; height: 2px; margin-top: 0px;">' +
  	  '<div style="margin:5px;"><p style="margin-top: 5px;"><a href="#" onClick="window.open(' +
  	  "'/content/includes/globes/sdisplay.asp?span=SPANS_EquatorSPAN_Data_WM.jpg&w=1000&h=288','spanwindow17','width=1000,height=288,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes'); void('');" +
  	  '">EquatorSPAN</a></p></div><hr style="color: #8CC242; height: 2px; margin-top: 0px;">';
  	  
var congo = '<a href="javascript: parent.ge.setBalloon(null);"><img src="/content/includes/globes/images/close.gif" width="10" height="10" style="border:0px; float: right;"/></a><img src="/content/includes/globes/images/featured_line_title.gif" width="200" height="21" style="margin: 0px 0px 5px 5px;" /><hr style="color: #8CC242; height: 2px; margin-top: 0px;">' +
  	  '<div style="margin:5px;"><p style="margin-top: 5px;"><a href="#" onClick="window.open(' +
  	  "'/content/includes/globes/sdisplay.asp?span=SPANS_CongoSPAN1_Data_WM.jpg&w=1000&h=202','spanwindow18','width=1000,height=202,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes'); void('');" +
  	  '">CongoSPAN 1</a></p></div><hr style="color: #8CC242; height: 2px; margin-top: 0px;">';
  	  
var nigeria = '<a href="javascript: parent.ge.setBalloon(null);"><img src="/content/includes/globes/images/close.gif" width="10" height="10" style="border:0px; float: right;"/></a><img src="/content/includes/globes/images/featured_line_title.gif" width="200" height="21" style="margin: 0px 0px 5px 5px;" /><hr style="color: #8CC242; height: 2px; margin-top: 0px;">' +
  	  '<div style="margin:5px;"><p style="margin-top: 5px;"><a href="#" onClick="window.open(' +
  	  "'/content/includes/globes/sdisplay.asp?span=SPANS_NigeriaSPAN_Data_WM.jpg&w=1000&h=202','spanwindow19','width=1000,height=202,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes'); void('');" +
  	  '">NigeriaSPAN</a></p></div><hr style="color: #8CC242; height: 2px; margin-top: 0px;">';

var gulf = '<a href="javascript: parent.ge.setBalloon(null);"><img src="/content/includes/globes/images/close.gif" width="10" height="10" style="border:0px; float: right;"/></a><img src="/content/includes/globes/images/featured_line_title.gif" width="200" height="21" style="margin: 0px 0px 5px 5px;" /><hr style="color: #8CC242; height: 2px; margin-top: 0px;">' +
  	  '<div style="margin:5px;"><p style="margin-top: 5px;"><a href="#" onClick="window.open(' +
  	  "'/content/includes/globes/sdisplay.asp?span=SPANS_GulfSPAN_Data_WM.jpg&w=1000&h=202','spanwindow20','width=1000,height=202,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes'); void('');" +
  	  '">GulfSPAN</a></p></div><hr style="color: #8CC242; height: 2px; margin-top: 0px;">';

var india = '<a href="javascript: parent.ge.setBalloon(null);"><img src="/content/includes/globes/images/close.gif" width="10" height="10" style="border:0px; float: right;"/></a><img src="/content/includes/globes/images/featured_line_title.gif" width="200" height="21" style="margin: 0px 0px 5px 5px;" /><hr style="color: #8CC242; height: 2px; margin-top: 0px;">' +
  	  '<div style="margin:5px;"><p style="margin-top: 5px;"><a href="#" onClick="window.open(' +
  	  "'/content/includes/globes/sdisplay.asp?span=SPANS_IndiaSPAN_Data_WM.jpg&w=1000&h=202','spanwindow21','width=1000,height=202,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes'); void('');" +
  	  '">IndiaSPAN</a></p></div><hr style="color: #8CC242; height: 2px; margin-top: 0px;">';
  	  
var javas = '<a href="javascript: parent.ge.setBalloon(null);"><img src="/content/includes/globes/images/close.gif" width="10" height="10" style="border:0px; float: right;"/></a><img src="/content/includes/globes/images/featured_line_title.gif" width="200" height="21" style="margin: 0px 0px 5px 5px;" /><hr style="color: #8CC242; height: 2px; margin-top: 0px;">' +
  	  '<div style="margin:5px;"><p style="margin-top: 5px;"><a href="#" onClick="window.open(' +
  	  "'/content/includes/globes/sdisplay.asp?span=SPANS_JavaSPAN_Data_WM.jpg&w=1000&h=288','spanwindow22','width=1000,height=288,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes'); void('');" +
  	  '">JavaSPAN</a></p></div><hr style="color: #8CC242; height: 2px; margin-top: 0px;">';
  	  
var eafrica = '<a href="javascript: parent.ge.setBalloon(null);"><img src="/content/includes/globes/images/close.gif" width="10" height="10" style="border:0px; float: right;"/></a><img src="/content/includes/globes/images/featured_line_title.gif" width="200" height="21" style="margin: 0px 0px 5px 5px;" /><hr style="color: #8CC242; height: 2px; margin-top: 0px;">' +
  	  '<div style="margin:5px;"><p style="margin-top: 5px;"><a href="#" onClick="window.open(' +
  	  "'/content/includes/globes/sdisplay.asp?span=SPANS_EastAfricaSPAN_Data.jpg&w=1000&h=202','spanwindow23','width=1000,height=202,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes'); void('');" +
  	  '">AfricaSPAN - East</a></p></div><hr style="color: #8CC242; height: 2px; margin-top: 0px;">';
  	  
var neatlantic = '<a href="javascript: parent.ge.setBalloon(null);"><img src="/content/includes/globes/images/close.gif" width="10" height="10" style="border:0px; float: right;"/></a><img src="/content/includes/globes/images/featured_line_title.gif" width="200" height="21" style="margin: 0px 0px 5px 5px;" /><hr style="color: #8CC242; height: 2px; margin-top: 0px;">' +
  	  '<div style="margin:5px;"><p style="margin-top: 5px;"><a href="#" onClick="window.open(' +
  	  "'/content/includes/globes/sdisplay.asp?span=SPANS_NEAtlanticSPAN_Data_WM.jpg&w=1000&h=202','spanwindow24','width=1000,height=202,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes'); void('');" +
  	  '">NEAtlanticSPAN</a></p></div><hr style="color: #8CC242; height: 2px; margin-top: 0px;">';

var nova = '<a href="javascript: parent.ge.setBalloon(null);"><img src="/content/includes/globes/images/close.gif" width="10" height="10" style="border:0px; float: right;"/></a><img src="/content/includes/globes/images/featured_line_title.gif" width="200" height="21" style="margin: 0px 0px 5px 5px;" /><hr style="color: #8CC242; height: 2px; margin-top: 0px;">' +
  	  '<div style="margin:5px;"><p style="margin-top: 5px;"><a href="#" onClick="window.open(' +
  	  "'/content/includes/globes/sdisplay.asp?span=SPANS_NovaSPAN_Data_WM.jpg&w=1000&h=288','spanwindow25','width=1000,height=288,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes'); void('');" +
  	  '">NovaSPAN</a></p></div><hr style="color: #8CC242; height: 2px; margin-top: 0px;">';
  	    	  
google.load("earth", "1");

// init
// place the google earth instance into the HTML
function init() {
  var content = document.getElementById('content');
  var inputHTML = '';
  content.innerHTML = inputHTML;
	document.getElementById('loading').style.display = 'inline';
	google_type = 0;
  google.earth.createInstance('content', initCB, failureCB);
}

// finishFetchKml
// called after the kml is loaded, checks it and adds it to the earth
function finishFetchKml(kmlObject) {
  // check if the KML was fetched properly
  if (kmlObject) {
    // add the fetched KML to Earth
    currentKmlObject = kmlObject;
    ge.getFeatures().appendChild(currentKmlObject);
    getPlacemarks();
    ge.getOptions().setFlyToSpeed(0.1);
    setTimeout("document.getElementById('loading').style.display = 'none';", 5000);
  } else {
    alert('ERROR: The KML or KMZ file is invalid or cannot be found.');
  }
}

// initCB
// initializes the earth's attributes and loads any KML/KMZ files needed
function initCB(instance) {
  ge = instance;
  ge.getWindow().setVisibility(true);

  // add a navigation control
  ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);

  // add some layers
  ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, false);
	ge.getLayerRoot().enableLayerById(ge.LAYER_TERRAIN, true);
	
	// set the movement functions
	google.earth.addEventListener(ge.getView(), 'viewchangebegin', stoptour);
  
  google.earth.addEventListener(ge.getView(), 'viewchangeend', function() {
	  //if (allownewtour) idleid = setTimeout("showtour();", 3*60*1000);
  });
	
	// load kmz
	google.earth.fetchKml(ge, "http://www.iongeo.com/content/includes/globes/BasinSpans.kmz", finishFetchKml);
	
  var pluginVersion = ge.getPluginVersion().toString();
  //document.getElementById('installed-plugin-version').innerHTML = 'Version: ' +  pluginVersion;
}

// failureCB
// failure function for the initialization, currently empty
function failureCB(errorCode) {}

google.setOnLoadCallback(init);

// stoptour
// called any time the user interacts with the globe. if the tour is going it stops the tour.
// it also kills the idle timeout. the idle timeout is reset everytime the earth stops moving.
function stoptour(force) {
	clearTimeout(idleid);
	tourstopcount++;
	if ((tourstopcount != tourstopexpect)||force) {
		clearTimeout(manualpopup);
  	for (var i = 0; i < tourstop.length; i++) clearTimeout(tourstop[i]);
  	allownewtour = true;
  	tourstopcount = 0;
  }
}

// showpopup
// actually a pre-popup that is blank. This is because of the know google earth plugin scrollbar issue.
// without this function, the scrollbar position will be remembered from popup to popup and each new popup
// window will not have the scrollbar at the top.
/*
function showpopup(placemarkid) {
  var balloon = ge.createHtmlDivBalloon('');
  balloon.setFeature(tourArray[placemarkid]);
  balloon.setCloseButtonEnabled(false);
  balloon.setBackgroundColor("#000000");
  
  var div = document.createElement('DIV');
  div.innerHTML = "<img src='images/spacer.gif' width='255' height='300'/>";
  
  balloon.setContentDiv(div);
  ge.setBalloon(balloon);
  setTimeout("showpopuppost(" + placemarkid + ");", 500);
}
*/
// showpopuppost
// the actual function that shows the popup with content
function showpopup(placemarkid) {
	// create the balloon object
	var balloon = ge.createHtmlDivBalloon('');
  balloon.setFeature(tourArray[placemarkid]);
  balloon.setCloseButtonEnabled(false);
  balloon.setBackgroundColor("#000000");

  // create the <div>
  var div = document.createElement('DIV');
  div.style.fontFamily = "Arial";
  div.style.fontSize = "12px";
  div.style.lineHeight = "14px";
  div.style.color = "#FFFFFF";
  div.style.background = "#000000";
  div.style.border = "0 none";
  div.style.padding = "0px 0px 10px 0px";
  div.style.margin = "5px 0px 0px 5px";
  div.style.width = "285px";
  
  // small margin adjustments for scrolling/non-scrolling windows
  switch (placemarkid) {
  	case 0:
  	case 4:
  	case 6:
  	case 8:
  	case 14:
  	case 23:
  	case 25:
  		div.style.margin = "10px 0px 0px 10px";
	  	break;
	  case 10:
	  	div.style.margin = "7px 0px 0px 7px";
	  	break;
	  default:
	  	break;
  }
  
  switch (placemarkid) {
  	case 0:		// ArcticSPAN
		  div.innerHTML = arcticspan;
		  break;
  	case 4:		// BrasilSPAN
  	  div.innerHTML = brasilspan;
		  break;
		case 6:		// CaribeSPAN
  	  div.innerHTML = caribespan;
		  break;
		case 8:		// ColombiaSPAN
  	  div.innerHTML = colombiaspan;
		  break;
		case 10:	// AfricaSPAN - West
			div.innerHTML = waspan;
			break;
  	case 14:	// GulfSPAN
		  div.innerHTML = gulfspan;
		  break;
		case 16:
		case 17:	// IndiaSPAN
  	  div.innerHTML = indiaspan;
		  break;
		case 19:	// JavaSPAN
  	  div.innerHTML = javaspan;
		  break;
		case 21:	// AfricaSPAN - East
			div.innerHTML = easpan;
			break;
		case 23:	// NEAtlanticSPAN
  	  div.innerHTML = neatlanticspan;
		  break;
		case 25:	// NovaSPAN
  	  div.innerHTML = novaspan;
		  break;
		case 101:	// Beaufort 2
  	  div.innerHTML = beaufort2;
		  break;
	  case 102:	// Beaufort 1
  	  div.innerHTML = beaufort1;
		  break;
		case 103:	// Chuckchi
  	  div.innerHTML = chuckchi;
		  break;
		case 105:	// Brasil
  	  div.innerHTML = brasil;
		  break;
		case 107:	// Caribe
  	  div.innerHTML = caribe;
		  break;
		case 109:	// Colombia
  	  div.innerHTML = colombia;
		  break;
		case 111:	// Nigeria
  	  div.innerHTML = nigeria;
		  break;
		case 112:	// Equator
  	  div.innerHTML = equator;
		  break;
		case 113:	// CongoSPAN1
  	  div.innerHTML = congo;
		  break;
		case 115:	// Gulf
  	  div.innerHTML = gulf;
		  break;
		case 118:	// India
  	  div.innerHTML = india;
		  break;
		case 120:	// Java
  	  div.innerHTML = javas;
		  break;
		case 122:	// EAfrica
  	  div.innerHTML = eafrica;
		  break;
		case 124:	// NEAtlantic
  	  div.innerHTML = neatlantic;
		  break;
		case 126:	// Nova
  	  div.innerHTML = nova;
		  break;
		default:
			div.innerHTML = '';
			break;
	}
	balloon.setContentDiv(div);
  ge.setBalloon(balloon);
}

// getPlacemarks
// iterate through the kmz file and retrieve all placemarks, set them in an array
function getPlacemarks() {
	if (currentKmlObject) {
		var placemark = currentKmlObject.getFeatures().getFirstChild();
		var pmloc = 0;
		placemark = placemark.getFeatures().getFirstChild();
		var i = 0;
		while(placemark) {
			if (placemark.getType() == "KmlPlacemark") {
				var tourpoint = placemark;
				tourArray[tourArray.length] = tourpoint;
				// assign the click event for this placemark
				switch (pmloc) {
					case 0:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(0);
					  });
						break;
					case 1:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(101);
							//window.open('sdisplay.asp?span=SPANS_ArcticSPAN_Beaufort2.jpg&w=1000&h=202','spanwindow11','width=1000,height=202,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
					  });
						break;
					case 2:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(102);
							//window.open('sdisplay.asp?span=SPANS_ArcticSPAN_Beaufort_Data_WM.jpg&w=1000&h=283','spanwindow12','width=1000,height=283,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
					  });
						break;
					case 3:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(103);
							//window.open('sdisplay.asp?span=SPANS_ArcticSPAN_Chukchi_Data_WM.jpg&w=1000&h=202','spanwindow13','width=1000,height=202,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
					  });
						break;
					case 4:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(4);
					  });
						break;
					case 5:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(105);
							//window.open('sdisplay.asp?span=SPANS_BrasilSPAN_Data_WM.jpg&w=1000&h=202','spanwindow14','width=1000,height=202,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
					  });
						break;
					case 6:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(6);
					  });
						break;
					case 7:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(107);
							//window.open('sdisplay.asp?span=SPANS_CaribeSPAN_Data_WM.jpg&w=1000&h=202','spanwindow15','width=1000,height=202,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
					  });
						break;
					case 8:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(8);
					  });
						break;
					case 9:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(109);
							//window.open('sdisplay.asp?span=SPANS_ColombiaSPAN_Data_WM.jpg&w=1000&h=202','spanwindow16','width=1000,height=202,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
					  });
						break;
					case 10:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(10);
					  });
						break;
					case 11:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(111);
							//window.open('sdisplay.asp?span=SPANS_EquatorSPAN_Data_WM.jpg&w=1000&h=288','spanwindow17','width=1000,height=288,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
					  });
						break;
					case 12:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(112);
							//window.open('sdisplay.asp?span=SPANS_CongoSPAN1_Data_WM.jpg&w=1000&h=202','spanwindow18','width=1000,height=202,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
					  });
						break;
					case 13:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(113);
							//window.open('sdisplay.asp?span=SPANS_NigeriaSPAN_Data_WM.jpg&w=1000&h=202','spanwindow19','width=1000,height=202,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
					  });
						break;
					case 14:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(14);
					  });
						break;
					case 15:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(115);
							//window.open('sdisplay.asp?span=SPANS_GulfSPAN_Data_WM.jpg&w=1000&h=202','spanwindow20','width=1000,height=202,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
					  });
						break;
					case 16:
					case 17:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(16);
					  });
						break;
					case 18:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(118);
							//window.open('sdisplay.asp?span=SPANS_IndiaSPAN_Data_WM.jpg&w=1000&h=202','spanwindow21','width=1000,height=202,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
					  });
						break;
					case 19:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(19);
					  });
						break;
					case 20:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(120);
							//window.open('sdisplay.asp?span=SPANS_JavaSPAN_Data_WM.jpg&w=1000&h=288','spanwindow22','width=1000,height=288,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
					  });
						break;
					case 21:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(21);
					  });
						break;
					case 22:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(122);
							//window.open('sdisplay.asp?span=SPANS_EastAfricaSPAN_Data.jpg&w=1000&h=202','spanwindow23','width=1000,height=202,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
					  });
						break;
					case 23:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(23);
					  });
						break;
					case 24:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(124);
							//window.open('sdisplay.asp?span=SPANS_NEAtlanticSPAN_Data_WM.jpg&w=1000&h=202','spanwindow24','width=1000,height=202,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
					  });
						break;
					case 25:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(25);
					  });
						break;
					case 26:
						google.earth.addEventListener(placemark, 'click', function(event) {
							showpopup(126);
							//window.open('sdisplay.asp?span=SPANS_NovaSPAN_Data_WM.jpg&w=1000&h=288','spanwindow25','width=1000,height=288,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
					  });
						break;
					default:
						break;
				}
				pmloc++;
			}
			placemark = placemark.getNextSibling();
		}
	}
}

// showtour
// starts the tour. this is a manual tour and not a KML tour so that we have the most control		
function showtour() {
	if ((tourArray.length > 0)&&allownewtour&&!google_type) {
		allownewtour = false;
		tourstop[tourstop.length] = setTimeout("ge.setBalloon(null); tourstopcount = 0; tourstopexpect = 1; ge.getView().setAbstractView(tourArray[14].getAbstractView())",0);
		tourstop[tourstop.length] = setTimeout("showpopup(14)",waittime*1 - popuphold);
		tourstop[tourstop.length] = setTimeout("ge.setBalloon(null); tourstopexpect = 2; ge.getView().setAbstractView(tourArray[4].getAbstractView())",waittime*1);
		tourstop[tourstop.length] = setTimeout("showpopup(4)",waittime*2 - popuphold);
		tourstop[tourstop.length] = setTimeout("ge.setBalloon(null); tourstopexpect = 3; ge.getView().setAbstractView(tourArray[10].getAbstractView())",waittime*2);
		tourstop[tourstop.length] = setTimeout("showpopup(10)",waittime*3 - popuphold);
		tourstop[tourstop.length] = setTimeout("ge.setBalloon(null); tourstopexpect = 4; ge.getView().setAbstractView(tourArray[21].getAbstractView())",waittime*3);
		tourstop[tourstop.length] = setTimeout("showpopup(21)",waittime*4 - popuphold);
		tourstop[tourstop.length] = setTimeout("ge.setBalloon(null); tourstopexpect = 5; ge.getView().setAbstractView(tourArray[16].getAbstractView())",waittime*4);
		tourstop[tourstop.length] = setTimeout("showpopup(16)",waittime*5 - popuphold);
		tourstop[tourstop.length] = setTimeout("ge.setBalloon(null); tourstopexpect = 6; ge.getView().setAbstractView(tourArray[0].getAbstractView()); allownewtour = true; setTimeout('showtour();', waittime);",waittime*5);
		tourstop[tourstop.length] = setTimeout("showpopup(0)",waittime*6 - popuphold);
	}
}

// prepMove
// common code for each of the show functions
function prepMove() {
	stoptour(true);
	tourstopcount = 0; tourstopexpect = 1;
	ge.setBalloon(null);
}

// show functions for each area. these could actually be consolidated into 1 function
// but it's easier to read and understand this way. additionally, it would be easier to
// change given any changes in the KMZ file.
function showEastAfrica() {
	if (!google_type) {
		prepMove();
		ge.getView().setAbstractView(tourArray[21].getAbstractView());
		manualpopup = setTimeout("showpopup(21);", waittime - popuphold);
	} else {
		map.panTo(new GLatLng(-11.598456,44.800155), 4);
		map.setZoom(4);
	}
}

function showWestAfrica() {
	if (!google_type) {
		prepMove();
		ge.getView().setAbstractView(tourArray[10].getAbstractView());
		manualpopup = setTimeout("showpopup(10);", waittime - popuphold);
	} else {
		map.panTo(new GLatLng(-3.825464,14.512514), 4);
		map.setZoom(4);
	}
}
    
function showArctic() {
	if (!google_type) {
		prepMove();
		ge.getView().setAbstractView(tourArray[0].getAbstractView());
		manualpopup = setTimeout("showpopup(0);", waittime - popuphold);
	} else {
		map.panTo(new GLatLng(71.979827,-146.769346), 4);
		map.setZoom(4);
	}
}

function showBrasil() {
	if (!google_type) {
		prepMove();
		ge.getView().setAbstractView(tourArray[4].getAbstractView());
		manualpopup = setTimeout("showpopup(4);", waittime - popuphold);
	} else {
		map.panTo(new GLatLng(-25.095807,-38.260986), 5);
		map.setZoom(5);
	}
}

function showCaribe() {
	if (!google_type) {
		prepMove();
		ge.getView().setAbstractView(tourArray[6].getAbstractView());
		manualpopup = setTimeout("showpopup(6);", waittime - popuphold);
	} else {
		map.panTo(new GLatLng(11.270952,-60.209021), 7);
		map.setZoom(7);
	}
}

function showColombia() {
	if (!google_type) {
		prepMove();
		ge.getView().setAbstractView(tourArray[8].getAbstractView());
		manualpopup = setTimeout("showpopup(8);", waittime - popuphold);
	} else {
		map.panTo(new GLatLng(11.359996,-74.048793), 6);
		map.setZoom(6);
	}
}

function showGulf() {
	if (!google_type) {
		prepMove();
		ge.getView().setAbstractView(tourArray[14].getAbstractView());
		manualpopup = setTimeout("showpopup(14);", waittime - popuphold);
	} else {
		map.panTo(new GLatLng(29.337166,-93.106176), 5);
		map.setZoom(5);
	}
}

function showIndia() {
	if (!google_type) {
		prepMove();
		ge.getView().setAbstractView(tourArray[16].getAbstractView());
		manualpopup = setTimeout("showpopup(16);", waittime - popuphold);
	} else {
		map.panTo(new GLatLng(15.030326,77.421622), 5);
		map.setZoom(5);
	}
}

function showJava() {
	if (!google_type) {
		prepMove();
		ge.getView().setAbstractView(tourArray[19].getAbstractView());
		manualpopup = setTimeout("showpopup(19);", waittime - popuphold);
	} else {
		map.panTo(new GLatLng(-4.655952,119.091950), 5);
		map.setZoom(5);
	}
}

function showNEAtlantic() {
	if (!google_type) {
		prepMove();
		ge.getView().setAbstractView(tourArray[23].getAbstractView());
		manualpopup = setTimeout("showpopup(23);", waittime - popuphold);
	} else {
		map.panTo(new GLatLng(59.006286,-2.143515), 4);
		map.setZoom(4);
	}
}

function showNova() {
	if (!google_type) {
		prepMove();
		ge.getView().setAbstractView(tourArray[25].getAbstractView());
		manualpopup = setTimeout("showpopup(25);", waittime - popuphold);
	} else {
		map.panTo(new GLatLng(42.962838,-61.046068), 6);
		map.setZoom(6);
		//alert(tourArray[25].getAbstractView().getLatitude());
	}
}

function googleToggle() {
	stoptour();
	if (GBrowserIsCompatible()) {
		if (google_type != 1) {
			document.getElementById("togglelink").innerText = 'GOOGLE EARTH VERSION';
			var geoXml = new GGeoXml("http://www.iongeo.com/content/includes/globes/BasinSpans.kmz");
	    map = new GMap2(document.getElementById("content"));
	    //var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
		  //alert(la.getLatitude());
		  //alert(la.getLongitude());
	    map.setCenter(new GLatLng(29.337166,-93.106176), 5); 
	    map.addControl(new GLargeMapControl());
	    //map.addControl(new GLargeMapControl());
	    map.addControl(new GMapTypeControl());
	    map.addOverlay(geoXml);
	    google_type = 1;
	  } else {
	  	location.href = "data_library.asp";
	  	/*
	  	document.getElementById("togglelink").innerText = 'GOOGLE MAP VERSION';
	  	init();
	  	*/
	  }
	}
	else alert("browser not compatible");
}
