/**
 * Electronation Maps object
 */
$.electronationMaps = {
	/**
	 * Variable to store map
	 */
	map: null,

	
	/**
	 * Initialize the electronationMaps object and load the Google map
	 */
	init: function() {
		// Check if Google maps object exists
		if(typeof GMap2 == 'undefined') {
			alert('GoogleMaps is not loaded!');
			return false;
		}
		// Check if browser is compatible
		if (!GBrowserIsCompatible()) {
			alert('Browser not capable of showing GoogleMaps!');
			return false;
		}
		
		// Bind the unload function
		$(document).bind("unload", function() {
			GUnload();
		});
	},
	
	
	/**
	 * Plot a venue to the map
	 */
	plotVenue: function(venueName,venueUrl,venueStreetaddress,venuePostalcode,venueCity,venueCountry,venueLatitude,venueLongtitude) {
		// Load Google map
		map = new GMap2(document.getElementById("gmap"));
		
		// Set the map type
		map.setMapType(G_NORMAL_MAP);
		
		// Enable map controls
		map.enableContinuousZoom();
		map.enableScrollWheelZoom();
		map.enableDragging();
		map.addControl(new GSmallZoomControl3D());
		
		var point = new GLatLng(venueLatitude,venueLongtitude);
		
		// Set the center of the map and show it at a decent zoom level
		map.setCenter(point, 12);
		
		// Create a marker to show the venue's location
		var marker = new GMarker(point);
		
		// Create a point to set the marker on
		map.addOverlay(marker);
		
		// Open an info window for the marker containing the venue information
		marker.openInfoWindowHtml('<div class="venue"><h3>' + venueName + '</h3><ul><li>' + venueStreetaddress + '</li><li>' + venuePostalcode + ' ' + venueCity + '</li></ul></div>');
	},
};

// Initialize the Electronation maps object
$(document).ready(function() {
	$.electronationMaps.init();
});