$(document).ready(function() {
	//Map Generation
	var map;
	map = new GMap2(document.getElementById("killmap"));
	map.setCenter(new GLatLng(40.798185,-77.865193), 16);
	map.addControl(new GLargeMapControl3D());
	map.setMapType(G_NORMAL_MAP);
	
	//hide japan
	/*
	var polygon = new GPolygon([
		new GLatLng(45.64579227216771,140.789794921875),
		new GLatLng(45.67650566841965,142.723388671875),
		new GLatLng(44.293449573635804,145.689697265625),
		new GLatLng(43.85143084797379,145.250244140625),
		new GLatLng(43.39014642366325,145.535888671875),
		new GLatLng(44.07285288651121,146.942138671875),
		new GLatLng(41.015276341047304,143.06396484375),
		new GLatLng(35.32214714467105,146.8212890625),
		new GLatLng(31.954647977724136,140.03173828125),
		new GLatLng(24.92895148636826,127.81494140625),
		new GLatLng(26.591146932464717,125.26611328125),
		new GLatLng(31.46865251660494,128.86962890625),
		new GLatLng(32.95582641461018,127.68310546875),
		new GLatLng(35.355605484097914,131.72607421875),
		new GLatLng(37.09257670405391,131.68212890625),
		new GLatLng(45.46218546778625,138.88916015625)
	], "#99b3cc", 0, 1, "#99b3cc", 1);
	// map.addOverlay(polygon); */
	var polygon = new GPolygon([
		new GLatLng(37.926868,-95.712891),
		new GLatLng(37.916868,-95.712891),
		new GLatLng(37.916868,-95.722891),
		new GLatLng(37.926868,-95.722891)
	], "#99b3cc", 0, 1, "#99b3cc", 1);
	// map.addOverlay(polygon); */

	var iconOptions = {};
	iconOptions.width = 16;
	iconOptions.height = 16;
	iconOptions.primaryColor = "#ba503f";
	iconOptions.cornerColor = "#ba503f";
	iconOptions.strokeColor = "#f2ede4";
	var icon = MapIconMaker.createMarkerIcon(iconOptions);
	markerOptions = { icon:icon };
	
	//XML Proccessing
	$.getJSON(map_data, function(data) {
		$.each(data.marker, function(i, marker) {
			var latlng = new GLatLng(marker.latitude, marker.longitude);
			var killMarker = new GMarker(latlng, markerOptions);
			var infoHtml = "<div><img style=\"height:60px;width:60px;margin:5px 0 0 5px;float:right;\" src=\"/uploads/profile/60/"+marker.photo+"\" /><h1 style=\"font-size:120%;\">"+marker.target+"</h1>";
			if(marker.antidote) {
				infoHtml += "<h4 style=\"font-size:80%;font-style:italic;\">(saved by an antidote)</h4>";
			}
			infoHtml += "<h4 style=\"font-size:80%;font-style:italic;\">Lost "+marker.time+"</h4>";
			if (marker.description) {
				infoHtml += "<p style=\"margin:0;\">"+marker.description+"</p>";
			}
			if (marker.tagger) {
				infoHtml += "<h2 style=\"font-size:100%;\">Tagged by "+marker.tagger+"</h2>";
			}
			if (marker.assist1 && !marker.assist2) {
				infoHtml += "<h3 style=\"font-size:90%;\">Assisted by "+marker.assist1+"</h3>";
			}
			if (marker.assist1 && marker.assist2) {
				infoHtml += "<h3 style=\"font-size:90%;\">Assisted by "+marker.assist1+" and "+marker.assist2+"</h3>"
			}
			infoHtml+="</div>"
			killMarker.bindInfoWindowHtml(infoHtml, {
				maxWidth: 400
			});
			map.addOverlay(killMarker);
		});
	});

});
