google.load("maps", "2");

function initialize() {
	
  if (google.maps) {
	
	//fetch the "my map" that is editable under the CDINT account
	var cdi_my_map_url = "http://maps.google.com/maps/ms?ie=UTF8&hl=en&vps=1&jsv=202c&oe=UTF8&msa=0&msid=103648302023930707793.00047927bedf1f70ec235&output=kml";
	
	var cdi_map = new google.maps.Map2(document.getElementById("map"), {backgroundColor: "#9cb4cb"});
	var cdi_map_center = new google.maps.LatLng(30, 0);
	cdi_map.setCenter(cdi_map_center, 1);
	cdi_map.addControl(new GSmallZoomControl());
	cdi_map.disableDoubleClickZoom();
	
	//load the "my map" pins with Google's geoxml function
	var cdi_my_map = new google.maps.GeoXml(cdi_my_map_url);
	cdi_map.addOverlay(cdi_my_map);
	
	//create a listener to catch clicks and act on them
	var cdi_set_center = function(map_center) {
		cdi_map.setCenter(map_center);
	}
	google.maps.Event.addListener(cdi_map, "infowindowclose", function() {
		cdi_set_center(cdi_map_new_center);
  	});
	
	//add function on infowindowopen that scrubs anchors so they open in the same window
	google.maps.Event.addListener(cdi_map, "infowindowopen", function() {
		cdi_map_new_center = cdi_map.getCenter(); //get new center for return when closing
		var cdi_infowindow = document.getElementById('iw_kml').childNodes[0].childNodes;
		var cdi_i = cdi_infowindow.length;
		
		for (var i = 0; i < cdi_i; i++) {
			if (cdi_infowindow[i].nodeName == "A") {
				cdi_infowindow[i].setAttribute('target', '_self');
			}
		}
		
  	});
	
  }
}

function cdi_unload() {
	if (google.maps) {
		google.maps.Unload();
	}
}
