var centerLatitude = 17;
var centerLongitude = -15;
var startZoom = 2;

var map;



function region(regionLatitude, regionLongitude, regionZoom) {
	map.setCenter(new GLatLng(regionLatitude, regionLongitude), regionZoom);
}

        

function addMarker(latitude, longitude, type, description, links) {

	if(type==0) {
		var icon = new GIcon();
		icon.image = '_images/_icons/people_icon.png';
		icon.shadow = "_images/_icons/shadow.png";
		icon.iconSize = new GSize(32, 32);
		icon.iconAnchor = new GPoint(16, 32);
		icon.infoWindowAnchor = new GPoint(16, 16);	}

	if(type==1) {
		var icon = new GIcon();
		icon.image = '_images/_icons/places_icon.png';
		icon.shadow = "_images/_icons/shadow.png";
		icon.iconSize = new GSize(32, 32);
		icon.iconAnchor = new GPoint(16, 32);
		icon.infoWindowAnchor = new GPoint(16, 16);
	}
	
	if(type==2) {
		var icon = new GIcon();
		icon.image = '_images/_icons/atrisk_icon.png';
		icon.shadow = "_images/_icons/shadow.png";
		icon.iconSize = new GSize(32, 32);
		icon.iconAnchor = new GPoint(16, 32);
		icon.infoWindowAnchor = new GPoint(16, 16);
	}
	
	if(type==3) {
		var icon = new GIcon();
		icon.image = '_images/_icons/protected_icon.png';
		icon.shadow = "_images/_icons/shadow.png";
		icon.iconSize = new GSize(32, 32);
		icon.iconAnchor = new GPoint(16, 32);
		icon.infoWindowAnchor = new GPoint(16, 16);
	}
	
	if(type==4) {
		var icon = new GIcon();
		icon.image = '_images/_icons/atrisk_icon.png';
		icon.shadow = "_images/_icons/shadow.png";
		icon.iconSize = new GSize(32, 32);
		icon.iconAnchor = new GPoint(16, 32);
		icon.infoWindowAnchor = new GPoint(16, 16);
	}
	
	if(type==5) {
		var icon = new GIcon();
		icon.image = '_images/_icons/fieldwork_icon.png';
		icon.shadow = "_images/_icons/shadow.png";
		icon.iconSize = new GSize(32, 32);
		icon.iconAnchor = new GPoint(16, 32);
		icon.infoWindowAnchor = new GPoint(16, 16);
	}
	
	var opts = {maxHeight:260}; 
	
	var marker = new GMarker(new GLatLng(latitude, longitude), icon);	
	GEvent.addListener(marker, 'click',
		function() {
			marker.openInfoWindowHtml(description, opts);
		}
	);
	
	map.addOverlay(marker);
}



function init() {
	if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        map.enableDoubleClickZoom();
        map.addControl(new GSmallMapControl());
		map.addControl(new GHierarchicalMapTypeControl());
        map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);
        map.setMapType(G_SATELLITE_MAP);
        
        for(id in markers) {
        	addMarker(markers[id].latitude, markers[id].longitude, markers[id].type, markers[id].description, markers[id].links);
        }
	}
}




window.onload = init;
window.onunload = GUnload;