
var oMap = Base.extend({

	staticMapOptions: {},
	polylineStaticManager: new Array(),
	polylineStaticInfo: new Array(),

	constructor: function()
	{
    	iMap = this;
    	iMap.class_name = 'oMap';
    	iMap.gmap = null;

		manager 		 = new Array();
		markerZoom		 = new Array();
		markerUnZoom 	 = new Array();

		polylineManager  = new Array();
		polylineInfo 	 = new Array();
		polylineContener = new Array();

		this.staticMapOptions = {'sensor':'false','size':'800x400','weight':'3','shadow':'true','zoom':'16'};
		this.polylineStaticManager 	= new Array();
		this.polylineStaticInfo 	= new Array();
    },

	CreateMap: function (MapCenterX, MapCenterY, Zoom, id, custom)
	{

    	if (GBrowserIsCompatible())
    	{
	    	var GoogleMapObj = document.getElementById(id);
			GoogleMap = new GMap2(GoogleMapObj);

			if(typeof(MapCenterX) == "number" && typeof(MapCenterY) == "number" && typeof(Zoom) == "number")
			{
				this.MapCenter(MapCenterX, MapCenterY, Zoom);
			}else return false;

			this.gmap = GoogleMap;
	    	if(custom=="disabled")//Map par defaut
	    	{
				GoogleMap.addControl(new GLargeMapControl());
				GoogleMap.addControl(new GMapTypeControl());
				function wheelZoom(a) {
					if ((a.detail || -a.wheelDelta) < 0)
						GoogleMap.zoomIn();
					else
						GoogleMap.zoomOut();
				}

				MapName = "NavitiaMap";
	    	}
	    	else//Map custom
	    	{
				GoogleMap.addControl(new CustomGLargeMapControl(this.gmap), new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(5,5)));
	    		GoogleMap.addControl(new CustomMapControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(5,5)));
	    	}
	    	this.overviewMap = new GOverviewMapControl();
        	GoogleMap.addControl(this.overviewMap);
	    	Geocoder = new GClientGeocoder();
	    	GoogleMap.enableDoubleClickZoom();
			GoogleMap.enableContinuousZoom();

		  	mgr = new GMarkerManager(GoogleMap);

    	}
	},

	ResizeMap: function()
	{
		this.gmap.removeControl(this.overviewMap);
    	this.gmap.checkResize();
		this.gmap.addControl(this.overviewMap);
	},

	/* Marker HTML LocalSearch */
	CustomMarkerHtml : function(marker, html, resultat)
	{
		html.innerHTML = "<br />";
		html.innerHTML += "<div class='strong'>" + resultat.titleNoFormatting + "</div>";
		html.innerHTML += "<div>" + resultat.addressLines[0] + "</div>";
		html.innerHTML += "<div>" + resultat.addressLines[1] + "</div>";
		return html;
	},

	MapCenter: function (pf_LamberX, pf_LamberY, pi_scale)
	{
      la_Result = Lamb_WGS84(pf_LamberX, pf_LamberY);
      GoogleMap.setCenter(new GLatLng(parseFloat(la_Result[1]), parseFloat(la_Result[0])), parseInt(pi_scale));
	},

	/* Construit une etiquette en fonction du nom d'arret, de ville et d'un tableau de ligne*/
	InfoContentBuilder: function(Name,CName,LineArray)
	{
		var etiquette = "<div class='info_bulle'>";
		etiquette +="<h2>"+Name;
		if(CName != "")
			etiquette += " ("+CName+")";
		etiquette +="</h2>";

		var more = false;
		if(LineArray.length > 4)
		{
			LineArray.length = 4;
			more = true;
		}

		etiquette += "<ul>";
		for(var i=0;i<LineArray.length;i++)
		{
			etiquette += "<li><span>Ligne "+LineArray[i]['LCode']+" : </span>"+LineArray[i]['LName']+"</li>";
		}
		if(more == true)
		{
			etiquette += "<li>...</li>";
		}
		etiquette += "</ul>";

		etiquette += '<p>Rechercher un itin&eacute;raire</p>';
		etiquette += '<div><a href=\"'+urlSite+'/route/vuesearch/?rappelDeparture='+encodeURIComponent(CName)+'%20-'+encodeURIComponent(Name)+'\">&Agrave; partir de cet arr&ecirc;t &raquo;</a></div>';
		etiquette += '<div><a href=\"'+urlSite+'/route/vuesearch/?rappelDestination='+encodeURIComponent(CName)+'%20-'+encodeURIComponent(Name)+'\">Vers cet arr&ecirc;t &raquo;</a></div>';
		etiquette += '<div><a href=\"'+urlSite+'/route/vueHoraire/?stopAreaLibelle='+encodeURIComponent(Name)+'&cityLibelle='+encodeURIComponent(CName)+'">Voir les horaires &agrave; cet arr&ecirc;t &raquo;</a></div>';

		etiquette += '</div>';
		delete(LineArray);
		return etiquette;
	},

	/* Bind une infobulle sur un marqueur de depart ou d'arrivee */
	InfoBindContent: function(content,id,adresse,cityName)
	{
		var etiquette = "<div class='info_bulle info-details'>";
		if(content == 'Departure')
		{
			etiquette += "<div class='info-start-flag'><h2>"+adresse+" ("+cityName+")</h2>";
			etiquette += "<p>Ce point correspond \340 votre point de d\351part.</p>";
			etiquette += "</div>";
		}
		else if(content == 'Destination')
		{
			etiquette += "<div class='info-stop-flag'><h2>"+adresse+" ("+cityName+")</h2>";
			etiquette += "<p>Ce point correspond \340 votre point d\'arriv\351e.</p>";
			etiquette += "</div>";
		}
		etiquette += '<p><a href="#" onclick="map.DeleteMarker(\''+content+'\',\''+id+'\');return false;" title="Supprimer ce point">Supprimer ce point</a></p>';
		etiquette += "</div>";
		iMap.BindInfoWindowCustom(manager[id],etiquette);
	},

	/* Cree une etiquette pour le depart arrivee laissant a l'utilisateur le choix de son point */
	InfoContentBuilderDepartureArrival: function(Link,id,adresse,cityName,codePoint)
	{
		var etiquette = "<div class='info_bulle'>";

		if(id=="error")
		{
			etiquette += "<p>Il est impossible de faire une recherche d'itin&eacute;raire &agrave; partir ou vers ce point. En dehors de la r&eacute;gion Pays de la Loire, seuls les points d'arr&ecirc;ts signal&eacute;s sur la carte sont cliquables.</p>";
		}
		else
		{
			etiquette += "<div class='info-details info-stop'><h2>"+adresse+" ("+cityName+")</h2>";
			etiquette += "<div>Rechercher un itin\351raire</div>";
			for(var i=0;i<Link.length;i++)
			{
				if(Link[i]=="Departure")
					etiquette +="<div><a title='Choisissez ce point comme d\351part' class='rouge' id='markerDepart' onclick='map.MarkerSelected(\"Departure\",\""+id+"\",\""+adresse+"\",\""+cityName+"\",\""+codePoint+"\"); return false;' href='#'>A partir de cette adresse &raquo;</a></div>";
				if(Link[i]=="Destination")
					etiquette +="<div><a title='Choisissez ce point comme destination' class='rouge' id='markerDestination' onclick='map.MarkerSelected(\"Destination\",\""+id+"\",\""+adresse+"\",\""+cityName+"\",\""+codePoint+"\"); return false;' href='#'>Vers cette adresse &raquo;</a></div>";
			}
			etiquette += "</div>";
		}
		etiquette += "</div>";
		return etiquette;
	},

	/* Fonction permettant l'affichage d'une adresse */
	ShowAddress: function(address) {
		Geocoder.getLatLng(
			address,
			function(point) {
				if (!point) {
					$('#msg_error_container').removeClass('hide')
					GoogleMap.clearOverlays() ;
				} else {
					Geocoder.getLocations(
						address,
						function(response){
							if(response || response.Status.code==200)
							{
								var detailsRes = response.Placemark[0].AddressDetails;
								address = "";
								if(detailsRes.Accuracy>=4)
								{
									address += detailsRes.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName;
									address += ", ";
									address += detailsRes.Country.CountryName;
									$('#msg_error_container').addClass('hide')
									GoogleMap.setCenter(point, 13);
									var marker = new GMarker(point);
									GoogleMap.addOverlay(marker);
									marker.openInfoWindowHtml(address);
								}
								else
								{
									$('#msg_error_container').removeClass('hide')
									GoogleMap.clearOverlays() ;
								}
							}
						}
					)

				}
			}
		)
	},


	/* Fonction gerant les deux clic de depart et d'arrivee */
	InitMarkerListener: function()
	{
		msw = new MswStreetNetwork();
		manager['X1']=iMap.CreateMarkerSelection(0,0,''); manager['X1'].hide();
		manager['X2']=iMap.CreateMarkerSelection(0,0,''); manager['X2'].hide();
		manager['error']=iMap.CreateMarkerSelection(0,0,''); manager['error'].hide();

		GEvent.addListener(GoogleMap,'click',function(overlay,latlng){

			if($('#IsClick').val() == "1")
			{
				if(latlng != null)
				{
					var lat = latlng.lat();
					var lon = latlng.lng();
					var point = new GLatLng(lat,lon);

					var iTp = new oTp();

					var result = WGS_ED50(lon,lat);

					msw.getAdressByXY(parseFloat(result[0]),parseFloat(result[1]),

						function(objet_retourne,param)
						{
							//var codePoint = typePoint+"|"+idx+"|"+adresse+"|"+cityName+"|"+result[0]+"|"+result[1];
							var codePoint = result[0]+"-"+result[1];

							var lat = latlng.lat();
							var lon = latlng.lng();
							var point = new GLatLng(lat,lon);

							if(objet_retourne.status == 'error')
							{
								manager['error'].setLatLng(point);
								manager['error'].show();
								manager['error'].openExtInfoWindow(GoogleMap,"custom_info_window",iMap.InfoContentBuilderDepartureArrival([],'error','','',codePoint));
							}
							else
							{
								var cityName = iTp.htmlentities(objet_retourne.place.city.trim());
								var adresse = iTp.htmlentities(objet_retourne.adress.trim());
								var idx = iTp.htmlentities(objet_retourne.place.idx);
								var typePoint = iTp.htmlentities(objet_retourne.place.type);

								manager['error'].hide();

								if($('#DepartureCityName').attr('rel') == 0 && $('#DestinationCityName').attr('rel') == 0 )
								{
									tab = new Array('Departure','Destination');

									manager['X1'].setLatLng(point);
									manager['X1'].show();
									manager['X1'].openExtInfoWindow(GoogleMap,"custom_info_window",iMap.InfoContentBuilderDepartureArrival(tab,'X1',adresse,cityName,codePoint));
								}
								else if($('#DepartureCityName').attr('rel') != 0 ^ $('#DestinationCityName').attr('rel') != 0 )
								{
									if($('#DepatureCityName').attr('rel') != 0)
										tab = new Array('Destination');
									if($('#DestinationCityName').attr('rel') != 0)
										tab = new Array('Departure');

									if(manager['X1'].isHidden())
									{
										manager['X1'].setLatLng(point);
										manager['X1'].show();
										manager['X1'].openExtInfoWindow(GoogleMap,"custom_info_window",iMap.InfoContentBuilderDepartureArrival(tab,'X1',adresse,cityName,codePoint));
									}
									else
									{
										manager['X2'].setLatLng(point);
										manager['X2'].show();
										manager['X2'].openExtInfoWindow(GoogleMap,"custom_info_window",iMap.InfoContentBuilderDepartureArrival(tab,'X2',adresse,cityName,codePoint));
									}
								}
							}
						},'json'
					);
				}
			}
		});
	},


	/* InitClusterMarkerListener via StopAreaExternalCode */
	InitClusterMarkerListener: function(marker,ExternalCode)
	{
		if($('#IsClick').val() == "1")
		{
			if(marker != null && ExternalCode != null)
			{
				var latlng = marker.getPoint();
				var lat = latlng.lat();
				var lon = latlng.lng();
				var point = new GLatLng(lat,lon);
				var result = WGS_ED50(lon,lat);
				var codePoint = result[0]+"-"+result[1];

				$.getJSON(urlSite+"/InfoWindow/maker",{StopAreaExternalCode:ExternalCode},
					function(data)
					{
						if(data == '')
						{
							manager['error'].setLatLng(point);
							manager['error'].show();
							manager['error'].openExtInfoWindow(GoogleMap,"custom_info_window",iMap.InfoContentBuilderDepartureArrival([],'error','','',codePoint));
						}
						else
						{

							/* InfoStoparea */
							//var Idx = "" ;
							//var Id = "";
							//var ExternalCode = "";
							var Name = "";
							//var CoordX = "";
							//var CoordY = "";

							/* InfoCity */
							//var CIdx = "";
							//var CId= "" ;
							var CName= "" ;
							//var CCityCode = "";
							//var CExternalCode = "";
							//var CCode = "";

							var k=0;
				 			//==> Parseur JSON
				 			$.each(data,function(i,item){
					 			if(i!='LineArray')
					 			{
					 				/* InfoStopAea */
					 				//Idx = item[k].Idx;
					 				//Id = item[k].Id;
					 				//ExternalCode = item[k].ExternalCode;
					 				Name = item[k].Name;
					 				//CoordX = item[k].Coord.CoordX;
					 				//CoordY = item[k].Coord.CoordY;

					 				/* InfoCity */
					 				//CIdx = item[k].City.Idx;
					 				//CId= item[k].City.Id;
					 				CName= item[k].City.Name;
					 				//CCityCode = item[k].City.CityCode;
					 				//CExternalCode = item[k].City.ExternalCode;
					 				//CCode = item[k].City.Idx;

					 			}
					 			k++;
				 			});

				 			var iTp = new oTp();
				 			var cityName = iTp.htmlentities(CName);
							var adresse = iTp.htmlentities(Name);

							manager['error'].hide();


							if($('#DepartureCityName').attr('rel') == 0 && $('#DestinationCityName').attr('rel') == 0 )
							{
								tab = new Array('Departure','Destination');

								manager['X1'].setLatLng(point);
								manager['X1'].show();
								manager['X1'].openExtInfoWindow(GoogleMap,"custom_info_window",iMap.InfoContentBuilderDepartureArrival(tab,'X1',adresse,cityName,codePoint));
							}
							else if($('#DepartureCityName').attr('rel') != 0 ^ $('#DestinationCityName').attr('rel') != 0 )
							{
								if($('#DepatureCityName').attr('rel') != 0)
									tab = new Array('Destination');
								if($('#DestinationCityName').attr('rel') != 0)
									tab = new Array('Departure');

								if(manager['X1'].isHidden())
								{
									manager['X1'].setLatLng(point);
									manager['X1'].show();
									manager['X1'].openExtInfoWindow(GoogleMap,"custom_info_window",iMap.InfoContentBuilderDepartureArrival(tab,'X1',adresse,cityName,codePoint));
								}
								else
								{
									manager['X2'].setLatLng(point);
									manager['X2'].show();
									manager['X2'].openExtInfoWindow(GoogleMap,"custom_info_window",iMap.InfoContentBuilderDepartureArrival(tab,'X2',adresse,cityName,codePoint));
								}
							}
						}
					},'json'
				);
			}
		}
	},


	MarkerSelected: function(rappelMarker,id,adresse,cityName,codePoint)
	{
		var rappelEntrypoint = '';
		if (adresse != '')
			rappelEntrypoint += adresse;
		else if (cityName != '')
			rappelEntrypoint += cityName;
		$('#'+rappelMarker+'Rappel').empty().append(rappelEntrypoint);
		$('#'+rappelMarker+'Libelle').attr('rel',$('#'+rappelMarker+'Libelle').val());
		$('#'+rappelMarker+'Libelle').val(adresse); //On remplit les champs du formulaire
		$('#'+rappelMarker+'CityName').attr('rel',$('#'+rappelMarker+'CityName').val());
		$('#'+rappelMarker+'CityName').val(cityName);
		$('#'+rappelMarker+'Selected').empty().append('<a href="#" id="'+rappelMarker+'LinkSelected" class="grisSmall" onclick="map.DeleteMarker(\''+rappelMarker+'\',\''+id+'\');return false;" title="Supprimer la s&eacute;lection">Supprimer la s&eacute;lection &raquo;</a>');

		//Et on modifie l'info bulle
		map.InfoBindContent(rappelMarker,id,adresse,cityName);

		if(rappelMarker == "Departure")
			manager[id].setImage(urlImage+'icon-start-flag.gif');
		else if(rappelMarker == "Destination")
			manager[id].setImage(urlImage+'icon-stop-flag.gif');

		manager[id].closeExtInfoWindow(GoogleMap);
		$('#'+rappelMarker).val(codePoint);

	},

	/* Efface un Marker depart arrivee */
	DeleteMarker: function(rappelMarker,id)
	{
		manager[id].closeExtInfoWindow(GoogleMap);
		manager[id].hide();
		$('#'+rappelMarker+'Rappel').empty();
		$('#'+rappelMarker+'Libelle').val($('#'+rappelMarker+'Libelle').attr('rel'));
		$('#'+rappelMarker+'Libelle').attr('rel','0');
		$('#'+rappelMarker+'CityName').val($('#'+rappelMarker+'CityName').attr('rel'));
		$('#'+rappelMarker+'CityName').attr('rel','0');
		$('#'+rappelMarker).val('');
		$('#'+rappelMarker+'LinkSelected').remove();
	},

	/* Initialise un marker */
	CreateMarkerSelection: function(CoordX,CoordY,etiquette)
	{
		var point = new GLatLng(CoordX,CoordY);
		var icon  = new GIcon();
			icon.image 			  = urlImage+'icon-stop.gif';
			icon.iconSize 		  = new GSize(16,16);
			icon.iconAnchor 	  = new GPoint(8,16);
			icon.infoWindowAnchor = new GPoint(8,0);
		var marker = new GMarker(point,{icon:icon});
		GoogleMap.addOverlay(marker);
		marker.bindInfoWindow(etiquette);
		//iMap.BindInfoWindowCustom(marker,etiquette);
		return marker;
	},

	/* PLAN DU RESEAU (CARTE INTERACTIVE) */
	GetInfoWindowPlan: function(externalCode,marker)
	{

 		//InfoStoparea
		var Idx = "" ;
		var Id = "";
		var ExternalCode = "";
		var Name = "";
		var CoordX = "";
		var CoordY = "";
		//InfoCity
		var CIdx = "";
		var CId= "" ;
		var CName= "" ;
		var CCityCode = "";
		var CExternalCode = "";
		var CCode = "";
		//InfoLines
		LineArray = new Array();
		Line = new Array();
		var LExternalCode = "";
		var LName = "";
		var LIdx = "";
		var LId= "";
		var LCode = "";
		var LNetworkExternalCode = "";
		var LNetwork = "";

 		$.getJSON(urlSite+"/InfoWindow/maker",{StopAreaExternalCode:externalCode},function(data){
 			var k=0;
 			//==> Parseur JSON
 			$.each(data,function(i,item){
	 			if(i=='LineArray')
	 			{
	 				var longueur = item.length;
	 				/* InfoLines */
	 				for(var j=0;j<longueur;j++)
	 				{
	 					LineArray[j]=new Array();
	 					LineArray[j]["LExternalCode"] = item[j].ExternalCode;
	 					LineArray[j]["LName"] = item[j].Name;
	 					LineArray[j]["LIdx"] = item[j].Idx;
	 					LineArray[j]["LId"] = item[j].Id;
	 					LineArray[j]["LCode"] = item[j].Code;
	 					LineArray[j]["LNetworkExternalCode"] = item[j].NetworkExternalCode;
	 					LineArray[j]["LNetwork"] = item[j].Network;
	 				}
	 				/**/
	 			}
	 			else
	 			{
	 				/* InfoStopAea */
	 				Idx = item[k].Idx;
	 				Id = item[k].Id;
	 				ExternalCode = item[k].ExternalCode;
	 				Name = item[k].Name;
	 				CoordX = item[k].Coord.CoordX;
	 				CoordY = item[k].Coord.CoordY;

	 				/* InfoCity */
	 				CIdx = item[k].City.Idx;
	 				CId= item[k].City.Id;
	 				CName= item[k].City.Name;
	 				CCityCode = item[k].City.CityCode;
	 				CExternalCode = item[k].City.ExternalCode;
	 				CCode = item[k].City.Idx;
	 			}
	 			k++;
 			});// ==> Fin parseur JSON
 			marker.openExtInfoWindow(GoogleMap,"custom_info_window",iMap.InfoContentBuilder(Name,CName,LineArray));
 		});
	},

	//InfoBulle VeloPlus
	VeloInfoWindowContentBuilder: function(infos)
	{
		var content = ''
		var infosTab = new Array();
		if (infos!='')
		{
			infosTab = infos.split('|');
			if(infosTab.length==3)
			{
				content += "<div class='velo_plus'>";
				var libelle = infosTab[0].split(' - ');
				content += "<div><strong>Station "+libelle[0]+"</strong></div>";
				content += "<div>Bornes disponibles : "+infosTab[1]+"</div>";
				if(infosTab[2]=='1')
					content +="<div>Terminal de paiement : oui</div>";
				else if (infosTab[2]=='0')
					content += "<div>Terminal de paiement : non</div>";
				content += "</div>";
			}
		}
		return content;
	},

	GetInfoWindowMarker: function(marker,infos)
	{
		marker.openExtInfoWindow(GoogleMap,"custom_info_window",iMap.VeloInfoWindowContentBuilder(infos));
	},

	BindInfoWindowCustom: function(marker,content)
	{
		GEvent.addListener(marker, 'click', function(){
            marker.openExtInfoWindow(
              GoogleMap,
              "custom_info_window",
              content);
          });
	},

	/* FEUILLE DE ROUTE DETAILS ITINERAIRE */
	/* Organise les markers custom avec markermanagers */
	DrawMarkerStopArea: function(detailMarker,tabToAdd)
	{
		var tab = detailMarker.split('=>');
		var type = tab[0];
		var cx   = tab[2];
		var cy   = tab[1];

		var point = new GLatLng(cx,cy);

		var icon = new GIcon();
			icon.image = this.GetImageUrl(type.toLowerCase());
			icon = this.SetIcon(icon,type.toLowerCase());

		var marker = new GMarker(point,{icon:icon});

		if(tabToAdd == "zoom" && type != "correspondance")
		{
			markerZoom.push(marker);
		}
		else if(tabToAdd == "unzoom")
		{
			markerUnZoom.push(marker);
		}
	},

	/* encode les polylines */
	DrawPolylines: function(detailPolyline)
	{
		var tab = detailPolyline.split('=>');

		var num = parseInt(tab[0]);
		var type = tab[1];
		var cx = parseFloat(tab[3]);
		var cy = parseFloat(tab[2]);

		if(polylineManager[num] == null || polylineManager[num] == undefined || polylineManager[num] == false)
		{
			polylineManager[num] = new Array();
		}

		polylineManager[num].push(new GLatLng(cx,cy));
		polylineInfo[num] = type;
	},

	DrawStaticPolylines: function(detailPolyline)
	{
		var tab = detailPolyline.split('=>');
		var num  = parseInt(tab[0]);
		var type = tab[1];

		var attributes 	= new Array();
			attributes['type'] = type;
			attributes['x'] = parseFloat(tab[3]);
			attributes['y'] = parseFloat(tab[2]);
			attributes['polylinecolor']	= this.GetModeColor(type);

		if(typeof(this.polylineStaticManager[num]) == 'undefined')
		{
			this.polylineStaticManager[num] = new Array();
		}

		this.polylineStaticManager[num].push(attributes);
		this.polylineStaticInfo[num] = type;
	},

	SetStaticMapOptions : function(options)
	{
		if(typeof(options) == 'object')
			this.staticMapOptions = options;
	},

	GetStaticMapOptions : function()
	{
		return this.staticMapOptions;
	},

	GetPolylineStaticManager : function()
	{
		return this.polylineStaticManager;
	},

	GetPolylineStaticInfo : function()
	{
		return this.polylineStaticInfo;
	},

	GetStaticMap: function(sectionId,options)
	{
		var mapUrl = '';
		var mapUrlOptions = '';
		var mapUrlPath = '';
		var mapUrlDep = '';
		var mapUrlArr = '';

		var bounds = new GLatLngBounds;

		if(typeof(this.polylineStaticManager[sectionId]) != 'object')
		{
			return false;
		}
		else
		{
			if(typeof(options) != 'object' || typeof(options) == 'undefined')
				var options = this.staticMapOptions;

			mapUrl = "http://maps.google.com/maps/api/staticmap?";
			mapUrlOptions = "sensor=" + options.sensor;
			mapUrlOptions += "&size=" + options.size;

			var poly = this.polylineStaticManager[sectionId];
			var countMax = (poly.length - 1);

			for(var i=0; i<=countMax; i++)
			{

				var path = '';

				if(i == 0)
				{
					mapUrlOptions += "&center=" + poly[i]['x'] + "," + poly[i]['y'];

					//mapUrlDep += "&markers=icon:" + encodeURI( urlRoot + this.GetImageUrl(poly[i]['type'].toLowerCase()) );
					mapUrlDep += "&markers=label:D";
					mapUrlDep += "|color:" + encodeURI( this.GetModeColor(poly[i]['type'].toLowerCase()).replace('#','0x') ) + "FF";
					mapUrlDep += "|shadow:" + options.shadow;
					mapUrlDep += "|" + poly[i]['x'] + "," + poly[i]['y'];

					mapUrlPath   += "&path=weight:" + options.weight;
					mapUrlPath   += "|color:" + encodeURI( this.GetModeColor(poly[i]['type'].toLowerCase()).replace('#','0x') ) + "FF";
				}
				else if(i == countMax)
				{
					mapUrlArr += "&markers=label:A";
					mapUrlArr += "|color:" + encodeURI( this.GetModeColor(poly[i]['type'].toLowerCase()).replace('#','0x') ) + "FF";
					mapUrlArr += "|" + poly[i]['x'] + "," + poly[i]['y'];
				}

				mapUrlPath += "|" + poly[i]['x'] + "," + poly[i]['y'];

				bounds.extend(new GLatLng(poly[i]['x'],poly[i]['y']));

			}

			mapUrlOptions += "&zoom=" + (8 + this.gmap.getBoundsZoomLevel(bounds));
			//mapUrlOptions += "&zoom=" + options.zoom;

			mapUrl += mapUrlOptions + mapUrlDep + mapUrlArr + mapUrlPath;

			return mapUrl;
		}
	},

	/* affiche les markers et les polylines */
	DrawResult: function()
	{
		var couleur;

		mgr.addMarkers(markerZoom,14,17);
		mgr.addMarkers(markerUnZoom,1,13);
		mgr.refresh();

		var polylineEncoder = new PolylineEncoder();

		for(var i=0;i<polylineManager.length;i++)
		{
			if(polylineManager[i].length>1)
			{
				var polyReturn = polylineEncoder.dpEncode(polylineManager[i]);

				couleur = this.GetModeColor(polylineInfo[i].toLowerCase());

				polylineContener[i] = new GPolyline.fromEncoded({
									color:couleur,
									weight: 3,
									opacity: 1,
									points: polyReturn.encodedPoints,
									levels: polyReturn.encodedLevels,
									zoomFactor: 2,
									numLevels: 18
									});

				GoogleMap.addOverlay(polylineContener[i]);
			}
		}
	},

	/* bind une infobulle a un marker */
	BindMarkerInfoWindow: function(detailMarker,opt)
	{
		var tab = detailMarker.split('=>');
		var indice = parseInt(tab[0]);
		var text = tab[1];

		if(opt != 'zoom')
		{
			iMap.BindInfoWindowCustom(markerUnZoom[indice],text);
		}
		else if(opt == 'zoom')
		{
			iMap.BindInfoWindowCustom(markerZoom[indice],text);
		}
	},

	GetModeColor: function(mode)
	{
		var couleur;

		if(typeof(mode) != 'string')
		{
			return false;
		}
		else
		{
			switch(mode.toLowerCase())
			{

				/* Mode avion */
				case 'avion':
					couleur="#00904D";
				break;

				/* Mode bateau */
				case 'bateau':
					couleur="#00AEEF";
				break;

				case 'navette fluviale':
					couleur="#00AEEF";
				break;

				/* Mode taxi */
				case 'taxi':
					couleur="#6E6E6E";
				break;

				/* Mode bus */
				case 'bus':
					couleur="#0072BC";
				break;

				case 'busway':
					couleur="#0072BC";
				break;

				/* Mode car */
				case 'car':
					couleur="#AE1A1F";
				break;

				case 'taxi sty':
					couleur="#AE1A1F";
				break;

				case 'car ter':
					couleur="#AE1A1F";
				break;

				/* Mode metro */
				case 'metro':
					couleur="#6E6E6E";
				break;

				case 'm&#233;tro':
					couleur="#6E6E6E";
				break;

				/* Mode rer */
				case 'rer a':
					couleur="#6E6E6E";
				break;

				case 'rer b':
					couleur="#6E6E6E";
				break;

				case 'rer c':
					couleur="#6E6E6E";
				break;

				case 'rer d':
					couleur="#6E6E6E";
				break;

				case 'rer e':
					couleur="#6E6E6E";
				break;

				/* Mode marche */
				case 'pieton':
					couleur="#E29D3F";
				break;

				/* Mode voiture */
				case 'voiture':
					couleur="#F1D249";
				break;

				/* Mode velo */
				case 'velo':
					couleur="#B1E1DB";
				break;

				case 'v&#233;lo':
					couleur="#B1E1DB";
				break;

				/* Mode tramway */
				case 'tram':
					couleur="#22B24B";
				break;

				case 'tramway':
					couleur="#22B24B";
				break;

				/* Mode train */
				default:
					couleur="#0BAC9B";
				break;
			}

			return couleur;
		}
	},

	GetImageUrl: function(type)
	{
		var urlPicto = urlImage + "pictos/";
		var imgName;

		if(typeof(type) != 'string')
		{
			return false;
		}
		else
		{
			switch(type.toLowerCase())
			{
				case 'departure':
					imgName = "marker-depart.gif";
				break;

				case 'arrival':
					imgName = "marker-arrivee.gif";
				break;

				case 'correspondance':
					imgName = "marker-correspondance.gif";
				break;

				/* Mode avion */
				case 'avion':
					imgName = "small-picto-avion.gif";
				break;

				/* Mode bateau */
				case 'bateau':
					imgName = "small-picto-bateau.gif";
				break;

				case 'navette fluviale':
					imgName = "small-picto-bateau.gif";
				break;

				/* Mode car */
				case 'taxi sty':
					imgName = "small-picto-car.gif";
				break;

				case 'car ter':
					imgName = "small-picto-car.gif";
				break;

				case 'car':
					imgName = "small-picto-car.gif";
				break;

				/* Mode bus */
				case 'bus':
					imgName = "small-picto-bus.gif";
				break;

				case 'busway':
					imgName = "small-picto-bus.gif";
				break;

				/* Mode metro */

				case 'metro':
					imgName = "small-picto-metro.gif";
				break;

				case 'm&#233;tro':
					imgName = "small-picto-metro.gif";
				break;

				/* Mode rer */
				case 'rer a':
					imgName = "small-picto-rer.gif";
				break;

				case 'rer b':
					imgName = "small-picto-rer.gif";
				break;

				case 'rer c':
					imgName = "small-picto-rer.gif";
				break;

				case 'rer d':
					imgName = "small-picto-rer.gif";
				break;

				case 'rer e':
					imgName = "small-picto-rer.gif";
				break;

				/* Mode taxi */
				case 'taxi':
					imgName = "small-picto-taxi.gif";
				break;

				/* Mode tramway */
				case 'tramway':
					imgName = "small-picto-tramway.gif";
				break;

				/* Mode Marche */
				case 'marche':
					imgName = "small-picto-marche.gif";
				break;

				case 'pieton':
					imgName = "small-picto-marche.gif";
				break;

				/* Mode velo */
				case 'velo':
					imgName = "small-picto-velo.gif";
				break;

				case 'v&#233;lo':
					imgName = "small-picto-velo.gif";
				break;

				/* Mode voiture */
				case 'voiture':
					imgName = "small-picto-voiture.gif";
				break;

				/* Mode train */
				default:
					imgName = "small-picto-train.gif";
				break;
			}

			urlPicto += imgName;

			return urlPicto;
		}
	},

	SetIcon: function(icon,type)
	{
		if(typeof(icon) != 'object' || typeof(type) != 'string')
		{
			return false;
		}
		else
		{
			switch(type.toLowerCase())
			{
				case 'departure':
					icon.iconSize = new GSize(16,16);
					icon.iconAnchor = new GPoint(8,8);
					icon.infoWindowAnchor = new GPoint(8,8);
				break;

				case 'arrival':
					icon.iconSize = new GSize(16,16);
					icon.iconAnchor = new GPoint(8,8);
					icon.infoWindowAnchor = new GPoint(8,8);
				break;

				default :
					icon.iconSize = new GSize(19,19);
					icon.iconAnchor = new GPoint(9,9);
					icon.infoWindowAnchor = new GPoint(9,9);
				break;
			}

			return icon;
		}
	}

});
