 var RMAP = {

	map: {},

	markers: [], 
	
	allGroups: true,

	addMarker: function(marker) {this.markers.push(marker);},

	createMarkers: function() {
		var self = this;
		jQuery.each(this.markers, function(index, item) {
			
			if (index == 0) {self.recenterAndZoom(item);}                        
			
			var point = new GLatLng(item.latitude, item.longitude),
				marker = new GMarker(point),
				that = self;
			
			GEvent.addListener(marker, "click", function() {
				
				var html = '<p>';
				
				if (item.address !== '') {
					html += item.address;
				}
				
				if (item.address_2 !== '') {
					html += '<br />' + item.address_2;
				}      
				
				if (html !== '<p>') {
					html += '<br />';
				}                              

				html += item.city + ', ' + item.state + ' ' + item.postalcode;
				
				html += '</p>';
				        
				
				if (item.group_email !== '') {
					html += '<p>' + item.group_email + '</p>';
				}
				
				html += '<p><a style="position: absolute; bottom: 0; right: 0px;" href="http://www.results.org//groups/'+item.url_title+'">More info</a></p>';
				   
				if (item.group_name !== '')
				{
					html = '<h4>' + item.group_name + '</h4>' + html;
				}
				
				that.map.openInfoWindowHtml(point, '<div style="height: 125px;">'+html+'</div>');
			}); 
			
			self.map.addOverlay(marker);
		   
		});
	}, 
	
	show: function() {
		$("#map_canvas").animate({ opacity: 0 }, 200, function() {
			$("#map_canvas").html('<h4 style="margin:auto;">Loading map...</h4><img src="/images/ajax-loader.gif" style="border:none;display:block;margin:60px auto 0px auto;" />');
			$("#map_canvas").css("display","block");
			$("#map_canvas").animate({
				height: "300px",
				marginBottom: "20px",
				opacity: 1
			}, 
			300, 
			function() {
				RMAP.loadMap();
				RMAP.createMarkers();   
			});
		});
	},              
      
	recenterAndZoom: function(markerData) {
	   	if (!this.allGroups) {
			var point = new GLatLng(markerData.latitude, markerData.longitude);
			this.map.setCenter(point); 
			this.map.setZoom(6);       
		}   
	},

	loadMap: function() {
	    this.map = new GMap2(document.getElementById("map_canvas"));
	    this.map.setCenter(new GLatLng(37, -100), 4);		    
	    this.map.setUIToDefault();
	} 
};     


