var load_gmaps = function() {
    load();
}

var unload_gmaps = function() {
    GUnload();
}

function load() {
    resize();
    if (GBrowserIsCompatible()) {
	var the_div = document.getElementById("map");
	var map = new GMap2(the_div);
	var point = new GLatLng(GMAP_latitude, GMAP_longitude);
	map.addControl(new GSmallMapControl());
	map.enableScrollWheelZoom();
	if (GMAP_allow_sat) {
	    map.addControl(new GMapTypeControl());
	}
	if (typeof GMAP_zoom_level != "undefined") {
		map.setCenter(point, GMAP_zoom_level);
	} else {
		map.setCenter(point, 16);
	}
      	if (typeof GMAP_icon != "undefined") {
		if (GMAP_icon != "") {
			var tinyIcon = new GIcon();
			tinyIcon.image = GMAP_icon;
       	 		if (typeof GMAP_icon_shadow != "undefined") {
				tinyIcon.shadow = GMAP_icon_shadow;
			}
        		if (typeof GMAP_icon_width != "undefined" && typeof GMAP_icon_height != "undefined") {
				tinyIcon.iconSize = new GSize(GMAP_icon_width, GMAP_icon_height);
	        		if (typeof GMAP_icon_shadow != "undefined") {
					tinyIcon.shadowSize = new GSize(GMAP_icon_width, GMAP_icon_height);
				}
			}
        		if (typeof GMAP_anchor_X != "undefined" && typeof GMAP_anchor_Y != "undefined") {
				tinyIcon.iconAnchor = new GPoint(GMAP_anchor_X, GMAP_anchor_Y);
				tinyIcon.infoWindowAnchor = new GPoint(GMAP_anchor_X, GMAP_anchor_Y);
			}
			var marker = new GMarker(point, {icon:tinyIcon});
		} else {
			var marker = new GMarker(point);
		}
		map.addOverlay(marker);
		if (typeof GMAP_html != "undefined") {
			GEvent.addListener(marker, "click", function() {
	    			marker.openInfoWindowHtml(GMAP_html);
			});
			marker.openInfoWindowHtml(GMAP_html);
		}
        } else if (typeof GMAP_html != "undefined") {
		map.openInfoWindow(map.getCenter(), GMAP_html);
	}
    }
}

function resize() {
    resize_all();
    var the_div = document.getElementById("map");
    if ($is_ie_bug) {
	bsize=30;
    } else {
	bsize=20;
    }
    the_div.style.height=findPageHeight()*0.7-bsize+'px';
}

if (window.addEventListener) {
    window.addEventListener("load", load_gmaps, false);
    window.addEventListener("unload", unload_gmaps, false);
} else if (document.body.onload) {
    document.body.onload = load_gmaps;
    document.body.onunload = unload_gmaps;
}

