var map; // GMap2
var mapFlag; // GMarker

var city = new Array();
var people = new Array();

var homeLatitude = 46.8;
var homeLongitude = -119.9;
var homeZoom = 6;

var iconLibrary = new Array();
iconLibrary[0] = makeIcon("marker");
for (i=1; i<=9; i++) {
	iconLibrary[i] = makeIcon(i);
}

iconLibrary["highlight"] = new GIcon();
iconLibrary["highlight"].image				= "markers/highlight/marker.png";
iconLibrary["highlight"].shadow				= "markers/highlight/shadow.png";
iconLibrary["highlight"].printShadow		= "markers/highlight/shadowie.gif";
iconLibrary["highlight"].mozPrintShadow		= "markers/highlight/shadowff.gif";
iconLibrary["highlight"].iconSize 	= new GSize(20, 34);
iconLibrary["highlight"].shadowSize	= new GSize(37, 34);
iconLibrary["highlight"].iconAnchor	= new GPoint(10, 34);
	
function makeIcon(i) {
	var xIcon = new GIcon();
	xIcon.image				= "markers/flag/"+i+".png";
	xIcon.printImage 		= "markers/flag/markerie.gif";
	xIcon.mozPrintImage		= "markers/flag/markerff.gif";
	xIcon.shadow			= "markers/flag/shadow.png";
	xIcon.printShadow		= "markers/flag/shadowie.gif";
	xIcon.mozPrintShadow	= "markers/flag/shadowff.gif";
	xIcon.iconSize = new GSize(20, 34);
	xIcon.shadowSize = new GSize(37, 34);
	xIcon.iconAnchor = new GPoint(10, 34);
	return xIcon;
}

function initialize() {
	map = new GMap2(document.getElementById("map"));
	map.setCenter(new GLatLng(homeLatitude, homeLongitude), homeZoom);
	map.addControl(new GSmallMapControl()); // Or "GLargeMapControl()
	
	for (i in people) {
		var marker = new GMarker(new GLatLng(people[i][11], people[i][12]), {icon: iconLibrary[i]});
		marker.i = i;
		map.addOverlay(marker);
		GEvent.addListener(map, "click", function(marker, point) {
			if (marker && !isNaN(marker.i)) {
				view(marker.i);
			}
		});
	}

		// ====== Restricting the range of Zoom Levels =====
		// http://econym.googlepages.com/range.htm (2007-01-25)
		// Get the list of map types      
		var mt = map.getMapTypes();
		// Overwrite the getMinimumResolution() and getMaximumResolution() methods
		for (var i=0; i<mt.length; i++) {
			mt[i].getMinimumResolution = function() {return 6;}
			mt[i].getMaximumResolution = function() {return 8;}
		}

}

function view(i) {
	update_text("name",     people[i][1]);
	update_text("position", people[i][2]);
	update_text("hometown", people[i][3]+"<br/>");
	update_text("height",   people[i][4]+", ");
	update_text("weight",   people[i][5]);
	update_text("school",   people[i][6]);
	update_text("college",  "Committed to:<br/>"+people[i][7]);
	update_text("bio",      people[i][8]);
	
	update_photo("person",  people[i][9]);
	//update_photo("college", people[i][10]);
	
	update_map(people[i][11], people[i][12]);
}

function update_text(name, value) {
	document.getElementById("nwn_"+name).innerHTML = value;
}

function update_photo(type, file) {
	var photo = 'images/'+type+'/' + ((file) ? file : '_.jpg');
	document["nwn_photo_"+type].src = photo
}

function update_map(lat, lng) {
	if (mapFlag) {
		map.removeOverlay(mapFlag);
	} else {
		mapFlag = new GMarker(new GLatLng(homeLatitude, homeLongitude), {icon: iconLibrary["highlight"]});
	}
	mapFlag.setLatLng(new GLatLng(lat, lng));
	map.addOverlay(mapFlag);
}