      function resizeHeight() {
            var map = document.getElementById("map");
            var mapframe = document.getElementById("mapframe");
	    if( typeof( window.innerWidth ) != 'undefined' ) {
	    	winHeight = window.innerHeight;
	    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		winHeight = document.documentElement.clientHeight;
	    } else if( document.body && ( document.body.clientHeight ) ) {
		winHeight = document.body.clientHeight;
	    }
 
	    winHeight = winHeight -100;
            if( winHeight < 400 ) { winHeight = 400; }

	    if( mapframe.clientHeight != winHeight ) {
            	map.style.height = winHeight - 21;
           	mapframe.style.height = winHeight;
	    }
      }

    window.onresize = resizeHeight;

    function select_favorite(v) {
	var fav = v.value;
	document.location.href = "http://www.globalwarmingart.com/sealevel" + fav;	
    }

    function toggleControl() {
    }

    toggleControl.prototype = new GControl();

    toggleControl.prototype.initialize = function(map) {
      var container = document.createElement("div");
      var toggle = document.createElement("div");

      this.setButtonStyle_(toggle);
      container.appendChild(toggle);

      textnode = document.createTextNode("Hide Elevation");
      toggle.appendChild(textnode);
      GEvent.addDomListener(toggle, "click", function() {
	if( textnode.nodeValue == "Hide Elevation" ) {
		textnode.nodeValue = "Show Elevation";
		map.removeOverlay(overlay);
		toggle.style.border = "2px gray inset";
	} else {
		textnode.nodeValue = "Hide Elevation";
		map.addOverlay(overlay);
		toggle.style.border = "2px gray outset";
		toggle.style.borderTop = "1px black solid";
		toggle.style.borderLeft = "1px black solid";
	}
      });

      map.getContainer().appendChild(container);
      return container;
    }

    toggleControl.prototype.getDefaultPosition = function() {
      return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(80,7));
    }

    toggleControl.prototype.setButtonStyle_ = function(button) {
	button.style.backgroundColor = "#fffff0";
	button.style.font = "small Arial";
	button.style.border = "2px outset gray";
	button.style.borderTop = "1px black solid";
	button.style.borderLeft = "1px black solid";
	button.style.padding = "2px";
	button.style.textAlign = "center";
	button.style.cursor = "pointer";
	button.style.width = "9em";
    }

	var copyCollection = new GCopyrightCollection('globalwarmingart.com');
	var copyright = new GCopyright(100,
		new GLatLngBounds(new GLatLng(-90,-180),
					new GLatLng(90,180)),
		0,
		"&copy;2008 - Global Warming Art");
	copyCollection.addCopyright(copyright);

	var SeaLevelTile = new GTileLayer(copyCollection,0,17);

	SeaLevelTile.isPng = function() { return true; }
	SeaLevelTile.getOpacity = function() { return 1.0; }

	SeaLevelTile.getTileUrl = function(tile,zoom) {
	    if( zoom <= 10 ) {
		return 'http://www.globalwarmingart.com/tiles/' + zoom + '/' + tile.y + '/' +tile.x +'.png';
	    } else if( zoom <= 17 ) {
		return 'http://www.globalwarmingart.com/tiles/EE/' + zoom + '/' + tile.y + '/' +tile.x +'.png';
	    } else {
                return 'http://www.globalwarmingart.com/tiles/zoomtile.png';
	    }		
	}
 
    var overlay;
    var overlaystate = 1;

    function mapLoad() {
	    function updateLink() {
		var link = document.getElementById("sealevellink");
		var loc = map.getCenter();
		var z = map.getZoom();

		var s = "http://www.globalwarmingart.com/sealevel?lat=" + Math.round(loc.y*1000)/1000 + "&lng=" + Math.round(loc.x*1000)/1000;
		if (z != 4) {
			s = s + "&zoom=" + z;
		}
		
		var mode = 0;
		var mt = map.getCurrentMapType().getName();
		switch(mt) {
		case "Map":
			mode = 1;
			break;
		case "Satellite":
			mode = 3;
			break;
		case "Hybrid":
			mode = 2;
			break;
		}

		if (mode != 0) {
			s = s + "&mode=" + mode;
		}

		link.innerHTML = s;
		link.href = s;
    	    }

	    function mapTypeChange() {
		var mt = map.getCurrentMapType().getName();
		var notice = document.getElementById("datanotice");
		var scale = document.getElementById("scalelabel");
		switch(mt) {
		case "Satellite":
		case "Hybrid":
			notice.style.color = "#ffffff";
			scale.style.color = "#ffffff";
			break;
		default:
			notice.style.color = "#000000";
			scale.style.color = "#000000";
			break;
		}
    	    }

      if (GBrowserIsCompatible()) {
	var qs = new Querystring();
        var lat = qs.get("lat",37);
	var long = qs.get("lng",-95);
	var zoom = parseInt(qs.get("zoom",4));
	var mode = parseInt(qs.get("mode",0));

	resizeHeight();

	var maptype = G_PHYSICAL_MAP;
	switch(mode) {
	case 1: 
		maptype = G_NORMAL_MAP;
		break;
	case 2:
		maptype = G_HYBRID_MAP;
		break;
	case 3: 
		maptype = G_SATELLITE_MAP;
		break;
	}

        var map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(lat, long), zoom);
	map.addControl(new GLargeMapControl());
	map.addControl(new GScaleControl());
	map.addControl(new GMapTypeControl());
	map.addControl(new GOverviewMapControl());
	map.addMapType(G_PHYSICAL_MAP);
	map.setMapType(maptype);

	GEvent.addListener(map, "moveend",updateLink);
	GEvent.addListener(map, "maptypechanged",mapTypeChange);

	overlay = new GTileLayerOverlay(SeaLevelTile);
	map.addOverlay( overlay );
        map.addControl(new toggleControl() );

	mapTypeChange();
      }
    }


