
    //
    // Copyright © 2001-2007, Ecilia SARL, Francis PALLINI
    //

	if (loadAnimation) {
		Event.stopObserving(window, 'load', loadAnimation);
	}
	Event.observe(window, 'load', loadMap, false);

	Event.observe(window, 'unload', GUnload, false);

	var france = { point: new GLatLng(47.52, 2.11), zoom: 5, type: G_SATELLITE_MAP };
	var paris  = { point: new GLatLng(48.886194, 2.303289), zoom: 13, type: G_NORMAL_MAP,
		url: '/articles/infobulle-12-brut.html', title: 'Bureau de Paris' };
	var lyon   = { point: new GLatLng(45.762975, 4.853678), zoom: 13, type: G_NORMAL_MAP,
		url: '/articles/infobulle-13-brut.html', title: 'Agence de Lyon' };

	var map;
	var mapControl = new GSmallMapControl();

	function loadMap() {
		if (loadAnimation) {
			loadAnimation();
		}

		if (GBrowserIsCompatible()) {
		    map = new GMap2($('map'));

			// Icone Ecilia
			var icon        = new GIcon();
			icon.image      = '/images/map/icon1.png';
			icon.shadow     = '/images/map/icon1_shadow.png';
			icon.iconSize   = new GSize(38, 24);
			icon.shadowSize = new GSize(38, 24);
			icon.iconAnchor = new GPoint(19, 12);
			icon.infoWindowAnchor = new GPoint(24, 4);

			// Villes
			paris.marker = new GMarker(paris.point, { icon: icon, title: paris.title });
			lyon.marker  = new GMarker(lyon.point, { icon: icon, title: lyon.title });

		    configureFrance(map);

			map.addOverlay(paris.marker);
			map.addOverlay(lyon.marker);
		}

		Event.observe($('map_france'), 'click', function() {
			configureFrance(map);
		}, false);

		Event.observe($('map_paris'), 'click', function() {
			configureCity(map, paris);
		}, false);

		Event.observe($('map_lyon'), 'click', function() {
			configureCity(map, lyon);
		}, false);
	}

	function configureFrance(map) {
		// Affiche une vue satellite de France
	    map.setCenter(france.point, france.zoom, france.type);
		map.disableDragging();
		map.disableInfoWindow();
		map.removeControl(mapControl);

		// Zoom sur une ville
		GEvent.clearListeners(paris.marker, 'click');
		GEvent.addListener(paris.marker, 'click', function() {
			configureCity(map, paris);
		});

		GEvent.clearListeners(lyon.marker, 'click');
		GEvent.addListener(lyon.marker, 'click', function() {
			configureCity(map, lyon);
		});
	}

	function configureCity(map, city) {
		// Affiche un plan de ville
	    map.setCenter(city.point, city.zoom, city.type);
		map.enableDragging();
		map.enableInfoWindow();
		map.addControl(mapControl);

		GEvent.clearListeners(paris.marker, 'click');
		GEvent.clearListeners(lyon.marker, 'click');
		GEvent.addListener(city.marker, 'click', function() {
			configureFrance(map);
		});

		new Ajax.Request(city.url, { onSuccess:
			function(transport) {
				var html = transport.responseText;
				city.marker.openInfoWindowHtml(html, {maxWidth: 200});
			}
		});
	}
