/**
 * @author mreeve
 * 
 * Make sure to include <div id="map"></div> somewhere in html of page
 */
var googleMapsApiKeys = [];
googleMapsApiKeys['http://greatharvestutah.com/']=googleMapsApiKeys['http://www.greatharvestutah.com/']='ABQIAAAAHOfaqK9eZFl41woc8qCUzBTWYGUnSMDY210FWhwzTg9DdzbuExTELnIHvwCqKhPoGy6dG91b00DR7w';
googleMapsApiKeys['http://summerlinbread.com/']=googleMapsApiKeys['http://www.summerlinbread.com/']='ABQIAAAAHOfaqK9eZFl41woc8qCUzBRqhgnKcGC9rFcNnfAnN4SOFPI8phQjW2WdgqOBqNx6FQxHcyhG_btIBg';
googleMapsApiKeys['http://greatharvestlv.com/']=googleMapsApiKeys['http://www.greatharvestlv.com/']='ABQIAAAAHOfaqK9eZFl41woc8qCUzBRlE1gW7hk5FZbt70xNQFlHN7W1NhSQeoZgTTzCXGr0Ft6QWaNqYlZbNg';
googleMapsApiKeys['http://birminghambread.com/']=googleMapsApiKeys['http://www.birminghambread.com/']='ABQIAAAAHOfaqK9eZFl41woc8qCUzBRIh7PHHB7syAHgt63deedc5a5J8xSteDF5zVFwDiXJqErdWDTsB5LEBg';

document.write('<script src="http://maps.google.com/maps?file=api&v=2&key='+googleMapsApiKeys[location.protocol+"//"+location.host+"/"]+'" type="text/javascript"></script\>');

var map;
var markers = new Array();
var lat;
var lng;

$(function() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById('map'));
		map.addControl(new GLargeMapControl());
		map.setCenter(new GLatLng(40.644178,-111.897125), 10);
	}
	
	$("div.allLocations > p").each(function(index) {
		lat = parseFloat($(this).children("#lat").html());
		lng = parseFloat($(this).children("#lng").html());
		
		if (lat && lng) {

			var point = new GLatLng(lat,lng);
			var html = $(this).html();
			
			// Create the marker. 
			var marker = new GMarker(point);          
				GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowHtml(html);
			});
			markers[index] = marker;
			map.addOverlay(marker);
			
			$(this).bind('mouseover', function() {
				markers[index].openInfoWindowHtml(html);	
			})
		}
	});
	
	if ($("div.allLocations > p").length == 1) {
		map.setCenter(new GLatLng(lat, lng), 13);
	}	
});

$(document.body).unload(function() {
	if (GBrowserIsCompatible()) {
		GUnload();
	}
});	