var Map = Class.create({

	marker: null,
	map_control_offset: 20,
	type: null,
	route: { from: null, to: null },
	query: null,
	point: null,

	initialize: function(application, map, point) 
	{
		
		this.app = application;

		// create and setup a new google map 
		this.gMap = new GMap2(map);
		
		this.point = point;
		
		this.setMapView(this.gMap, this.point, this.type);
		
		var c = new GSmallMapControl;
		this.gMap.addControl(c);
		
		this.gMap.enableDoubleClickZoom();
		//this.gMap.enableContinuousZoom();
		this.gMap.enableScrollWheelZoom();
		GEvent.addDomListener(this.gMap.getContainer(), "DOMMouseScroll",
			function(oEvent) { if (oEvent.preventDefault) oEvent.preventDefault(); });
		
	},
	
	clear: function() 
	{

		this.gMap.clearOverlays();
		
	},

	// Observes changes in the map area
	initObserve: function() {
		
	},
	
	getMapView: function() 
	{
		
		var center = this.gMap.getCenter();
		var lat = Math.round(center.lat()*100000)/100000;
		var lng = Math.round(center.lng()*100000)/100000;
		
		this.point = { lat: lat, lng: lng, zoom: this.gMap.getZoom() };
		this.type = this.gMap.getCurrentMapType().getUrlArg();
		
	},
	
	setMapView: function(map, point, type) 
	{
		
		if (!point || !point.lat || !point.lng || !point.zoom) {

			var center = new GLatLng(0,0);
			var zoom = 2;
			
		} else {
			
			var center = new GLatLng(point.lat, point.lng);
			var zoom = point.zoom;
			
		}
		
		map.setCenter(center, zoom);
		// This one caused a lot of trouble until I realized to convert variable to integer. Be sure that your variables are of desired type.
		map.setZoom(parseInt(zoom)); 

		switch (type) {
			
			case "k": map.setMapType(G_SATELLITE_MAP); break;
			case "h": map.setMapType(G_HYBRID_MAP); break;
			case "m": map.setMapType(G_NORMAL_MAP); break;
			default: map.setMapType(G_NORMAL_MAP); break;
			
		}

	}
	
});


