var url = 'http://www.webhebergement.com/dev/madmundo/images/';
var map = null;
var geocoder = null;

function gmaps() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("gmaps"));
		map.addMapType(G_HYBRID_MAP);
		map.setMapType(G_HYBRID_MAP);
            map.addControl(new GScaleControl());
            map.addControl(new GSmallZoomControl3D(), new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7,15)));                
            map.setCenter(new GLatLng(25.0, 0.0), 2);

		geocoder = new GClientGeocoder();

		for (var i = 0; i < datas.length; i++) {
			var marker = createMarker(i);
			//map.addOverlay(marker);
		}

	}

}

function showAddress(address) {
	if (geocoder) {
		geocoder.getLatLng(
			address,
			function(point) {
				if (!point) {
					alert(address + " not found");
				} else {
					//map.setCenter(point, 13);
					map.panTo(point);
					var marker = new GMarker(point);
					marker.content = address;
					addClickevent(marker);
					map.addOverlay(marker);
					//marker.openInfoWindowHtml(address);
				}
			}
		);
	}
}

function addMarker(data) {
	if (geocoder) {
		geocoder.getLatLng(
			data.city+','+data.country,
			function(point) {
				if (!point) {
					alert(address + " not found");
				} else {
					//map.setCenter(point, 13);
					//map.panTo(point);
					var marker = new GMarker(point);
					//marker.content = ['<b>', data.title, '</b><br>', data.city, ', ', data.country, '<br><a href="', data.url, '" target="_blank">', '<img src="', data.img, '" alt="" width="240" height="180" border="0" /></a>', '.<br><a href="', data.url, '" target="_blank">Voir la vidéo</a>'].join('');
					addClickevent(data,marker);
					map.addOverlay(marker);
				}
			}
		);
	}
}

function addClickevent(data,marker) { // Add a click listener to the markers
 GEvent.addListener(marker, "click", function() {
 //alert(data.url);
  window.location.href=data.url;
 });
 return marker;
}

function createMarker(ind) {
  var data = datas[ind];
  var marker = addMarker(datas[ind]);
  //geocoder.getLatLng(data.city +', '+ data.country, function(point) { var marker = new GMarker(point); } );

  //var marker = new GMarker(new GLatLng(business.lat, business.lng));

/*
  GEvent.addListener(marker, 'click', function() {
    marker.html = ['<b>', data.title, '</b><br>', data.city, '<br> ', data.country, '.'].join('');
    currentMarker = marker;
    marker.openInfoWindowHtml(marker.html);
  });
*/
  return marker;

}
