$(function(){ 

  $("#map").css({
		height: 300,
		width: 635
	});
	var myLatLng = new google.maps.LatLng(9, -20);
  MYMAP.init('#map', myLatLng, 2);
  
	MYMAP.placeMarkers('/products/_deployments');
});

var MYMAP = {
  map: null,
	bounds: null
}

MYMAP.init = function(selector, latLng, zoom) {
  var myOptions = {
    zoom:zoom,
    center: latLng,
    disableDefaultUI: true,
    navigationControl: true,
    mapTypeId: google.maps.MapTypeId.TERRAIN
  }
  this.map = new google.maps.Map($(selector)[0], myOptions);
	this.bounds = new google.maps.LatLngBounds();
}

var infoWindow = new google.maps.InfoWindow({maxWidth:350});

MYMAP.placeMarkers = function(filename) {
	$.get(filename, function(xml){
		$(xml).find("marker").each(function(){
			var name = $(this).find('name').text();
			var desc = $(this).find('description').text();
			var url = $(this).find('url').text();
			
			// create a new LatLng point for the marker
			var lat = $(this).find('latitude').text();
			var lng = $(this).find('longitude').text();
			var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));
			
			// extend the bounds to include the new point
			MYMAP.bounds.extend(point);
			
			var marker = new google.maps.Marker({
				position: point,
				map: MYMAP.map,
				icon: "/-/images/_icons/marker_ushahidi.png"
			});
			
			
			
			var html='<h4 class="infoWindow-title"><a href="'+url+'">'+name+'</a></h4><div class="infoWindow-content">'+desc+"</div>";
			google.maps.event.addListener(marker, 'click', function() {
				infoWindow.setContent(html);
				infoWindow.open(MYMAP.map, marker);
			});
			//MYMAP.map.fitBounds(MYMAP.bounds);
		});
	});
}


