var largeMapControl3D = '';
function initLargeMap(Latitude, Longitude, facteurZoom, fichier, largeur, hauteur) { // initialisation de la carte Google Maps encart GEO
	var locations = {};
	var isLoaded = true;
	if(document.getElementById('GEOmapGlobal')) {
		isLoaded = (document.getElementById('GEOmapGlobal').innerHTML.length == 0 ) ? false : true;
	}
	if ( typeof largeur == "undefined") {
	   largeur = 410;
	}
    if ( typeof hauteur == "undefined") {
       hauteur = 306;
    }

	if ( (isLoaded == false) && typeof Latitude != "undefined" && typeof Longitude != "undefined" ) {
		if ( GBrowserIsCompatible() ) {
		      var regionMap = new GMap2( document.getElementById('GEOmapGlobal'), { size: new GSize(largeur, hauteur) } );
	
/*
  on a un pb avec l'ajax et ce controle
  regionMap.addControl(new GLargeMapControl3D() );
  il ne faut le créer qu'une fois ( on le stoque donc en local ) sinon cela plante l'affichage de la carte au rechargement ajax ... merci GM
  C'est comme si qu'on faisait un saint geulton
*/
              if (largeMapControl3D == '' ) {
                largeMapControl3D = new GLargeMapControl3D();
              }
              regionMap.addControl(largeMapControl3D);
              regionMap.setMapType(/*G_HYBRID_MAP*/);
              regionMap.enableDoubleClickZoom();
              regionMap.addControl(new GMapTypeControl());
              var pointCentre = new GLatLng( Latitude , Longitude );
              regionMap.setCenter(pointCentre, facteurZoom);
			/*regionMap.addControl(new GOverviewMapControl(new GSize(80,70)));*/ 
            GDownloadUrl('/scripts/' + fichier, function(data) {
				var xml = GXml.parse(data);
				var markers = xml.documentElement.getElementsByTagName('marker');

				for (var i = 0; i < markers.length; i++) {
                    var name    = xml.documentElement.getElementsByTagName('name')[i].firstChild.nodeValue;
                    var type    = xml.documentElement.getElementsByTagName('typeword')[i].firstChild.nodeValue;
					var picture = xml.documentElement.getElementsByTagName('picture');
					var text 	= xml.documentElement.getElementsByTagName('text');
					var mylink 	= xml.documentElement.getElementsByTagName('link');
					var pricing = xml.documentElement.getElementsByTagName('price');

					for (var j = 0; j < markers.length; j++) {
						var pageurl 	= mylink[i].getAttribute('pageurl');
						var pagetitle 	= mylink[i].getAttribute('title');
						var pageword 	= mylink[i].getAttribute('word');
						var urlimg 		= picture[i].getAttribute('urlimg');
						var prodtype 	= pricing[i].getAttribute('prodtypeword');
						var bestprice 	= pricing[i].getAttribute('amount');
						var currency 	= pricing[i].getAttribute('curr');
						var priceword 	= pricing[i].getAttribute('word');
						var details 	= (text[i].firstChild != null) ? text[i].firstChild.nodeValue : '' ;
					}
					var address = markers[i].getAttribute('address');
					var flag 	= markers[i].getAttribute('type');
					var latlng 	= new GLatLng(parseFloat(markers[i].getAttribute('lat')),
									parseFloat(markers[i].getAttribute('lng')));
					var residence = { 
						latlng		: latlng, 
						name		: name, 
						address		: address, 
						flag 		: flag,
						type		: type, 
						urlimg		: urlimg, 
						details		: details, 
						pageurl		: pageurl,
						pagetitle	: pagetitle,
						pageword	: pageword,
						prodtype 	: prodtype,
						bestprice	: bestprice,
						currency	: currency,
						priceword	: priceword
					};
					var latlngHash = (latlng.lat().toFixed(6) + "" + latlng.lng().toFixed(6));
					latlngHash = latlngHash.replace('.','').replace('.', '').replace('-','');
					if (locations[latlngHash] == null) {
					locations[latlngHash] = []
					}
				locations[latlngHash].push(residence);
				}
				for (var latlngHash in locations) {
					var residencesList = locations[latlngHash];
					regionMap.addOverlay(createMarker(residencesList));
				}
			});
			
			/* definition des classes d'icone */
			var iconresid 				= new GIcon();
			iconresid.image 			= '/img/geo/GEO_gmap-iconresid.png';
			iconresid.shadow 			= '/img/geo/GEO_gmap-iconshadow.png';
			iconresid.iconSize 			= new GSize(13,24);
			iconresid.shadowSize 		= new GSize(17,24);
			iconresid.iconAnchor 		= new GPoint(5,24);
			iconresid.infoWindowAnchor 	= new GPoint(6,12);
			
			var iconclub 				= new GIcon();
			iconclub.image 				= '/img/geo/GEO_gmap-iconclub.png';
			iconclub.shadow 			= '/img/geo/GEO_gmap-iconshadow.png';
			iconclub.iconSize 			= new GSize(13,24);
			iconclub.shadowSize 		= new GSize(17,24);
			iconclub.iconAnchor 		= new GPoint(5,24);
			iconclub.infoWindowAnchor 	= new GPoint(6,12);
			
			var iconhotel 				= new GIcon();
			iconhotel.image 			= '/img/geo/GEO_gmap-iconhotel.png';
			iconhotel.shadow 			= '/img/geo/GEO_gmap-iconshadow.png';
			iconhotel.iconSize 			= new GSize(13,24);
			iconhotel.shadowSize 		= new GSize(17,24);
			iconhotel.iconAnchor 		= new GPoint(5,24);
			iconhotel.infoWindowAnchor 	= new GPoint(6,12);
			
			var iconapart 				= new GIcon();
			iconapart.image 			= '/img/geo/GEO_gmap-iconapart.png';
			iconapart.shadow 			= '/img/geo/GEO_gmap-iconshadow.png';
			iconapart.iconSize 			= new GSize(13,24);
			iconapart.shadowSize 		= new GSize(17,24);
			iconapart.iconAnchor 		= new GPoint(5,24);
			iconapart.infoWindowAnchor 	= new GPoint(6,12);
			
			var iconairport 			= new GIcon();
			iconairport.image 			= '/img/geo/GEO_gmap-iconairport.png';
			iconairport.shadow 			= '/img/geo/GEO_gmap-iconshadow.png';
			iconairport.iconSize 		= new GSize(20,20);
			iconairport.shadowSize 		= new GSize(17,24);
			iconairport.iconAnchor 		= new GPoint(10,20);
			iconairport.infoWindowAnchor 	= new GPoint(10,10);
            
            var icongare             = new GIcon();
            icongare.image           = '/img/geo/GEO_gmap-icongare.png';
            icongare.shadow          = '/img/geo/GEO_gmap-iconshadow.png';
            icongare.iconSize        = new GSize(20,20);
            icongare.shadowSize      = new GSize(17,24);
            icongare.iconAnchor      = new GPoint(10,20);
            icongare.infoWindowAnchor    = new GPoint(10,10);
            
            var icondefault            = new GIcon();
            icondefault.image           = '/img/geo/GEO_gmap-icongare.png';
            icondefault.shadow          = '/img/geo/GEO_gmap-iconshadow.png';
            icondefault.iconSize        = new GSize(20,20);
            icondefault.shadowSize      = new GSize(17,24);
            icondefault.iconAnchor      = new GPoint(10,20);
            icondefault.infoWindowAnchor    = new GPoint(10,10);
			
			function createMarker(residencesList) {
				var residence = residencesList[0];
				var iconSelected = 'resid';
				if(residence.flag == 'village')
				{
					iconSelected = iconclub;
				}
				else if(residence.flag == 'residence')
				{
					iconSelected = iconresid;
				}
				else if(residence.flag == 'hotel')
				{
					iconSelected = iconhotel;
				}
				else if(residence.flag == 'apparthotel')
				{
					iconSelected = iconapart;
				}
				else if(residence.flag == 'airport')
				{
					iconSelected = iconairport;
                    residence.type = '';
				}
                else if(residence.flag == 'gare')
                {
                    icongare.image = residence.urlimg;
                    iconSelected = icongare;
                    residence.type = '';
                }
                else
                {
                    icondefault.image = residence.urlimg;
                    iconSelected = icondefault;
                    residence.type = '';
                }
				var marker = new GMarker(residence.latlng, {icon: iconSelected});
				var options = {
					maxTitle: 	'<em>' + residence.type + '</em> <strong>' + residence.name + '</strong>',
					maxContent: '<p style="padding: 6px 6px 6px 0;"><span class="GEOgmapPhoto" style="background-image: url(' + residence.urlimg + 
								')"><img src="img/cartouches/masque_photo-init.png" alt="'+ residence.name +'" /></span>' +
								' ' + residence.details + '</p>' +
								'<div style="clear: both; font-size: 0; width: 250px;"></div>' +
								'<p class="GEOgmapLinker"><a href="' + residence.pageurl + '" title="' + residence.pagetitle + ' ' + residence.name + 
								'" />' + residence.pageword + ' ' + residence.name + '</a></p> ' +
								'<p class="GEOgmapPricer"><span class="priceword">' + residence.priceword + '</span> <strong><span prix="' + residence.bestprice + 
								' ' + residence.currency + '">' + residence.bestprice + '&nbsp;' + residence.currency + '</span></strong>' + 
								'<span class="priceword">' + residence.prodtype + '</span></p>'						
				};
				var html = 	'<p style="margin: 0; padding: 0;"><em>' + residence.type + '</em><br /> <strong>' + residence.name + '</strong><br/> ' + residence.details + '</p>' +
							((residence.address != '') ?'<p>' + residence.address + '</p>' : '') +
							'<p><a href="' + residence.pageurl + '" title="' + residence.pagetitle + ' ' + residence.name + '" />' + residence.pagetitle + '</a></p> ';

				GEvent.addListener(marker, 'click', function() {
					if( residence.bestprice != '' ) {
						marker.openInfoWindowHtml(html, options);
					} else {
						marker.openInfoWindowHtml(html);
					}
				});
				return marker;
			}
		}
	}
}

 /* ******************************************* */
 /*   menu par onglets intÃ©rieur : afficher et masquer des divs    */
 /* ******************************************* */

function changeSrub( pilote, cible, num, nball ) { 

	var option = document.getElementById(cible+num);
	var version = navigator.appVersion;
	
	isIE = (document.all) && (version.indexOf('MSIE 8.0') == -1)
	isGek = (!isIE) && (document.getElementById)
	//alert(version.indexOf('8.0'));
	if (isIE) option = document.all[cible+num];
	if (isGek) option = document.getElementById(cible+num);
	
	for (i=0;i<=nball;i++)  { 
		if(isIE) { 
			document.all[cible+i].style.display='none';
			document.all[pilote+i].setAttribute('className','');
			
		} else {
			document.getElementById(cible+i).style.display='none';
			document.getElementById(pilote+i).setAttribute('class','');
		}
	}
	option.style.display='block';
	if(isIE) { 
		document.all[pilote+num].setAttribute('className','GEOactive');
	} else {
		document.getElementById(pilote+num).setAttribute('class','GEOactive');
	}
}

/* ***************************** */
/*    Aller chercher les galeries d'images     */
/* ***************************** */

function getGalery(num) {
		var htmlCode = '';
		var galeryContainer = document.getElementById('PRgalerie');
		var galeryImgURI = tabURI[num];
		htmlCode = '<img alt="illustration residence" src="' + galeryImgURI[0][1] + '" /><br />';
		htmlCode += '<ul>';
		for (i=0; i<galeryImgURI.length; i++) {
			htmlCode += '<li><a href="#" onClick="return false;"><img alt="illustration residence" src="' +galeryImgURI[i][0]+ '" /><span>'+
						'<img alt="illustration residence" src="' +galeryImgURI[i][1]+ '" /></span></a></li>';
		}
		htmlCode += '</ul>';
		galeryContainer.innerHTML = htmlCode;
	}
