var map = null;
var geocoder = null;
var INIT_LAT;
var INIT_LNG;


// load/unload JS for GMap (instead of using body tag)
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

addLoadEvent(load);

// arrange for our onunload handler to 'listen' for onunload events
if (window.attachEvent) {
	window.attachEvent("onunload", function() {
		GUnload();			// Internet Explorer
	});
} else {
	window.addEventListener("unload", function() {
		GUnload(); // Firefox and standard browsers
	}, false);
}

function load() {
	if(GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		map.setMapType(G_PHYSICAL_MAP);
		//map.disableDragging();  current disables all click events so icons can be interacted with
		geocoder = new GClientGeocoder();

		// set default map center to user's current location
		if(!INIT_LAT && !INIT_LNG) {
			INIT_LAT = parseFloat($("#init_lat").text());
			INIT_LNG = parseFloat($("#init_lng").text());
		}

		// if default map center location isn't specified, use google's geolocator.
		if(google.loader.ClientLocation && (!INIT_LAT || !INIT_LNG)) {
			INIT_LAT = google.loader.ClientLocation.latitude;
			INIT_LNG = google.loader.ClientLocation.longitude;
		}

		// if google couldn't find the user, centre to London.
		if(!INIT_LAT)
			INIT_LAT = 51.5;
		if(!INIT_LNG)
			INIT_LNG = 20;

		map.setCenter(new GLatLng(INIT_LAT, INIT_LNG), 7);
		map.enableDoubleClickZoom();
		
		//var mapControl = new GMapTypeControl();
		//map.addControl(mapControl);
		//map.removeMapType(G_NORMAL_MAP);
		//map.removeMapType(G_HYBRID_MAP);
		//map.addMapType(G_PHYSICAL_MAP);
		//map.addControl(new GLargeMapControl());

           //     control = new GSmallZoomControl();
	   
// 	control.initialize(map);



		var customUI = map.getDefaultUI();
		customUI.controls.scalecontrol = false;
		map.setUI(customUI);
		map.removeMapType(G_NORMAL_MAP);
	  map.removeMapType(G_HYBRID_MAP);
	  map.disableScrollWheelZoom();



		if(typeof(MAP_INIT_FUNCS) != 'undefined') {
			for(var i=0; i<MAP_INIT_FUNCS.length; i++) {
				if(typeof(MAP_INIT_FUNCS[i]) == 'function') {
					GEvent.bind(map, "load", this, MAP_INIT_FUNCS[i]());
				}
			}
		}

		if(map.getZoom() < 1) {
			map.setZoom(1);
		}

		if(map.getZoom() > 6) {
			map.setZoom(6);
		}
		
if(typeof(INT_MIN_ZOOM) != 'undefined') {
			if(map.getZoom() > INT_MIN_ZOOM) {
				map.setZoom(INT_MIN_ZOOM);
			}
		}

		map.initialize;
		
	}
}

