/**
 *  Wetland
 *	
 *  A class for displaying wetland info using Google Maps.
 *  http://www.developer.com/java/web/article.php/10935_3528381_1
 *
 */
var Wetlands = Class.create();
Wetlands.prototype = {
	
	// Alberta coords (center).
	AB_LAT: 55,
	AB_LONG: -115,
	
	initialize: function(map_id, wetlands) {
		this.wetlands = wetlands;
		this.loadMap(map_id);
		this.loadWetlands();
	},
	
	loadMap: function(id) {
		this.map = new GMap2($(id));
		this.map.setCenter(new GLatLng(this.AB_LAT, this.AB_LONG), 5);
		this.map.addControl(new GLargeMapControl());
	},
	
	loadWetlands: function() {
		var _this = this;
		this.wetlands.each(function(w) {
			var point = new GLatLng(w.value.lat, w.value.long);
			w.value.point = point;
			var marker = new GMarker(point);
			_this.map.addOverlay(marker);
			GEvent.addListener(marker, "click", function() { _this.activateWetland(null, w.value); });
			
		});
	},

	activateWetland: function(event, wetland) {
		// Show the infoWindow overlay.
		var myHtml = "<b>" + wetland.name + "</b><br />" + wetland.location + '<br />';
		this.map.openInfoWindowHtml(wetland.point, myHtml);
		// Hide all the info divs
		$$('.wetland_details').each(function(w) {w.hide(); });
		// Show this wetland
		$('wetland_details_' + wetland.id).show();
	},
		
	reset: function() {
		this.map.setCenter(new GLatLng(this.AB_LAT, this.AB_LONG), 5);
	}
	
}