// Google maps functions //

var map;
var baseIcon;

function mapSetup(size) {
	// Runs new map and adds controls
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		//alert("map:"+map);
		if(size == 'large') {
			// add movement and zoom controls
			map.addControl(new GLargeMapControl3D());
			// add map type switching
			map.addControl(new GMapTypeControl());
			// add map overview switching
			map.addControl(new GOverviewMapControl());
		} else {
			// add movement and zoom controls
			map.addControl(new GSmallMapControl());
		}
		// coordinate listener
		//GEvent.addListener(map, "moveend", function() {
			//get centre of the map
			//var center = map.getCenter();
			// gets individual coordinates
			//var mapLat = center.lat();
			//var mapLng = center.lng();
		//});
		// Create a base icon for all of our markers that specifies the shadow, icon dimensions, etc.
		zephyrIcon = new GIcon();
		zephyrIcon.image = "/images/zephyr_marker.png";
		zephyrIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
		zephyrIcon.iconSize = new GSize(20, 34);
		zephyrIcon.shadowSize = new GSize(37, 34);
		zephyrIcon.iconAnchor = new GPoint(9, 34);
		zephyrIcon.infoWindowAnchor = new GPoint(9, 2);
		zephyrIcon.infoShadowAnchor = new GPoint(18, 25);
		
		baseIcon = new GIcon();
		baseIcon.image = "/images/airfield_marker.png";
		baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
		baseIcon.iconSize = new GSize(20, 34);
		baseIcon.shadowSize = new GSize(37, 34);
		baseIcon.iconAnchor = new GPoint(9, 34);
		baseIcon.infoWindowAnchor = new GPoint(9, 2);
		baseIcon.infoShadowAnchor = new GPoint(18, 25);
	}
}

// sets center point and zoom depth
function CenterMap(mapLat,mapLong,mapZoom) {
	map.setCenter(new GLatLng(mapLat, mapLong), mapZoom, G_HYBRID_MAP);
}

// move map to new coordinates
function MapMove(newMapLat,newMapLng) {
	// pan from one element to another
	window.setTimeout(function() {
	map.panTo(new GLatLng(newMapLat, newMapLng));
	// delay
	}, 0);

}

function CreateMarker(newMarkerLat,newMarkerLong,newMarkerHtml,type,size) {
	// Creates a marker at the given point with the given html
	if(type == "Z") {
		var icon = new GIcon(zephyrIcon);
	} else {
		var icon = new GIcon(baseIcon);
	}
	var point = new GLatLng(newMarkerLat,newMarkerLong);
	var marker = new GMarker(point, icon);
	var placeLink = "";
	if(size == 'large') {
		var placeLink = '<br/><a href="#" onclick="CenterMap('+newMarkerLat+','+newMarkerLong+',14); return false">View this Airfield</a>';
	}
	GEvent.addListener(marker, "click", function() {									 
	marker.openInfoWindowHtml(newMarkerHtml+placeLink);
	});
	map.addOverlay(marker);
}

function getMapCentre() {
	var center = map.getCenter();
	// gets individual coordinates			
	alert(center.lat()+","+center.lng());
}