/**
 * HoldenMap JS Class wraps Google Maps API and is implemented in object-oriented way.
 * 
 * Require: JQuery, HJS plugin (JQuery Object Oriented Class), and Google Maps API V3
 * 
 * USAGE:
 * var dealerMap;
 * $(document).ready(function() {
 *     dealerMap = new HoldenMap(document.getElementById("map"), ${dealer.latitude}, ${dealer.longitude});
 *     dealerMap.create();
 * });
 */
var HoldenMap = $.Class.create({
	initialize: function(node, latitude, longitude) {
		this.node = node;
		this.latitude = latitude;
		this.longitude = longitude;
		this.map = null;
	},

	create: function() {
		// Setup Map
		var centerLatlng = new google.maps.LatLng(this.latitude, this.longitude);
		var myOptions = {
			zoom: 15,
			center: centerLatlng,
			mapTypeId: google.maps.MapTypeId.ROADMAP
		}
		this.map = new google.maps.Map(this.node, myOptions);

		// Setup Marker
		var markerLatlng = new google.maps.LatLng(this.latitude, this.longitude);
	    var holdenMarkerImage = hld_resource_path + '/images/retailer_locator/HoldenMapsBaloon.PNG';
	    this.marker = new google.maps.Marker({
	        position: markerLatlng,
	        map: this.map,
	        icon: holdenMarkerImage
	    });
	},

	toggleMarker: function() {
		if (this.marker.getMap()) {
			this.marker.setMap(null);
		} else {
			this.marker.setMap(this.map);
		}
	}
});

