﻿if (GBrowserIsCompatible()) {
	var gmarkers = [];
	var htmls = [];
	var i = 0;

	var Icon = new GIcon();
	Icon.image = "images/hots-map.png";
	Icon.shadow = "images/hots-map-shadow.png";
	Icon.iconSize = new GSize(16, 16);
	Icon.shadowSize = new GSize(25, 16);
	Icon.iconAnchor = new GPoint(8, 8);
	Icon.infoWindowAnchor = new GPoint(8, 8);
	Icon.infoShadowAnchor = new GPoint(8, 8);
	
	var clusterIcon = new GIcon();
	clusterIcon.image = 'images/multi-map.png';
	clusterIcon.shadow = 'images/multi-map-shadow.png';
	clusterIcon.iconSize = new GSize( 32, 32 );
	clusterIcon.shadowSize = new GSize( 42, 32 );
	clusterIcon.iconAnchor = new GPoint( 8,8 );
	clusterIcon.infoWindowAnchor = new GPoint( 8, 8 );
	clusterIcon.infoShadowAnchor = new GPoint( 8, 8 );
	
	function createMarker(point,name,html) {
		var marker = new GMarker(point,Icon);
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(html);
		});
		return marker;
	}
	
	function myclick(i) {
		gmarkers[i].openInfoWindowHtml(htmls);
	}
	
	var map = new GMap(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
	map.setCenter(new GLatLng(38.479395,-97.998047), 4);
	
	var clusterer = new Clusterer(map);
	
	clusterer.icon = clusterIcon;
	clusterer.maxVisibleMarkers = 5;
	clusterer.gridSize = 10;
	clusterer.SetMinMarkersPerClusterer = 2;
	//clusterer.maxLinesPerInfoBox = 10;
	
	var request = GXmlHttp.create();
	request.open("GET", "jobs.xml", true);
	request.onreadystatechange = function() {
		if (request.readyState == 4) {
			var xmlDoc = GXml.parse(request.responseText);
			var markers = xmlDoc.documentElement.getElementsByTagName("marker");
			for (var i = 0; i < markers.length; i++) {
				var lat = parseFloat(markers[i].getAttribute("lat"));
				var lng = parseFloat(markers[i].getAttribute("lon"));
				var point = new GPoint(lng,lat);
				var title = markers[i].getAttribute("title");
				var url = markers[i].getAttribute("jobid");
				var marker = createMarker(point,title,"<div style='float:left; text-align:left;'><img src='images/hots-map.png' style='float:left; padding:2px 5px 2px 2px;'>"+title+"<br><div style='display:inline-block;'><a href=joblisting.php?id="+url+">View this job</a></div></div>");
				clusterer.AddMarker(marker,title,url);
			}
		}
	}
	request.send(null);
} else {
	alert("Sorry, the Google Maps API is not compatible with this browser");
}
