/*

	PACWEB
	© Princeton Alliance Church

	Javascript Handler: /about/directions/index.tpl

*/

function handler() {

	//
	// initialise Google Maps
	//
	if (GBrowserIsCompatible()) {

		// add loading screen
		$('<div id="map-loading">Loading...</div>').insertBefore('#map-stage');

		// locate custom icon
		var mapIconURL = $('#map img')[0].src;
		mapIconURL = mapIconURL.substr(0, mapIconURL.lastIndexOf('-') + 1) + 'logo.png'

		// create custom icon
		var mapIcon = new GIcon();
		mapIcon.image = mapIconURL;
		mapIcon.iconSize = new GSize(48, 40);
		mapIcon.iconAnchor = new GPoint(24, 20);

		var mapMarker = new GMarker(new GLatLng(40.339478, -74.592528), {icon: mapIcon});
		GEvent.addListener(mapMarker, 'click', function() {
			return !spawn(
				'http://maps.google.com/maps?f=l&hl=en&geocode=&time=&date=&ttype=&q=%22Princeton+Alliance+Church%22&near=&sll=40.338535,-74.591082&sspn=0.011024,0.020084&ie=UTF8&z=16&iwloc=A&om=1&iwstate1=dir',
				this.id,
				prefs.spawnOnExternalURL
			);
		});

		// map it
		var map = new GMap2($('#map-stage')[0]);
		map.addControl(new GSmallZoomControl());
		map.addControl(new GMapTypeControl());
		GEvent.addListener(map, 'load', function() {
			// remove loading screen
			$('#map-loading').remove();
		});
		map.setCenter(new GLatLng(40.338078, -74.592528), 15);
		map.addOverlay(mapMarker);

	}

	// make sure GMaps cleans up after itself
	$(window).unload(function() {
		GUnload();
	});

}

// [EOF]