var TMM = {
	/* CONFIG:  add the Google Map key, URL of the KML file, map width, and map height here:  */
	gmap_key:'ABQIAAAAxjJDlC-Q3A8b7WIxl6KwshRVGC_2Md9L1Gi1w2yV5jU87t8pARR3ZjpnKvIrgujopw-l1JaBEzG88w',
kml_file:'http://maps.google.com/maps/ms?ie=UTF8&hl=en&msa=0&output=nl&msid=107444494116951053799.00043e81c596a6346fbb5',
	map_width:675,
	map_height:675,		
	/* That's it!  */
	map:null,
	kml:null,
	container:null,
	alrdyLoaded:false,
	markers:null,
	loadchecker:false,
	list:null,
	loadstatus:0,
	catchHandle:null,		
	setup:function() {
		if(!document.getElementById('TMMscript')) { return false; }
		TMM.markers = [];
		var h = document.getElementsByTagName('head')[0];
		var s = document.createElement('script');
		s.setAttribute('type','text/javascript');
		s.id = 'TMM_gscript';
		h.insertBefore(s,h.firstChild);
		s.setAttribute('src','http://www.google.com/jsapi?async=2&callback=TMM.go&key='+TMM.gmap_key);
		var sc = document.getElementById('TMMscript');
		var sp = sc.parentNode;
		if(!document.getElementById('TMM_map')) {
			var m = document.createElement('div');
			m.setAttribute('id','TMM_map');
		} else {
			m = document.getElementById('TMM_map');
		}	
		m.style.width = TMM.map_width+'px';
		m.style.height = TMM.map_height+'px';
		if(!document.getElementById('TMM_container')) {
			TMM.container = document.createElement('div');
			TMM.container.setAttribute('id','TMM_container');
		} else {
			TMM.container = document.getElementById('TMM_container');
		}
		TMM.container.style.width = TMM.map_width+'px';
		TMM.container.appendChild(m);
		TMM.lst = document.createElement('ul');
		TMM.lst.setAttribute('id','TMM_selectlist');
		TMM.lst.style.height = Math.ceil(TMM.map_height/3)+'px';
		TMM.lst.style.overflow = 'auto';
		TMM.container.appendChild(TMM.lst);
		sp.insertBefore(TMM.container,sc.nextSibling);	
	},
	go:function() {
		if(typeof google == 'undefined') {
			TMM.loadchecker = setTimeout(TMM.go,10);
		} else {
			TMM.loadchecker = false;
			google.load("maps", "2.132e", {"callback":TMM.mapsLoaded});
		}
	},
	mapsLoaded:function() {
	  if (google.maps.BrowserIsCompatible() && document.getElementById("TMM_map")) {
		TMM.map = new google.maps.Map2(document.getElementById("TMM_map"));
		TMM.map.addControl(new google.maps.LargeMapControl());
		TMM.map.addControl(new google.maps.MapTypeControl());
		TMM.map.enableContinuousZoom();
		TMM.kml = new google.maps.GeoXml(TMM.kml_file);
		google.maps.Event.addListener(TMM.kml,'load',TMM.kmlLoaded);
		TMM.catchHandle = google.maps.Event.addListener(TMM.map,'addoverlay',TMM.catchOverlay);
	  }
	},
	catchOverlay:function(overlay) {
		if(overlay.name && !overlay.Known) {
			// Save a reference
			TMM.markers.push(overlay);
			// remember that we know about this one
			overlay.Known = true;
		}
	},
	kmlLoaded:function() {
		if(TMM.loadstatus == 0) {
			if(TMM.kml.hasLoaded()) {
				if(!TMM.alrdyLoaded) {
					TMM.kml.gotoDefaultViewport(TMM.map);
					TMM.map.addOverlay(TMM.kml);
					TMM.alrdyLoaded = true;
				}
			}
		} else if(TMM.loadstatus == 1) {
			google.maps.Event.removeListener(TMM.catchHandle);
			TMM.addList();
		}
		TMM.loadstatus++;
	},
	alphabetize:function(a,b) {
		if(a.name < b.name) {
			return -1;
		} else if (a.name > b.name) {
			return 1;
		} else {
			return 0;
        }
	},
	addList:function() {
		TMM.markers.sort(TMM.alphabetize);
		var a,li;
		for(var i=0;i<TMM.markers.length;i++) {
			a = document.createElement('a');
			a.setAttribute('style','cursor:pointer;');
			a.appendChild(document.createTextNode(TMM.markers[i].name));
			a.onclick = TMM.show;
			a.style.lineHeight = '40px';
			li = document.createElement('li');
			li.style.background = "url("+TMM.markers[i].U[0].__src__+") no-repeat left center";
			li.style.paddingLeft = '32px';
			li.style.margin = '0.5em 0';
			li.style.listStyle = 'none';		
			li.appendChild(a);
			TMM.lst.appendChild(li);
		}
	},
	show:function() {
		var idx = false;
		var as = TMM.lst.getElementsByTagName('a');
		for(var i=0;i<as.length;i++) {
			if(as[i] == this) {
				break;
			}
		}
		TMM.map.setZoom(15);
		TMM.map.panTo(new google.maps.LatLng(TMM.markers[i].X.lat,TMM.markers[i].X.lng)); // Thx. to Andrew Leach
		google.maps.Event.trigger(TMM.markers[i],'click');
	},
	addLoadEvent:function(func) {
		var oldonload = window.onload;
		if(typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				oldonload();
				func();
			};
		}
	}
};
TMM.addLoadEvent(TMM.setup);