﻿// Class Map

BenefulMap.BaseMap = Class.extend({
	init: function(mapCanvas, spotLatLng, initialZoom) {
        this.mapCanvas = mapCanvas;

        this.spotLatLng = spotLatLng;
       
        this.initialZoom = initialZoom;
        
        this.gmap = new GMap2( $(mapCanvas).get(0) ); // equivalent to document.getElementById
        this.gmap.setMapType(G_NORMAL_MAP);
        this.gmap.setCenter(spotLatLng, initialZoom);
        
        var customIcon = new GIcon();
        customIcon.image = BenefulMap.Constants.IMG_MARKER;
    	customIcon.iconSize = new GSize(44,41);
        customIcon.iconAnchor = new GPoint(17,41);
        customIcon.infoWindowAnchor = new GPoint(0,0);
        this.icon = customIcon;
        
        var marker = new GMarker(spotLatLng, customIcon);
    	this.gmap.addOverlay(marker);
    	this.marker = marker;
        
        this.globalMapListeners();
	},
	getGmap: function() {
	   return this.gmap;
	},
	setGmap: function(gmap) {
	   this.gmap = gmap;
	},
	getMarker: function() {
	   return this.marker;
	},
	setMarker: function() {
	   this.marker = marker;
	},
	getIcon: function() {
	   return this.icon;
	},
	setIcon: function(icon) {
	   this.icon = icon;
	},
	getSpotLatLng: function() {
	   return this.spotLatLng;
	},
	setSpotLatLng: function(spot) {
	   this.spotLatLng = spot;
	},
	getMapCanvas: function() {
	   return this.mapCanvas;
	},
	setMapCanvas: function(mapCanvas) {
	   this.mapCanvas = mapCanvas;
	},
	globalMapListeners: function() {
	   	var self = this;
	   	$("window").resize( function() { 
    		self.getGmap().checkResize(); // Map refreshes if window resized
    	});

    	/*$("window").unload( function() {
    		GUnload(); // Avoid memory leaks in IE
    	});*/
	}
});
	

	

