//<![CDATA[

 var gmarkers = [];
 var customIcons = [];


var iconYellow = new GIcon();
iconYellow.image = 'http://www.adventistyouth.org/cor/images/yellow-dot.png';
iconYellow.shadow = 'http://www.adventistyouth.org/cor/images/msmarker_shadow.png';
iconYellow.iconSize = new GSize(32, 32);
iconYellow.shadowSize = new GSize(59, 32);
iconYellow.iconAnchor = new GPoint(13, 25);
iconYellow.infoWindowAnchor = new GPoint(13, 0);

var iconRed = new GIcon();
iconRed.image = 'http://www.adventistyouth.org/cor/images/red-dot.png';
iconRed.shadow = 'http://www.adventistyouth.org/cor/images/msmarker_shadow.png';
iconRed.iconSize = new GSize(32, 32);
iconRed.shadowSize = new GSize(59, 32);
iconRed.iconAnchor = new GPoint(13, 25);
iconRed.infoWindowAnchor = new GPoint(13, 0);

var iconGreen = new GIcon();
iconGreen.image = 'http://www.adventistyouth.org/cor/images/green-dot.png';
iconGreen.shadow = 'http://www.adventistyouth.org/cor/images/msmarker_shadow.png';
iconGreen.iconSize = new GSize(32, 32);
iconGreen.shadowSize = new GSize(59, 32);
iconGreen.iconAnchor = new GPoint(13, 25);
iconGreen.infoWindowAnchor = new GPoint(13, 0);


customIcons["NAD"] = iconYellow;
customIcons["PRO"] = iconRed;
customIcons["TED"] = iconGreen;


 function createMarker(point,name,address,type,website) {

        var marker = new GMarker(point,customIcons[type]);
		var html = "<span style=\"font-size:12px\"><b>"+name+"</b><br>"+address+"<br><a href=\""+website+"\" target=\"_blank\">"+website+"</a></span>";
		GEvent.addListener(marker, "click", function() {
		          marker.openInfoWindowHtml(html);
        });

        return marker;
      }




function initalise() {

	document.getElementById("map_canvas").innerHTML = "Map loading...";

	if (!GBrowserIsCompatible()) {
	  	alert('Sorry. Your browser is not Google Maps compatible.');
	}

	var map = new GMap2(document.getElementById("map_canvas"));
	map.setCenter(new GLatLng(38.6855, -98.2851), 4);
	map.addControl(new GOverviewMapControl());
	map.setUIToDefault();

	process_it = function(doc) {

        var jsonData = eval('(' + doc + ')');

		 for (var i=0; i<jsonData.length; i++) {
		          var point = new GLatLng(jsonData[i].lat, jsonData[i].lng);
		          var marker = createMarker(point,jsonData[i].name,jsonData[i].address,jsonData[i].type,jsonData[i].website);
		          map.addOverlay(marker);
        }
     }


	GDownloadUrl("http://www.adventistyouth.org/cor/ajax/cor-churches.php", process_it);


}// initialise


$(document).ready(function() {
	initalise();	
});

$(window).unload( function () { 
	GUnload();
} );



//]]>
