VansMap = function()
{
	this.start();	
}

VansMap.prototype = new Local();

// Resize the map viewport based on the height of the screen, 
// minus the nav bar at the top of the screen.
VansMap.prototype.start = function()
{
	this.map = new GMap2(document.getElementById("map"));
	
	var that = this;
	
	
	// Fire up the ajax and load the initial set of spots.
	ajax = new Ajax.Request('/ajax/get_user_lat_long/', 
	{
		method: 'get',
		onSuccess: function (transport, json) 
		{
			json = eval(transport.responseText);
			
			that.userLat = json.lat;
			that.userLong = json.long;
			that.localLevel = json.local_level;
			that.ISO2 = json.ISO2;
			that.setUpMap();
		}
	});	
}
VansMap.prototype.setUpMap = function()
{
	//this.map.setCenter(new GLatLng(this.userLat, this.userLong), this.getInitialZoomLevel());	
	this.map.setCenter(new GLatLng(34.048753,-118.274032), 11);	
	this.map.setUIToDefault();
	
	// Turn on scroll zooming.
	this.map.enableScrollWheelZoom(); 
	
	// Disable wheel scrolling if the user is over the map.
	// http://esa.ilmari.googlepages.com/scrollzoom.htm
	GEvent.addDomListener(this.map.getContainer(), "DOMMouseScroll", this.disableWheelEvent);
	this.map.getContainer().onmousewheel = this.disableWheelEvent; 
	
	var that = this;
	GEvent.addListener(this.map, "zoomend", function(oldZoom,newZoom) 
	{
		if (newZoom > oldZoom)
		{ 
			// When zooming with a window open, the map tends to pan it sels 
			// to the new window. To sort that, we'll just refocus on that open window
			// anwyay when zooming.
			if (that.map.getExtInfoWindow())
			{
				that.map.setCenter(that.map.getExtInfoWindow().marker_.getLatLng());
			}
		} 
		
		//that.buildMapPoints();
	});


	// Set default map type to terrain map
	//this.map.setMapType(G_SATELLITE_MAP);
	
	
	// Bind our clicks
	//GEvent.addListener(this.map, "click", this.leftClick);
	
	// Remove the types we dont want.
	//this.map.removeMapType(G_HYBRID_MAP);
	G_PHYSICAL_MAP.getMinimumResolution 	= function () { return 2 }; 
	G_NORMAL_MAP.getMinimumResolution 		= function () { return 2 }; 
	G_SATELLITE_MAP.getMinimumResolution 	= function () { return 2 }; 
	
	// And add the one we do.
	//this.map.addMapType(G_SATELLITE_MAP);
	
	// Kick off the zoom check
	var that = this;
	
	easeZoomOut = function()
	{
		var paragraphs = that.map.getContainer().getElementsByTagName('p').length;
		
		if(paragraphs > 6)
		{
			that.map.zoomOut();
		}
	}
	
	interval = setInterval(easeZoomOut,500);

	//this.buildMapPoints();
}



VansMap.prototype.buildMapPoints = function(opt_opts)
{	
	var point = this.getLatLong(45.031993,7.665474);
	var marker = new GMarker(point);
	
	this.map.setCenter(point, 11);
	
	var that = this;
	GEvent.addListener(marker, 'click', function()
	{ 
		$$('#vans-events-map #map')[0].hide();
		$$('#vans-events-map #address')[0].show();
	});
	
   this.map.addOverlay(marker);
}
