/* Some code to access the MyTopo APIs and to integrate the results using the Google Maps API.
 *
 * I started with some code I grabbed from the MyTopo JavaScript
 * (which unfortunately assumes the Google Maps API is already loaded):
 *
 * http://www.mytopo.com/google/mytopo.js
 *
 * I modified this code so that I could delay the Google Maps APIs calls until I had them loaded
 * (i.e., I call initialize_mytopo() after the user has twisted down my "show map" control),
 * started using the Google AJAX API version of the Google Maps APIs (namespace issues),
 * and then did a little clean up.
 *
 * - Chris Schneider
 * 
 * NOTE: Before calling any of these APIs, you must load (the Google AJAX API version of)
 *       the Google Maps API. For example, you could include the following lines before you
 *		 call any of the functions defined in this module:
 *
<script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAAHW4RRw8BBUGT6NNtXGmEKhQyPLe213Nw7d1A1WBsM4L9pZSMDRSn1zySnx7pdSMsNA0fqU4Lnffdmw"></script>
<script type="text/javascript" src="terraserver_gmaps.js"></script>
<script type="text/javascript">

	google.load("maps", "2", {"other_params":"sensor=false"});
	
	function initialize_google_maps() {
		if (!google.maps.BrowserIsCompatible()) {
			alert("Unfortunately, your browser is incompatible with Google Maps, so we're outta here!");
			window.close();
		}

	google.setOnLoadCallback(initialize_google_maps);
</script>	
 */

get_mytopo_tile=function(a, b, c) {
	var lURL = this.myBaseURL;
	lURL += b;
	lURL += "/"+a.x;
	lURL += "/"+a.y+".png";
	return lURL;
}

var MYTOPO_MAP = null;
function initialize_mytopo() {
	var mytopo_copyright
		= new google.maps.Copyright(1,
						 new google.maps.LatLngBounds(	new google.maps.LatLng(-90, -180),
														new google.maps.LatLng(90, 180)),
						 0,
						 '&#169; MyTopo <a href="http://www.mytopo.com/google/index.cfm" target="_blank"><b>(Topo Maps Terms of Use)</b></a>');
	var mytopo_copyright_collection = new google.maps.CopyrightCollection('');
	mytopo_copyright_collection.addCopyright(mytopo_copyright);
			
	var mytopo_tile_layer = new google.maps.TileLayer(mytopo_copyright_collection, 9, 15);
	mytopo_tile_layer.myLayers='topoG';
	mytopo_tile_layer.myFormat='image/png';
	mytopo_tile_layer.myBaseURL='http://maps.mytopo.com/mytopo/tilecache.py/1.0.0/topoG/';
	mytopo_tile_layer.getTileUrl=get_mytopo_tile;
			
	var mytopo_tile_layers=[mytopo_tile_layer];
	MYTOPO_MAP = new google.maps.MapType(mytopo_tile_layers,
										 google.maps.SATELLITE_MAP.getProjection(),
										 "MyTopo",
										 google.maps.PHYSICAL_MAP);
}

/* Strangely, the following code (copied directly from http://www.mytopo.com/google/mytopo.js)
 * isn't used in this file, nor are there suggestions to call initMytopo from client JavaScript.
 * The mytopo.js file also contains a commented-out line: tileMytopo.myBaseURL=mytopoUrl;
 */
var mytopoUrl;
function initMytopo(pid) {
	mytopoUrl = 'http://maps2.mytopo.com/mytopo/1.0.0/topoG/';
}
