//var requestURL = 'fileadmin/scripts/ajax/getImmeubles.php';
//var	detailsRequestURL = 'fileadmin/acadomia/scripts/ajax/getAgencyDetails.php';

var i = 0;

function loadMaps(pays, zoom) {
	if (GBrowserIsCompatible()) {
		var eMap = document.getElementById('map');
		var map = new GMap2(eMap);
		map.addControl(new GLargeMapControl());
		
	map.setCenter(new GLatLng(46.8, 1.5), 6);
				
		/*				if (zoom == 'IDF') {
					map.setCenter(new GLatLng(48.8, 2.2), 10);
				} else {
					map.setCenter(new GLatLng(46.8, 1.5), 6);
				}
				break;*/
		}
	
	getAgencies(map);
	
}

function createPoint(immeuble, theMap) {
	var point = new GPoint(immeuble.longi, immeuble.latti);
	if (point) {
		var theMarker = createMarker(point, immeuble, theMap);
		theMap.addOverlay(theMarker);
	} else {
		return;
	}
}

function createMarker(point, immeuble, theMap) {
	// creation de l'icone
	var icon = new GIcon();
	icon.image = "fileadmin/templates/html/images/" + immeuble.icon;
	icon.shadow = "fileadmin/templates/html/images/gmi_shadow.png";
	icon.iconSize = new GSize(16, 25);
	icon.shadowSize = new GSize(22, 20);
	icon.iconAnchor = new GPoint(12, 24);
	icon.infoWindowAnchor = new GPoint(5, 1);
		
	// creation du marker
	var marker = new GMarker(point, icon);
	
	// creation de l'infobulle au click sur le point
	GEvent.addListener(marker, 'click', function() {
		var html = '<div><div style="float: left; margin-left: 15px;"><img src="fileadmin/user_upload/residence/media/'+ immeuble.image +'" width="110" height="90"></div><div style="float: left; margin-left: 10px; margin-right:15px;"><strong>'+immeuble.nom+'</strong><br/><br/>'+immeuble.adresse+'<br/><a href="' + immeuble.fiche + '" style="color:#00F;text-decoration:underline;">Acc&eacute;der &agrave; la fiche</a></div></div>';
		marker.openInfoWindowHtml(html);
	});

	return marker;
}
	
function clearMarkers() {
	map.clearOverlays();
}


function getAgencies(theMap) {
	for (var i in tabRes) {
		createPoint(tabRes[i], theMap);
	}
	
	$('#loading-img').hide();
}

