// JavaScript Document
	var urlWebsite = "http://hotelburdigala.com/";
	var googleMapDir = "googlemap/";
	var googleMapDirImg = googleMapDir+"images/corners/";
	//var googleMapData = "/googlemap/data/markers.xml";
	var googleMapDataDefaultURL = "/googlemap/data/default.xml";
	var googleMapDataByTmplURL = "/pl/googlemap.pl?lg="+language;
	
	var googleMapPrintURL = [];
	googleMapPrintURL['fr'] = "http://maps.google.com/maps?f=q&hl=fr&geocode=&view=map&q=H%C3%94TEL+BURDIGALA+-+115,+rue+Georges+Bonnac+33000+Bordeaux+-+France&sll=44.839674,-0.586854&sspn=0.008642,0.022745&ie=UTF8&z=16&pw=2";
	googleMapPrintURL['uk'] = "http://maps.google.com/maps?f=q&hl=en&geocode=&view=map&q=HOTEL+BURDIGALA+-+115,+rue+Georges+Bonnac+33000+Bordeaux+-+France&sll=44.839674,-0.586854&sspn=0.008642,0.022745&ie=UTF8&ll=44.839484,-0.586846&spn=0.008642,0.022745&z=16&pw=2";
	
	var map = null;
    var mgr = null;
	
////// *********************************** DEFINITION DES MEDIAS ***********************************//////
	// Create our "tiny" marker icon
	var restaurantIconBig = new GIcon(G_DEFAULT_ICON);
	restaurantIconBig.image = urlWebsite+googleMapDirImg+"big_restaurants.png";
	restaurantIconBig.iconSize = new GSize(67, 58);
	restaurantIconBig.shadow = urlWebsite+googleMapDirImg+"big_ombre.png";
	restaurantIconBig.shadowSize = new GSize(67, 58);
	restaurantIconBig.iconAnchor = new GPoint(17, 55);
	restaurantIconBig.infoWindowAnchor = new GPoint(55, 3);	
	
	var hotelIconBig = new GIcon(G_DEFAULT_ICON);
	hotelIconBig.image = urlWebsite+googleMapDirImg+"big_hotels.png";
	hotelIconBig.iconSize = new GSize(67, 58);
	hotelIconBig.shadow = urlWebsite+googleMapDirImg+"big_ombre.png";
	hotelIconBig.shadowSize = new GSize(67, 58);
	hotelIconBig.iconAnchor = new GPoint(17, 55);
	hotelIconBig.infoWindowAnchor = new GPoint(55, 3);	
	
	var monumentIconBig = new GIcon(G_DEFAULT_ICON);
	monumentIconBig.image = urlWebsite+googleMapDirImg+"big_monuments.png";
	monumentIconBig.iconSize = new GSize(67, 58);
	monumentIconBig.shadow = urlWebsite+googleMapDirImg+"big_ombre.png";
	monumentIconBig.shadowSize = new GSize(67, 58);
	monumentIconBig.iconAnchor = new GPoint(17, 55);
	monumentIconBig.infoWindowAnchor = new GPoint(55, 3);	
	
	var otIconBig = new GIcon(G_DEFAULT_ICON);
	otIconBig.image = urlWebsite+googleMapDirImg+"big_ot.png";
	otIconBig.iconSize = new GSize(67, 58);
	otIconBig.shadow = urlWebsite+googleMapDirImg+"big_ombre.png";
	otIconBig.shadowSize = new GSize(67, 58);
	otIconBig.iconAnchor = new GPoint(17, 55);
	otIconBig.infoWindowAnchor = new GPoint(55, 3);	
	
	var mairieIconBig = new GIcon(G_DEFAULT_ICON);
	mairieIconBig.image = urlWebsite+googleMapDirImg+"big_mairie.png";
	mairieIconBig.iconSize = new GSize(67, 58);
	mairieIconBig.shadow = urlWebsite+googleMapDirImg+"big_ombre.png";
	mairieIconBig.shadowSize = new GSize(67, 58);
	mairieIconBig.iconAnchor = new GPoint(17, 55);
	mairieIconBig.infoWindowAnchor = new GPoint(55, 3);	
	
	
	var restaurantIconMed = new GIcon(G_DEFAULT_ICON);
	restaurantIconMed.image = urlWebsite+googleMapDirImg+"medium_restaurants.png";
	restaurantIconMed.iconSize = new GSize(42, 37);
	restaurantIconMed.shadow = urlWebsite+googleMapDirImg+"medium_ombre.png";
	restaurantIconMed.shadowSize = new GSize(42, 37);
	restaurantIconMed.iconAnchor = new GPoint(11, 36);
	restaurantIconMed.infoWindowAnchor = new GPoint(42, 5);	
	restaurantIconMed.imageMap = [0,0,24,0,24,24,0,24];
	restaurantIconMed.transparent = urlWebsite+googleMapDirImg+"medium_restaurants_trans.png";
	
	var hotelIconMed = new GIcon(G_DEFAULT_ICON);
	hotelIconMed.image = urlWebsite+googleMapDirImg+"medium_hotels.png";
	hotelIconMed.iconSize = new GSize(42, 37);
	hotelIconMed.shadow = urlWebsite+googleMapDirImg+"medium_ombre.png";
	hotelIconMed.shadowSize = new GSize(42, 37);
	hotelIconMed.iconAnchor = new GPoint(11, 36);
	hotelIconMed.infoWindowAnchor = new GPoint(42, 5);	
	hotelIconMed.imageMap = [0,0,24,0,24,24,0,24];
	hotelIconMed.transparent = urlWebsite+googleMapDirImg+"medium_hotels_trans.png";
	
	var monumentIconMed = new GIcon(G_DEFAULT_ICON);
	monumentIconMed.image = urlWebsite+googleMapDirImg+"medium_monuments.png";
	monumentIconMed.iconSize = new GSize(42, 37);
	monumentIconMed.shadow = urlWebsite+googleMapDirImg+"medium_ombre.png";
	monumentIconMed.shadowSize = new GSize(42, 37);
	monumentIconMed.iconAnchor = new GPoint(11, 36);
	monumentIconMed.infoWindowAnchor = new GPoint(42, 5);	
	monumentIconMed.imageMap = [0,0,24,0,24,24,0,24];
	monumentIconMed.transparent = urlWebsite+googleMapDirImg+"medium_monuments_trans.png";
	
	var otIconMed = new GIcon(G_DEFAULT_ICON);
	otIconMed.image = urlWebsite+googleMapDirImg+"medium_ot.png";
	otIconMed.iconSize = new GSize(42, 37);
	otIconMed.shadow = urlWebsite+googleMapDirImg+"medium_ombre.png";
	otIconMed.shadowSize = new GSize(42, 37);
	otIconMed.iconAnchor = new GPoint(11, 36);
	otIconMed.infoWindowAnchor = new GPoint(42, 5);		
	otIconMed.imageMap = [0,0,24,0,24,24,0,24];
	otIconMed.transparent = urlWebsite+googleMapDirImg+"medium_ot_trans.png";
	
	var mairieIconMed = new GIcon(G_DEFAULT_ICON);
	mairieIconMed.image = urlWebsite+googleMapDirImg+"medium_mairie.png";
	mairieIconMed.iconSize = new GSize(42, 37);
	mairieIconMed.shadow = urlWebsite+googleMapDirImg+"medium_ombre.png";
	mairieIconMed.shadowSize = new GSize(42, 37);
	mairieIconMed.iconAnchor = new GPoint(11, 36);
	mairieIconMed.infoWindowAnchor = new GPoint(42, 5);	
	mairieIconMed.imageMap = [0,0,24,0,24,24,0,24];
	mairieIconMed.transparent = urlWebsite+googleMapDirImg+"medium_mairie_trans.png";
	
	
	var restaurantIconSmall = new GIcon(G_DEFAULT_ICON);
	restaurantIconSmall.image = urlWebsite+googleMapDirImg+"small_restaurants.png";
	restaurantIconSmall.iconSize = new GSize(18, 15);
	restaurantIconSmall.shadow = urlWebsite+googleMapDirImg+"small_ombre.png";
	restaurantIconSmall.shadowSize = new GSize(18, 15);
	restaurantIconSmall.iconAnchor = new GPoint(5, 13);
	restaurantIconSmall.infoWindowAnchor = new GPoint(32, 3);	
	restaurantIconSmall.imageMap = [0,0,9,0,9,8,0,8];
	restaurantIconSmall.transparent = urlWebsite+googleMapDirImg+"small_restaurants_trans.png";
	
	var hotelIconSmall = new GIcon(G_DEFAULT_ICON);
	hotelIconSmall.image = urlWebsite+googleMapDirImg+"small_hotels.png";
	hotelIconSmall.iconSize = new GSize(18, 15);
	hotelIconSmall.shadow = urlWebsite+googleMapDirImg+"small_ombre.png";
	hotelIconSmall.shadowSize = new GSize(18, 15);
	hotelIconSmall.iconAnchor = new GPoint(5, 13);
	hotelIconSmall.infoWindowAnchor = new GPoint(32, 3);
	hotelIconSmall.imageMap = [0,0,9,0,9,8,0,8];
	hotelIconSmall.transparent = urlWebsite+googleMapDirImg+"small_hotels_trans.png";	
	
	var monumentIconSmall = new GIcon(G_DEFAULT_ICON);
	monumentIconSmall.image = urlWebsite+googleMapDirImg+"small_monuments.png";
	monumentIconSmall.iconSize = new GSize(18, 15);
	monumentIconSmall.shadow = urlWebsite+googleMapDirImg+"small_ombre.png";
	monumentIconSmall.shadowSize = new GSize(18, 15);
	monumentIconSmall.iconAnchor = new GPoint(5, 13);
	monumentIconSmall.infoWindowAnchor = new GPoint(32, 3);		
	monumentIconSmall.imageMap = [0,0,9,0,9,8,0,8];
	monumentIconSmall.transparent = urlWebsite+googleMapDirImg+"small_monuments_trans.png";
	
	var otIconSmall = new GIcon(G_DEFAULT_ICON);
	otIconSmall.image = urlWebsite+googleMapDirImg+"small_ot.png";
	otIconSmall.iconSize = new GSize(18, 15);
	otIconSmall.shadow = urlWebsite+googleMapDirImg+"small_ombre.png";
	otIconSmall.shadowSize = new GSize(18, 15);
	otIconSmall.iconAnchor = new GPoint(5, 13);
	otIconSmall.infoWindowAnchor = new GPoint(32, 3);		
	otIconSmall.imageMap = [0,0,9,0,9,8,0,8];	
	otIconSmall.transparent = urlWebsite+googleMapDirImg+"small_ot_trans.png";
	
	var mairieIconSmall = new GIcon(G_DEFAULT_ICON);
	mairieIconSmall.image = urlWebsite+googleMapDirImg+"small_mairie.png";
	mairieIconSmall.iconSize = new GSize(18, 15);
	mairieIconSmall.shadow = urlWebsite+googleMapDirImg+"small_ombre.png";
	mairieIconSmall.shadowSize = new GSize(18, 15);
	mairieIconSmall.iconAnchor = new GPoint(5, 13);
	mairieIconSmall.infoWindowAnchor = new GPoint(32, 3);
	mairieIconSmall.imageMap = [0,0,9,0,9,8,0,8];
	mairieIconSmall.transparent = urlWebsite+googleMapDirImg+"small_mairie_trans.png";	
		
	var customIconsBig = [];
    customIconsBig["restaurant"] = restaurantIconBig;
    customIconsBig["hotel"] = hotelIconBig;
    customIconsBig["monument"] = monumentIconBig;
    customIconsBig["ot"] = otIconBig;
    customIconsBig["mairie"] = mairieIconBig;
	
	var customIconsMed = [];
    customIconsMed["restaurant"] = restaurantIconMed;
    customIconsMed["hotel"] = hotelIconMed;
    customIconsMed["monument"] = monumentIconMed;
    customIconsMed["ot"] = otIconMed;
    customIconsMed["mairie"] = mairieIconMed;
	
	var customIconsSmall = [];
    customIconsSmall["restaurant"] = restaurantIconSmall;
    customIconsSmall["hotel"] = hotelIconSmall;
    customIconsSmall["monument"] = monumentIconSmall;
    customIconsSmall["ot"] = otIconSmall;
    customIconsSmall["mairie"] = mairieIconSmall;
	
	var iconTypes = ["restaurant", "hotel", "monument", "ot", "mairie"];
	var markersLoaded = { };
	var markerGroups = { };
	var markerVisibility = { };
	for (var i = 0; i < iconTypes.length; i++) {
		markerGroups[iconTypes[i]] = [];
		markerVisibility[iconTypes[i]] = true;
		markersLoaded[iconTypes[i]] = false;
	}
	if (loadFromFiche){	markerGroups["fiche"] = []; }
	
    //var markerGroups = { iconTypes[0]: [], iconTypes[2]: [], iconTypes[0]: [], iconTypes[0]: [], iconTypes[0]: []};
	//var markerVisibility = { "restaurant": true, "hotel": true, "monument": true, "ot": true, "mairie": true};
	
	var zoomsTransition = [0, 12, 16];
	
	
// Création du bouton d'impression
	// A TextualZoomControl is a GControl that displays textual "Zoom In"
	// and "Zoom Out" buttons (as opposed to the iconic buttons used in
	// Google Maps).
	var btnPrintText = [];
	btnPrintText['fr'] = "Imprimer le plan";
	btnPrintText['uk'] = "Print the map";
	
	// We define the function first
	function TextualCustomControl() {
	}
	
	// To "subclass" the GControl, we set the prototype object to
	// an instance of the GControl object
	TextualCustomControl.prototype = new GControl();
	
	// Creates a one DIV for each of the buttons and places them in a container
	// DIV which is returned as our control element. We add the control to
	// to the map container and return the element for the map class to
	// position properly.
	TextualCustomControl.prototype.initialize = function(map) {
	  var container = document.createElement("div");
	
	  var printDiv = document.createElement("div");
	  this.setButtonStyle_(printDiv);
	  container.appendChild(printDiv);
	  printDiv.appendChild(document.createTextNode(btnPrintText[language]));
	  GEvent.addDomListener(printDiv, "click", function() {
		var Shadowbox = window.parent.Shadowbox;
		Shadowbox.open({
			player:     'iframe',
			title:      btnPrintText[language],
			content:    googleMapPrintURL[language],
			height:     600,
			width:      800
		});
	  });
	
	  map.getContainer().appendChild(container);
	  return container;
	}
	
	// By default, the control will appear in the top left corner of the
	// map with 7 pixels of padding.
	TextualCustomControl.prototype.getDefaultPosition = function() {
	  return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10, 40));
	}
	
	// Sets the proper CSS for the given button element.
	TextualCustomControl.prototype.setButtonStyle_ = function(button) {
	  button.style.textDecoration = "none";
	  button.style.color = "#000000";
	  button.style.backgroundColor = "white";
	  button.style.font = "small Arial";
	  button.style.border = "1px solid black";
	  button.style.padding = "0px";
	  button.style.marginBottom = "3px";
	  button.style.textAlign = "center";
	  button.style.width = "12em";
	  button.style.cursor = "pointer";
	}	
	
	function createMarkers(typeData, itm) {
		var googleMapDataURL = '';
		
		if (typeData == "default"){
			markersLoaded["ot"] = true;
			markersLoaded["mairie"] = true;
			googleMapDataURL = googleMapDataDefaultURL;
		} else if (loadFromFiche != '') {
			googleMapDataURL = googleMapDataByTmplURL+"&t="+typeData;
			googleMapDataURL += "&i="+itm;
			googleMapDataURL += "&f=1";
		} else {
			if (markersLoaded[typeData] != true){
				markersLoaded[typeData] = true;
			}
			googleMapDataURL = googleMapDataByTmplURL+"&t="+typeData;
			if (itm != ''){ googleMapDataURL += "&i="+itm; }
		}
		
		GDownloadUrl(googleMapDataURL, 
			function(data, responseCode) {
				var xml = GXml.parse(data);
				var markers = xml.documentElement.getElementsByTagName("marker");
				var markersSet = [];
				for (var i = 0; i < zoomsTransition.length; i++){
					var currentZoomsTransition = zoomsTransition[i];
					markersSet[currentZoomsTransition] = [];
				}
				for (var i = 0; i < markers.length; i++) {
					var id = markers[i].getAttribute("id");
					var name = markers[i].getAttribute("name");
					var adresse = markers[i].getAttribute("adresse")+' '
								+ markers[i].getAttribute("code_postal")+' '
								+ markers[i].getAttribute("ville")+' '
								+ markers[i].getAttribute("pays");
					var station_tram = markers[i].getAttribute("station_tram");
					var arret_bus = markers[i].getAttribute("arret_bus");
					var arret_autocar = markers[i].getAttribute("arret_autocar");
					var quartier = markers[i].getAttribute("quartier");
					var type = markers[i].getAttribute("type");		
					var latitude = parseFloat(markers[i].getAttribute("latitude"));			
					var longitude = parseFloat(markers[i].getAttribute("longitude"));			
					var selected = parseFloat(markers[i].getAttribute("selected"));	
					
					var pointeurFiche = false;
					if (((type=='restaurant')||(type=='hotel')||(type=='monument'))&&(loadFromFiche)){
						pointeurFiche = true;
					}
					
					for (var j = 0; j<zoomsTransition.length; j++){
						var currentZoomsTransition = zoomsTransition[j];
						if ((currentZoomsTransition==0)&&(type=="hotel")){
							var marker = createMarker(latitude, longitude, id, name, adresse, station_tram, arret_bus, arret_autocar, quartier, type, selected, customIconsBig[type], pointeurFiche);
							markersSet[currentZoomsTransition].push(marker);
						}
						if (currentZoomsTransition==12){
							var marker = createMarker(latitude, longitude, id, name, adresse, station_tram, arret_bus, arret_autocar, quartier, type, selected, customIconsSmall[type], pointeurFiche);
							markersSet[currentZoomsTransition].push(marker);
						}
						if (currentZoomsTransition==16){
							var marker = createMarker(latitude, longitude, id, name, adresse, station_tram, arret_bus, arret_autocar, quartier, type, selected, customIconsMed[type], pointeurFiche);
							markersSet[currentZoomsTransition].push(marker);
						}
					}
					if ((pointeurFiche)&&(loadFromFiche != '')) { loadFromFiche=''; } 
				}
				for (var i = 0; i < zoomsTransition.length; i++){
					var currentZoomsTransition = zoomsTransition[i];
					if (i<zoomsTransition.length-1){
						var maxZoom = zoomsTransition[i+1]-1;
						mgr.addMarkers(markersSet[currentZoomsTransition], currentZoomsTransition, maxZoom);
					} else {
						mgr.addMarkers(markersSet[currentZoomsTransition], currentZoomsTransition);
					}
	  				mgr.refresh();
				}
			}
		);
	}
	
	function createMarker(latitude, longitude, id, name, adresse, station_tram, arret_bus, arret_autocar, quartier, type, selected, iconType, pointeurFiche){
		var point = new GLatLng(latitude, longitude);
		var marker = new GMarker(point, iconType);
		if (pointeurFiche){
			markerGroups["fiche"].push(marker);
			//alert ("fiche");
		} else {
			markerGroups[type].push(marker);
		}
			
		//Création du html de l'infobox			
		var html = '<div class="title">'+name+'</div>'
					+ '<div class="section1">'
					+ adresse
					+ '<br />'
					+ '<i>'+quartier+'</i>'
					+ '</div>'
					+ '<div class="section2">';
		if ((station_tram != null)&&(station_tram != '')){
			html += '<br>&bull; Station de Tram la plus proche : '+station_tram;
		}
		if ((arret_bus != null)&&(arret_bus != '')){
			html += '<br>&bull; Arrêt de Bus le plus proche : '+arret_bus;
		}
		if ((arret_autocar != null)&&(arret_autocar != '')){
			html += '<br>&bull; Arrêt d\'autocar le plus proche : '+arret_autocar;
		}
		// Gestion du lien plus d'infos
		if ((id != null)&&(id != '')&&(type != null)&&(type != '')&&(pointeurFiche == '')){
			var linkToShow = false;
			var linkURL = '';
			if (type == "restaurant"){
				linkToShow = true;
				linkURL = "/pl/restos.pl?itm="+id;
			}
			if (type == "hotel"){
				linkToShow = true;
				linkURL = "/pl/hotels.pl?itm="+id;
			}
			if (linkToShow){
				html += '<a href="'+linkURL+'"><img src="/googlemap/images/corners/btn_plus_infos.gif" align="right" border="0"></a>';			
			}			
		}
		html += '</div>';			
		
		GEvent.addListener(marker, 'mouseover', function() {
			if (map.getZoom() > 2){
				marker.openExtInfoWindow(map, "custom_info_window_"+type, html, {beakOffset: 3});
			}
		});
		//map.addOverlay(marker);
		if (selected == '1'){
			if (map.getZoom() > 2){
				marker.openExtInfoWindow(map, "custom_info_window_"+type, html, {beakOffset: 3});
			}
			//map.setCenter(new GLatLng(latitude, longitude), 16);
		}
		
		return marker;
	}
	function setupMarkers() {
		createMarkers("default", '');
		createMarkers('m', '');
		if ((typeSelected != '')&&(typeSelected != 'm')){
			if (itmSelected != ''){
				createMarkers(typeSelected, itmSelected);
			} else {
				createMarkers(typeSelected, '');
			}
		}
		mgr.refresh();
	}
	
	function updateMarkerGroupState(type) {
		for (var i = 0; i < markerGroups[type].length; i++) {
			var marker = markerGroups[type][i];
			
			if ((markerVisibility[type]) == true){
				if (marker.isHidden()) {
					marker.show();
				}
			} else {
				if (! marker.isHidden()) {
					marker.hide();
				}
			}
		}
	}
	
    function setupMap() {
      if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("shadowbox_content"));
		if ((googlemapDefaultZoom != null)&&(googlemapDefaultZoom != '')){
			map.setCenter(new GLatLng(44.845768, -0.573263), googlemapDefaultZoom);	
		} else {
			map.setCenter(new GLatLng(44.845768, -0.573263), 13);	
		}
		var topLeft = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10,15));	
		var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,15));	
		map.addControl(new GLargeMapControl(), topLeft);		
		//map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl(), topRight);
		// ajout du bouton imprimer
		map.addControl(new TextualCustomControl());
		map.enableDoubleClickZoom();
		
	  	mgr = new MarkerManager(map, {trackMarkers:true});
	
		GEvent.addListener(mgr, "changed", function() {
			for (var i = 0; i < iconTypes.length; i++) {
				updateMarkerGroupState(iconTypes[i]);
			}
		});
		
	 	mgr.refresh();
		
		//window.setTimeout(setupMarkers, 0);
		window.setTimeout(setupMarkers, 0);
      }
    }
