Subversion Repositories eFlore/Applications.cel

Rev

Rev 2287 | Rev 2350 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2287 Rev 2318
1
/*+--------------------------------------------------------------------------------------------------------+*/
1
/*+--------------------------------------------------------------------------------------------------------+*/
2
// PARAMÊTRES et CONSTANTES
2
// PARAMÊTRES et CONSTANTES
3
/**
3
/**
4
* Indication de certaines variables ajoutée par php
4
* Indication de certaines variables ajoutée par php
5
* var communeImageUrl ;
5
* var communeImageUrl ;
6
* var pointImageUrl ;
6
* var pointImageUrl ;
7
* var groupeImageUrlTpl ;
7
* var groupeImageUrlTpl ;
8
*/
8
*/
9
var DEBUG = false,// Mettre à true pour afficher les messages de débogage 
9
var DEBUG = false,// Mettre à true pour afficher les messages de débogage 
10
	pointsOrigine = null,
10
	pointsOrigine = null,
11
	boundsOrigine = null,
11
	boundsOrigine = null,
12
	markerClusterer = null,
12
	markerClusterer = null,
13
	map = null,
13
	map = null,
14
	infoBulle = new google.maps.InfoWindow(),
14
	infoBulle = new google.maps.InfoWindow(),
15
	stations = null,
15
	stations = null,
16
	pointClique = null,
16
	pointClique = null,
17
	carteCentre = new google.maps.LatLng(25, 10),
17
	carteCentre = new google.maps.LatLng(25, 10),
18
	carteOptions = {
18
	carteOptions = {
19
		zoom: 3,
19
		zoom: 3,
20
		center:carteCentre,
20
		center:carteCentre,
21
		mapTypeId: 'OSM',
21
		mapTypeId: 'OSM',
22
		mapTypeControlOptions: {
22
		mapTypeControlOptions: {
23
			mapTypeIds: ['OSM', 
23
			mapTypeIds: ['OSM', 
24
				google.maps.MapTypeId.ROADMAP, 
24
				google.maps.MapTypeId.ROADMAP, 
25
				google.maps.MapTypeId.HYBRID, 
25
				google.maps.MapTypeId.HYBRID, 
26
				google.maps.MapTypeId.SATELLITE, 
26
				google.maps.MapTypeId.SATELLITE, 
27
				google.maps.MapTypeId.TERRAIN]
27
				google.maps.MapTypeId.TERRAIN]
28
		},
28
		},
-
 
29
		scaleControl: true,
29
		zoomControlOptions: {
30
		zoomControlOptions: {
30
			style: google.maps.ZoomControlStyle.LARGE,
31
			style: google.maps.ZoomControlStyle.LARGE,
31
			position: google.maps.ControlPosition.LEFT_CENTER
32
			position: google.maps.ControlPosition.LEFT_CENTER
32
		},
33
		},
33
		panControl: false
34
		panControl: false
34
	},
35
	},
35
	osmMapType = new google.maps.ImageMapType({
36
	osmMapType = new google.maps.ImageMapType({
36
		getTileUrl: function(coord, zoom) {
37
		getTileUrl: function(coord, zoom) {
37
			return "http://osm.tela-botanica.org/tile/" + // cache de tuiles avec nginx
38
			return "http://osm.tela-botanica.org/tile/" + // cache de tuiles avec nginx
38
			zoom + "/" + coord.x + "/" + coord.y + ".png";
39
			zoom + "/" + coord.x + "/" + coord.y + ".png";
39
		},
40
		},
40
		tileSize: new google.maps.Size(256, 256),
41
		tileSize: new google.maps.Size(256, 256),
41
		isPng: true,
42
		isPng: true,
42
		alt: "OpenStreetMap",
43
		alt: "OpenStreetMap",
43
		name: "OSM",
44
		name: "OSM",
44
		maxZoom: 19
45
		maxZoom: 19
45
	}),
46
	}),
46
	ctaLayer = null,
47
	ctaLayer = null,
47
	pagineur = {'limite':300, 'start':0, 'total':0, 'stationId':null, 'format':'tableau'},
48
	pagineur = {'limite':300, 'start':0, 'total':0, 'stationId':null, 'format':'tableau'},
48
	station = {'commune':'', 'obsNbre':0},
49
	station = {'commune':'', 'obsNbre':0},
49
	obsStation = new Array(),
50
	obsStation = new Array(),
50
	obsPage = new Array(),
51
	obsPage = new Array(),
51
	taxonsCarte = new Array(),
52
	taxonsCarte = new Array(),
52
	mgr = null,
53
	mgr = null,
53
	marqueursCache = new Array(),
54
	marqueursCache = new Array(),
54
	zonesCache = new Array(),
55
	zonesCache = new Array(),
55
	requeteChargementPoints,
56
	requeteChargementPoints,
56
	urlVars = null;
57
	urlVars = null;
57
 
58
 
58
/*+--------------------------------------------------------------------------------------------------------+*/
59
/*+--------------------------------------------------------------------------------------------------------+*/
59
// INITIALISATION DU CODE
60
// INITIALISATION DU CODE
60
 
61
 
61
//Déclenchement d'actions quand JQuery et le document HTML sont OK
62
//Déclenchement d'actions quand JQuery et le document HTML sont OK
62
$(document).ready(function() {
63
$(document).ready(function() {
63
	initialiserWidget();
64
	initialiserWidget();
64
});
65
});
65
 
66
 
66
function initialiserWidget() {
67
function initialiserWidget() {
67
	urlVars = getUrlVars();
68
	urlVars = getUrlVars();
68
	dimensionnerCarte();
69
	dimensionnerCarte();
69
	definirTailleOverlay();
70
	definirTailleOverlay();
70
	initialiserCarte();
71
	initialiserCarte();
71
	attribuerListenersOverlay();
72
	attribuerListenersOverlay();
72
	centrerTitreEtStats();
73
	centrerTitreEtStats();
73
	initialiserAffichagePanneauLateral();
74
	initialiserAffichagePanneauLateral();
74
	initialiserGestionnaireMarqueurs()
75
	initialiserGestionnaireMarqueurs()
75
	initialiserInfoBulle();
76
	initialiserInfoBulle();
76
	initialiserFormulaireContact();
77
	initialiserFormulaireContact();
77
	chargerLimitesCommunales();
78
	chargerLimitesCommunales();
78
	attribuerListenerCarte();
79
	attribuerListenerCarte();
79
}
80
}
80
 
81
 
81
function getUrlVars() {
82
function getUrlVars() {
82
	var vars = [], hash;
83
	var vars = [], hash;
83
	if (window.location.href.indexOf('?') != -1) {
84
	if (window.location.href.indexOf('?') != -1) {
84
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
85
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
85
		for (var i = 0; i < hashes.length; i++) {
86
		for (var i = 0; i < hashes.length; i++) {
86
			hash = hashes[i].split('=');
87
			hash = hashes[i].split('=');
87
			vars.push(hash[0]);
88
			vars.push(hash[0]);
88
			vars[hash[0]] = hash[1];
89
			vars[hash[0]] = hash[1];
89
		}
90
		}
90
	}
91
	}
91
	return vars;
92
	return vars;
92
}
93
}
93
 
94
 
94
/*+--------------------------------------------------------------------------------------------------------+*/
95
/*+--------------------------------------------------------------------------------------------------------+*/
95
// AFFICHAGE GÉNÉRAL
96
// AFFICHAGE GÉNÉRAL
96
 
97
 
97
function afficherTitreCarteEtStats() {
98
function afficherTitreCarteEtStats() {
98
	if (stations != null && taxonsCarte.length > 0) {
99
	if (stations != null && taxonsCarte.length > 0) {
99
		var obsNbre = stations.stats.observations;
100
		var obsNbre = stations.stats.observations;
100
		var obsNbreFormate = obsNbre;
101
		var obsNbreFormate = obsNbre;
101
		if(obsNbre != 0) {
102
		if(obsNbre != 0) {
102
		    obsNbreFormate = stations.stats.observations.formaterNombre();
103
		    obsNbreFormate = stations.stats.observations.formaterNombre();
103
		}
104
		}
104
		var plteNbre = taxonsCarte.length;
105
		var plteNbre = taxonsCarte.length;
105
		var plteNbreFormate = plteNbre;
106
		var plteNbreFormate = plteNbre;
106
		if (plteNbre != 0) {
107
		if (plteNbre != 0) {
107
			plteNbreFormate = taxonsCarte.length.formaterNombre();
108
			plteNbreFormate = taxonsCarte.length.formaterNombre();
108
		}
109
		}
109
		var communeNbre = stations.stats.communes;
110
		var communeNbre = stations.stats.communes;
110
		var communeNbreFormate = communeNbre;
111
		var communeNbreFormate = communeNbre;
111
		if(communeNbre != 0) {
112
		if(communeNbre != 0) {
112
		   communeNbreFormate = stations.stats.communes.formaterNombre();
113
		   communeNbreFormate = stations.stats.communes.formaterNombre();
113
		}
114
		}
114
		var stationNbre = stations.stats.stations;
115
		var stationNbre = stations.stats.stations;
115
		var stationNbreFormate = stationNbre;
116
		var stationNbreFormate = stationNbre;
116
		if(stationNbre != 0) {
117
		if(stationNbre != 0) {
117
		  	stationNbreFormate = stations.stats.stations.formaterNombre();
118
		  	stationNbreFormate = stations.stats.stations.formaterNombre();
118
		}
119
		}
119
	
120
	
120
		var stats = obsNbreFormate+' observation';
121
		var stats = obsNbreFormate+' observation';
121
		stats += (obsNbre > 1) ? 's' : '' ;
122
		stats += (obsNbre > 1) ? 's' : '' ;
122
 
123
 
123
		if (photos != null && photos == 1) {
124
		if (photos != null && photos == 1) {
124
			stats += ' avec photos ';
125
			stats += ' avec photos ';
125
		}
126
		}
126
		
127
		
127
		stats += ' sur '+(stationNbre+ communeNbre)+' station';
128
		stats += ' sur '+(stationNbre+ communeNbre)+' station';
128
		stats += (stationNbre > 1) ? 's' : '' ;
129
		stats += (stationNbre > 1) ? 's' : '' ;
129
		
130
		
130
		if (nt == '*') {
131
		if (nt == '*') {
131
			stats += ' parmi '+plteNbreFormate+' plante';
132
			stats += ' parmi '+plteNbreFormate+' plante';
132
			stats += (plteNbre > 1) ? 's' : '' ;
133
			stats += (plteNbre > 1) ? 's' : '' ;
133
		} else {
134
		} else {
134
			if($('.taxon-actif .taxon').text() != '') {
135
			if($('.taxon-actif .taxon').text() != '') {
135
				var element = $('.taxon-actif .taxon').clone();
136
				var element = $('.taxon-actif .taxon').clone();
136
				element.children().remove();
137
				element.children().remove();
137
				var taxon = element.text();
138
				var taxon = element.text();
138
				stats += ' pour '+taxon;
139
				stats += ' pour '+taxon;
139
			} else {
140
			} else {
140
				if (taxonsCarte[0]) {
141
				if (taxonsCarte[0]) {
141
					var taxon = taxonsCarte[0];
142
					var taxon = taxonsCarte[0];
142
					stats += ' pour '+taxon.nom;
143
					stats += ' pour '+taxon.nom;
143
				}
144
				}
144
			}
145
			}
145
		}
146
		}
146
		
147
		
147
		if(utilisateur != '*') {
148
		if(utilisateur != '*') {
148
			stats += ' pour l\'utilisateur '+utilisateur+' ';
149
			stats += ' pour l\'utilisateur '+utilisateur+' ';
149
		}
150
		}
150
		
151
		
151
		$('#zone-stats').show();
152
		$('#zone-stats').show();
152
	} else {
153
	} else {
153
		stats = "Aucune observation pour ces critères ou pour cette zone";
154
		stats = "Aucune observation pour ces critères ou pour cette zone";
154
	}
155
	}
155
	
156
	
156
	$('#zone-stats > h1').text(stats);
157
	$('#zone-stats > h1').text(stats);
157
	centrerTitreEtStats();
158
	centrerTitreEtStats();
158
}
159
}
159
 
160
 
160
function attribuerListenersOverlay() {
161
function attribuerListenersOverlay() {
161
	$(window).resize(function() {
162
	$(window).resize(function() {
162
		dimensionnerCarte();
163
		dimensionnerCarte();
163
		definirTailleOverlay();
164
		definirTailleOverlay();
164
		centrerTitreEtStats();
165
		centrerTitreEtStats();
165
		programmerRafraichissementCarte();
166
		programmerRafraichissementCarte();
166
		google.maps.event.trigger($('#carte'), 'resize');
167
		google.maps.event.trigger($('#carte'), 'resize');
167
	});
168
	});
168
	
169
	
169
	$('#lien_plein_ecran a').click(function(event) {
170
	$('#lien_plein_ecran a').click(function(event) {
170
		window.open(window.location.href);
171
		window.open(window.location.href);
171
		event.preventDefault();
172
		event.preventDefault();
172
	});
173
	});
173
	
174
	
174
	$('#lien-voir-cc a').click(function(event) {		
175
	$('#lien-voir-cc a').click(function(event) {		
175
		ouvrirPopUp(this, 'Avertissement', event);
176
		ouvrirPopUp(this, 'Avertissement', event);
176
		event.preventDefault();
177
		event.preventDefault();
177
	});
178
	});
178
}
179
}
179
 
180
 
180
var tailleMaxFiltreUtilisateur;
181
var tailleMaxFiltreUtilisateur;
181
function definirTailleOverlay() {
182
function definirTailleOverlay() {
182
	var largeurViewPort = $(window).width(),
183
	var largeurViewPort = $(window).width(),
183
		taille = '1.6',
184
		taille = '1.6',
184
		tailleMaxLogo = 60,
185
		tailleMaxLogo = 60,
185
		tailleMaxIcones = 10,
186
		tailleMaxIcones = 10,
186
		padding_icones = 8,
187
		padding_icones = 8,
187
		tailleFiltre = 80;
188
		tailleFiltre = 80;
188
	tailleMaxFiltreUtilisateur = 350;
189
	tailleMaxFiltreUtilisateur = 350;
189
	$('#raz-filtre-utilisateur').css('display', 'block');
190
	$('#raz-filtre-utilisateur').css('display', 'block');
190
	if (largeurViewPort <= 450) {
191
	if (largeurViewPort <= 450) {
191
		taille = '1';
192
		taille = '1';
192
		tailleMaxIcones = 10;
193
		tailleMaxIcones = 10;
193
		tailleFiltre = 65;
194
		tailleFiltre = 65;
194
		padding_icones = 2;	
195
		padding_icones = 2;	
195
		var tailleMaxLogo = 50;
196
		var tailleMaxLogo = 50;
196
		$('#raz-filtre-utilisateur').css('display', 'inline');
197
		$('#raz-filtre-utilisateur').css('display', 'inline');
197
	} else if (largeurViewPort <= 500) {
198
	} else if (largeurViewPort <= 500) {
198
		taille = '1.2';
199
		taille = '1.2';
199
		tailleMaxIcones = 10;
200
		tailleMaxIcones = 10;
200
		tailleFiltre = 65;
201
		tailleFiltre = 65;
201
		padding_icones = 2;	
202
		padding_icones = 2;	
202
		var tailleMaxLogo = 50;
203
		var tailleMaxLogo = 50;
203
		tailleMaxFiltreUtilisateur = 200;
204
		tailleMaxFiltreUtilisateur = 200;
204
		$('#raz-filtre-utilisateur').css('display', 'inline');
205
		$('#raz-filtre-utilisateur').css('display', 'inline');
205
	} else if (largeurViewPort > 500 && largeurViewPort <= 800) {
206
	} else if (largeurViewPort > 500 && largeurViewPort <= 800) {
206
		taille = '1.4';
207
		taille = '1.4';
207
		tailleMaxIcones = 15;
208
		tailleMaxIcones = 15;
208
		padding_icones = 6;
209
		padding_icones = 6;
209
		tailleFiltre = 65;
210
		tailleFiltre = 65;
210
		var tailleMaxLogo = 55;
211
		var tailleMaxLogo = 55;
211
		tailleMaxFiltreUtilisateur = 250;
212
		tailleMaxFiltreUtilisateur = 250;
212
	} else if (largeurViewPort > 800) {
213
	} else if (largeurViewPort > 800) {
213
		taille = '1.6';
214
		taille = '1.6';
214
		tailleMaxIcones = 20;
215
		tailleMaxIcones = 20;
215
		padding_icones = 8;
216
		padding_icones = 8;
216
		tailleFiltre = 80;
217
		tailleFiltre = 80;
217
		tailleMaxFiltreUtilisateur = 350;
218
		tailleMaxFiltreUtilisateur = 350;
218
	}
219
	}
219
	
220
	
220
	// Aménagement de la taille de police selon l'écran
221
	// Aménagement de la taille de police selon l'écran
221
	$("#carte-titre").css('font-size', taille+'em');
222
	$("#carte-titre").css('font-size', taille+'em');
222
	
223
	
223
	$("#zone-stats h1").css('font-size', Math.round((taille*0.75*100))/100+'em');
224
	$("#zone-stats h1").css('font-size', Math.round((taille*0.75*100))/100+'em');
224
	$("#zone-stats").css('padding', padding_icones+"px "+padding_icones+"px "+Math.round(padding_icones/4)+"px");	
225
	$("#zone-stats").css('padding', padding_icones+"px "+padding_icones+"px "+Math.round(padding_icones/4)+"px");	
225
	$('#zone-stats').height(tailleMaxIcones*1.5);
226
	$('#zone-stats').height(tailleMaxIcones*1.5);
226
	
227
	
227
	$("#zone-titre h1").css('font-size', (taille)+'em');
228
	$("#zone-titre h1").css('font-size', (taille)+'em');
228
	$("#zone-titre").css('padding', padding_icones+"px "+padding_icones+"px "+Math.round(padding_icones/4)+"px");	
229
	$("#zone-titre").css('padding', padding_icones+"px "+padding_icones+"px "+Math.round(padding_icones/4)+"px");	
229
	$('#zone-titre').height(tailleMaxIcones*2);
230
	$('#zone-titre').height(tailleMaxIcones*2);
230
	
231
	
231
	$('.icone').height(tailleMaxIcones);
232
	$('.icone').height(tailleMaxIcones);
232
	$('#lien_plein_ecran').css("padding", padding_icones+"px "+padding_icones+"px "+Math.ceil(padding_icones/2)+"px");
233
	$('#lien_plein_ecran').css("padding", padding_icones+"px "+padding_icones+"px "+Math.ceil(padding_icones/2)+"px");
233
	
234
	
234
	$('#lien-voir-cc').css("font-size", taille+"em");
235
	$('#lien-voir-cc').css("font-size", taille+"em");
235
	$('#lien-voir-cc').css("padding", padding_icones+"px");
236
	$('#lien-voir-cc').css("padding", padding_icones+"px");
236
	
237
	
237
	$("#panneau-lateral").css('font-size', (taille*0.9)+'em');
238
	$("#panneau-lateral").css('font-size', (taille*0.9)+'em');
238
	$("#pl-contenu").css('font-size', (taille/2)+'em');
239
	$("#pl-contenu").css('font-size', (taille/2)+'em');
239
	
240
	
240
	$("#panneau-lateral").css('padding', padding_icones+"px "+padding_icones+"px "+Math.round(padding_icones/4)+"px");
241
	$("#panneau-lateral").css('padding', padding_icones+"px "+padding_icones+"px "+Math.round(padding_icones/4)+"px");
241
	$('#pl-ouverture').height(((padding_icones*2)+$('#panneau-lateral').height())+"px");
242
	$('#pl-ouverture').height(((padding_icones*2)+$('#panneau-lateral').height())+"px");
242
	$("#panneau-lateral").width(tailleFiltre);
243
	$("#panneau-lateral").width(tailleFiltre);
243
	
244
	
244
	$('#lien-affichage-filtre-utilisateur').width(tailleFiltre);
245
	$('#lien-affichage-filtre-utilisateur').width(tailleFiltre);
245
	$('#lien-affichage-filtre-utilisateur').height(tailleFiltre*0.35);
246
	$('#lien-affichage-filtre-utilisateur').height(tailleFiltre*0.35);
246
	$('#lien-affichage-filtre-utilisateur').css('font-size', (taille*0.9)+'em');
247
	$('#lien-affichage-filtre-utilisateur').css('font-size', (taille*0.9)+'em');
247
	$('#conteneur-filtre-utilisateur').css('max-width',tailleMaxFiltreUtilisateur);
248
	$('#conteneur-filtre-utilisateur').css('max-width',tailleMaxFiltreUtilisateur);
248
		
249
		
249
	dimensionnerLogo(tailleMaxLogo);
250
	dimensionnerLogo(tailleMaxLogo);
250
	dimensionnerImage(largeurViewPort);
251
	dimensionnerImage(largeurViewPort);
251
	redimensionnerControleTypeCarte(largeurViewPort);
252
	redimensionnerControleTypeCarte(largeurViewPort);
252
}
253
}
253
 
254
 
254
function dimensionnerLogo(tailleMaxLogo) {
255
function dimensionnerLogo(tailleMaxLogo) {
255
	// Dimensionnement du logo
256
	// Dimensionnement du logo
256
	hauteurLogo = $('.image-logo').height();
257
	hauteurLogo = $('.image-logo').height();
257
	// Redimensionnement du logo s'il est trop grand
258
	// Redimensionnement du logo s'il est trop grand
258
	// on perd en qualité mais ça vaut mieux que de casser l'affichage
259
	// on perd en qualité mais ça vaut mieux que de casser l'affichage
259
	if (hauteurLogo > tailleMaxLogo) {
260
	if (hauteurLogo > tailleMaxLogo) {
260
		hauteurLogo = tailleMaxLogo;
261
		hauteurLogo = tailleMaxLogo;
261
		$('.image-logo').css("top", "5px");
262
		$('.image-logo').css("top", "5px");
262
		$('.image-logo').height(tailleMaxLogo);
263
		$('.image-logo').height(tailleMaxLogo);
263
	}
264
	}
264
	
265
	
265
	if (hauteurLogo == 0) {
266
	if (hauteurLogo == 0) {
266
		$('.image-logo').load(function(event) {
267
		$('.image-logo').load(function(event) {
267
			definirTailleOverlay();
268
			definirTailleOverlay();
268
		});
269
		});
269
		return;
270
		return;
270
	}
271
	}
271
	
272
	
272
	largeurLogo = $('#logo img').width();
273
	largeurLogo = $('#logo img').width();
273
}
274
}
274
 
275
 
275
function dimensionnerImage(largeurViewPort) {
276
function dimensionnerImage(largeurViewPort) {
276
	// Dimensionnement de l'image
277
	// Dimensionnement de l'image
277
	if (largeurViewPort > 500) {
278
	if (largeurViewPort > 500) {
278
		largeurLogo = 155;
279
		largeurLogo = 155;
279
	} else {
280
	} else {
280
		largeurLogo = 70;
281
		largeurLogo = 70;
281
	}
282
	}
282
	
283
	
283
	$('#image-utilisateur img').width(largeurLogo);
284
	$('#image-utilisateur img').width(largeurLogo);
284
}
285
}
285
 
286
 
286
function redimensionnerControleTypeCarte(largeurViewPort) {
287
function redimensionnerControleTypeCarte(largeurViewPort) {
287
	if (largeurViewPort <= 500) {
288
	if (largeurViewPort <= 500) {
288
		carteOptions.mapTypeControlOptions.style = google.maps.MapTypeControlStyle.DROPDOWN_MENU;
289
		carteOptions.mapTypeControlOptions.style = google.maps.MapTypeControlStyle.DROPDOWN_MENU;
289
	} else {
290
	} else {
290
		carteOptions.mapTypeControlOptions.style = google.maps.MapTypeControlStyle.DEFAULT;
291
		carteOptions.mapTypeControlOptions.style = google.maps.MapTypeControlStyle.DEFAULT;
291
	}
292
	}
292
	
293
	
293
	if (map != null) {	
294
	if (map != null) {	
294
		map.setOptions(carteOptions);
295
		map.setOptions(carteOptions);
295
	}
296
	}
296
}
297
}
297
 
298
 
298
function centrerTitreEtStats() {
299
function centrerTitreEtStats() {
299
	centrerTitre();
300
	centrerTitre();
300
	centrerStats();
301
	centrerStats();
301
}
302
}
302
 
303
 
303
function centrerTitre() {
304
function centrerTitre() {
304
	var largeurViewPort = $(window).width(),
305
	var largeurViewPort = $(window).width(),
305
		largeurTitre = $('#zone-titre').width(),
306
		largeurTitre = $('#zone-titre').width(),
306
		marge = (largeurViewPort - largeurTitre)/2;
307
		marge = (largeurViewPort - largeurTitre)/2;
307
	$('#zone-titre').css("margin-left",marge);
308
	$('#zone-titre').css("margin-left",marge);
308
	
309
	
309
	var tailleRestante = largeurViewPort - (marge + largeurTitre);
310
	var tailleRestante = largeurViewPort - (marge + largeurTitre);
310
	if (tailleRestante <= 170) {
311
	if (tailleRestante <= 170) {
311
		$('#zone-titre').css("top", "25px");
312
		$('#zone-titre').css("top", "25px");
312
	} else {
313
	} else {
313
		$('#zone-titre').css("top", "5px");
314
		$('#zone-titre').css("top", "5px");
314
	}
315
	}
315
}
316
}
316
 
317
 
317
function centrerStats() {
318
function centrerStats() {
318
	var largeurViewPort = $(window).width(),
319
	var largeurViewPort = $(window).width(),
319
		largeurStats = $('#zone-stats').width(),
320
		largeurStats = $('#zone-stats').width(),
320
		marge = ((largeurViewPort - largeurStats)/2);
321
		marge = ((largeurViewPort - largeurStats)/2);
321
	$('#zone-stats').css("margin-left",marge);
322
	$('#zone-stats').css("margin-left",marge);
322
}
323
}
323
 
324
 
324
/*+--------------------------------------------------------------------------------------------------------+*/
325
/*+--------------------------------------------------------------------------------------------------------+*/
325
// CARTE
326
// CARTE
326
 
327
 
327
function dimensionnerCarte() {
328
function dimensionnerCarte() {
328
	var largeurViewPort = $(window).width();
329
	var largeurViewPort = $(window).width();
329
	var hauteurViewPort = $(window).height();
330
	var hauteurViewPort = $(window).height();
330
	$('#carte').height(hauteurViewPort);
331
	$('#carte').height(hauteurViewPort);
331
	$('#carte').width(largeurViewPort);
332
	$('#carte').width(largeurViewPort);
332
}
333
}
333
 
334
 
334
function initialiserCarte() {
335
function initialiserCarte() {
335
	map = new google.maps.Map(document.getElementById('carte'), carteOptions);
336
	map = new google.maps.Map(document.getElementById('carte'), carteOptions);
336
	// Ajout de la couche OSM à la carte
337
	// Ajout de la couche OSM à la carte
337
	map.mapTypes.set('OSM', osmMapType);
338
	map.mapTypes.set('OSM', osmMapType);
-
 
339
 
-
 
340
	// écouteur sur changement de fond
-
 
341
	google.maps.event.addListener( map, 'maptypeid_changed', function() { 
-
 
342
		// licence par défaut
-
 
343
		var mention = 'Observations du réseau <a href="http://www.tela-botanica.org/site:botanique" ' +
-
 
344
				'onClick="ouvrirNouvelleFenetre(this, event)">' +
-
 
345
				'Tela Botanica' +
-
 
346
			'</a> ';
-
 
347
		if (map.getMapTypeId() == 'OSM') {
-
 
348
			// ajout licence OSM
-
 
349
			mention += ' - Carte : <a href="http://www.openstreetmap.org/copyright" target="_blank">© les contributeurs d’OpenStreetMap</a>' +
-
 
350
				' - Tuiles : <a href="http://www.openstreetmap.fr" target="_blank">OsmFr</a>';
-
 
351
		}
-
 
352
		$('#origine-donnees').html(mention);
-
 
353
	});
338
}
354
}
339
 
355
 
340
function initialiserGestionnaireMarqueurs() {
356
function initialiserGestionnaireMarqueurs() {
341
	mgr = new MarkerManager(map);
357
	mgr = new MarkerManager(map);
342
}
358
}
343
 
359
 
344
function chargerLimitesCommunales() {
360
function chargerLimitesCommunales() {
345
	if (urlsLimitesCommunales != null) {
361
	if (urlsLimitesCommunales != null) {
346
		for (urlId in urlsLimitesCommunales) { 
362
		for (urlId in urlsLimitesCommunales) { 
347
			var url = urlsLimitesCommunales[urlId];
363
			var url = urlsLimitesCommunales[urlId];
348
			ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: true});
364
			ctaLayer = new google.maps.KmlLayer(url, {preserveViewport: true});
349
			ctaLayer.setMap(map);
365
			ctaLayer.setMap(map);
350
		}
366
		}
351
	}
367
	}
352
}
368
}
353
 
369
 
354
var listener = null,
370
var listener = null,
355
	timer = null;
371
	timer = null;
356
 
372
 
357
function attribuerListenerCarte() {
373
function attribuerListenerCarte() {
358
	listener = google.maps.event.addListener(map, 'bounds_changed', function(){
374
	listener = google.maps.event.addListener(map, 'bounds_changed', function(){
359
		programmerRafraichissementCarte();
375
		programmerRafraichissementCarte();
360
	});
376
	});
361
	listener = google.maps.event.addListener(map, 'zoom_changed', function(){
377
	listener = google.maps.event.addListener(map, 'zoom_changed', function(){
362
		programmerRafraichissementCarte();
378
		programmerRafraichissementCarte();
363
	});
379
	});
364
}
380
}
365
 
381
 
366
function programmerRafraichissementCarte() {
382
function programmerRafraichissementCarte() {
367
	if (timer != null) {
383
	if (timer != null) {
368
		window.clearTimeout(timer);
384
		window.clearTimeout(timer);
369
	}
385
	}
370
	if (requeteChargementPoints != null) {
386
	if (requeteChargementPoints != null) {
371
		requeteChargementPoints.abort();
387
		requeteChargementPoints.abort();
372
	}
388
	}
373
	timer = window.setTimeout(function() {
389
	timer = window.setTimeout(function() {
374
		if (map.getBounds() != undefined) {
390
		if (map.getBounds() != undefined) {
375
			var zoom = map.getZoom(),
391
			var zoom = map.getZoom(),
376
				lngNE = map.getBounds().getNorthEast().lng(),
392
				lngNE = map.getBounds().getNorthEast().lng(),
377
				lngSW = map.getBounds().getSouthWest().lng()
393
				lngSW = map.getBounds().getSouthWest().lng()
378
			if (map.getBounds().getNorthEast().lng() < map.getBounds().getSouthWest().lng()) {
394
			if (map.getBounds().getNorthEast().lng() < map.getBounds().getSouthWest().lng()) {
379
				lngNE = 176;
395
				lngNE = 176;
380
				lngSW = -156;
396
				lngSW = -156;
381
			}
397
			}
382
			var NELatLng = (map.getBounds().getNorthEast().lat())+'|'+(lngNE),
398
			var NELatLng = (map.getBounds().getNorthEast().lat())+'|'+(lngNE),
383
				SWLatLng = (map.getBounds().getSouthWest().lat())+'|'+(lngSW);
399
				SWLatLng = (map.getBounds().getSouthWest().lat())+'|'+(lngSW);
384
			chargerMarqueurs(zoom, NELatLng, SWLatLng);
400
			chargerMarqueurs(zoom, NELatLng, SWLatLng);
385
		} else {
401
		} else {
386
			programmerRafraichissementCarte();
402
			programmerRafraichissementCarte();
387
		}
403
		}
388
	}, 400);
404
	}, 400);
389
}
405
}
390
 
406
 
391
var marqueurs = new Array();
407
var marqueurs = new Array();
392
function chargerMarqueurs(zoom, NELatLng, SWLatLng) {
408
function chargerMarqueurs(zoom, NELatLng, SWLatLng) {
393
	cacherMessageAucuneObs();
409
	cacherMessageAucuneObs();
394
	var url = stationsUrl+
410
	var url = stationsUrl+
395
		'&zoom='+zoom+
411
		'&zoom='+zoom+
396
		'&ne='+NELatLng+
412
		'&ne='+NELatLng+
397
		'&sw='+SWLatLng;
413
		'&sw='+SWLatLng;
398
	
414
	
399
	if (infoBulleOuverte) {
415
	if (infoBulleOuverte) {
400
		return;
416
		return;
401
	}
417
	}
402
	
418
	
403
	if (requeteChargementPoints != null) {
419
	if (requeteChargementPoints != null) {
404
		requeteChargementPoints.abort();
420
		requeteChargementPoints.abort();
405
		cacherMessageChargementPoints();
421
		cacherMessageChargementPoints();
406
	}
422
	}
407
	
423
	
408
	afficherMessageChargementPoints();
424
	afficherMessageChargementPoints();
409
	requeteChargementPoints = $.getJSON(url, function(data) {
425
	requeteChargementPoints = $.getJSON(url, function(data) {
410
		rafraichirMarqueurs(data);
426
		rafraichirMarqueurs(data);
411
		cacherMessageChargementPoints();
427
		cacherMessageChargementPoints();
412
	});
428
	});
413
}
429
}
414
 
430
 
415
function centrerDansLaPage(selecteur) {
431
function centrerDansLaPage(selecteur) {
416
	var largeurViewport = $(window).width(),
432
	var largeurViewport = $(window).width(),
417
		hauteurViewport = $(window).height();
433
		hauteurViewport = $(window).height();
418
	selecteur.css('display','block');
434
	selecteur.css('display','block');
419
	var left = (largeurViewport/2) - (selecteur.width())/2,
435
	var left = (largeurViewport/2) - (selecteur.width())/2,
420
		top = (hauteurViewport/2) - (selecteur.height())/2
436
		top = (hauteurViewport/2) - (selecteur.height())/2
421
	selecteur.css('left',left);
437
	selecteur.css('left',left);
422
	selecteur.css('top',top);
438
	selecteur.css('top',top);
423
}
439
}
424
 
440
 
425
function afficherMessageChargementPoints() {
441
function afficherMessageChargementPoints() {
426
	centrerDansLaPage($('#zone-chargement-point'));
442
	centrerDansLaPage($('#zone-chargement-point'));
427
	$('#zone-chargement-point').css('display','block');
443
	$('#zone-chargement-point').css('display','block');
428
}
444
}
429
 
445
 
430
function cacherMessageChargementPoints() {
446
function cacherMessageChargementPoints() {
431
	$('#zone-chargement-point').css('display','none');
447
	$('#zone-chargement-point').css('display','none');
432
}
448
}
433
 
449
 
434
function afficherMessageAucuneObs() {
450
function afficherMessageAucuneObs() {
435
	centrerDansLaPage($('#message-aucune-obs'));
451
	centrerDansLaPage($('#message-aucune-obs'));
436
	$('#message-aucune-obs').show();
452
	$('#message-aucune-obs').show();
437
}
453
}
438
 
454
 
439
function cacherMessageAucuneObs() {
455
function cacherMessageAucuneObs() {
440
	centrerDansLaPage($('#message-aucune-obs'));
456
	centrerDansLaPage($('#message-aucune-obs'));
441
	$('#message-aucune-obs').hide();
457
	$('#message-aucune-obs').hide();
442
}
458
}
443
 
459
 
444
premierChargement = true;
460
premierChargement = true;
445
function doitCentrerCarte() {
461
function doitCentrerCarte() {
446
	return premierChargement && urlVars != null && urlVars.length > 0;
462
	return premierChargement && urlVars != null && urlVars.length > 0;
447
}
463
}
448
 
464
 
449
function rafraichirMarqueurs(data) {
465
function rafraichirMarqueurs(data) {
450
	$.each(marqueurs, function(index, marqueur) {
466
	$.each(marqueurs, function(index, marqueur) {
451
		marqueur.setMap(null);
467
		marqueur.setMap(null);
452
	});
468
	});
453
 
469
 
454
	marqueurs = new Array();
470
	marqueurs = new Array();
455
	stations = null;
471
	stations = null;
456
	
472
	
457
	if (data.points.length > 0) {
473
	if (data.points.length > 0) {
458
		marqueurs = new Array();
474
		marqueurs = new Array();
459
		stations = data;
475
		stations = data;
460
		
476
		
461
		$.each(stations.points, function (index, station) {		
477
		$.each(stations.points, function (index, station) {		
462
			if(station != null) {
478
			if(station != null) {
463
				var nouveauMarqueur = creerMarqueur(station);
479
				var nouveauMarqueur = creerMarqueur(station);
464
				marqueurs.push(nouveauMarqueur);
480
				marqueurs.push(nouveauMarqueur);
465
			}
481
			}
466
		});
482
		});
467
		
483
		
468
		if (doitCentrerCarte()) {
484
		if (doitCentrerCarte()) {
469
			premierChargement = false;
485
			premierChargement = false;
470
			var bounds = new google.maps.LatLngBounds(),
486
			var bounds = new google.maps.LatLngBounds(),
471
				latMax = new google.maps.LatLng(data.stats.coordmax.latMax, data.stats.coordmax.lngMax),
487
				latMax = new google.maps.LatLng(data.stats.coordmax.latMax, data.stats.coordmax.lngMax),
472
				latMin = new google.maps.LatLng(data.stats.coordmax.latMin, data.stats.coordmax.lngMin);
488
				latMin = new google.maps.LatLng(data.stats.coordmax.latMin, data.stats.coordmax.lngMin);
473
			bounds.extend(latMax);
489
			bounds.extend(latMax);
474
			bounds.extend(latMin);
490
			bounds.extend(latMin);
475
			rendrePointsVisibles(bounds);	
491
			rendrePointsVisibles(bounds);	
476
		}
492
		}
477
	}
493
	}
478
	
494
	
479
	afficherTitreCarteEtStats();
495
	afficherTitreCarteEtStats();
480
}
496
}
481
 
497
 
482
function creerMarqueur(station) {
498
function creerMarqueur(station) {
483
	var titre = '';
499
	var titre = '';
484
	if (station.nbreMarqueur) {
500
	if (station.nbreMarqueur) {
485
		titre = station.nbreMarqueur+' points renseignés';
501
		titre = station.nbreMarqueur+' points renseignés';
486
	} else {
502
	} else {
487
		if(station.nom) {
503
		if(station.nom) {
488
			titre = station.nom;
504
			titre = station.nom;
489
		}
505
		}
490
	}
506
	}
491
	
507
	
492
	var icone = attribuerImageMarqueur(station['id'], station['nbreMarqueur']),
508
	var icone = attribuerImageMarqueur(station['id'], station['nbreMarqueur']),
493
		latLng = new google.maps.LatLng(station['lat'], station['lng']),
509
		latLng = new google.maps.LatLng(station['lat'], station['lng']),
494
			marqueur = new google.maps.Marker({
510
			marqueur = new google.maps.Marker({
495
				position: latLng,
511
				position: latLng,
496
				icon: icone,
512
				icon: icone,
497
				title: ''+titre,
513
				title: ''+titre,
498
				map: map,
514
				map: map,
499
				stationInfos: station
515
				stationInfos: station
500
			});
516
			});
501
	attribuerListenerClick(marqueur, station['id']);
517
	attribuerListenerClick(marqueur, station['id']);
502
	marqueur.setMap(map);
518
	marqueur.setMap(map);
503
	return marqueur;
519
	return marqueur;
504
}
520
}
505
 
521
 
506
function rendrePointsVisibles(bounds) {
522
function rendrePointsVisibles(bounds) {
507
	map.setCenter(bounds.getCenter());
523
	map.setCenter(bounds.getCenter());
508
	map.fitBounds(bounds);
524
	map.fitBounds(bounds);
509
}
525
}
510
 
526
 
511
function attribuerImageMarqueur(id, nbreMarqueur) {
527
function attribuerImageMarqueur(id, nbreMarqueur) {
512
	var marqueurImage = null;
528
	var marqueurImage = null;
513
	if (etreMarqueurCommune(id)) {
529
	if (etreMarqueurCommune(id)) {
514
		marqueurImage = new google.maps.MarkerImage(communeImageUrl, new google.maps.Size(24, 32));
530
		marqueurImage = new google.maps.MarkerImage(communeImageUrl, new google.maps.Size(24, 32));
515
	} else if (etreMarqueurStation(id)) {
531
	} else if (etreMarqueurStation(id)) {
516
		marqueurImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(16, 16));
532
		marqueurImage = new google.maps.MarkerImage(pointImageUrl, new google.maps.Size(16, 16));
517
	} else if (etreMarqueurGroupe(id)) {
533
	} else if (etreMarqueurGroupe(id)) {
518
		var type = 0,
534
		var type = 0,
519
			largeur = 0,
535
			largeur = 0,
520
			hauteur = 0;
536
			hauteur = 0;
521
		if (nbreMarqueur != null) {
537
		if (nbreMarqueur != null) {
522
			if (nbreMarqueur >= 2 && nbreMarqueur < 100 ) {
538
			if (nbreMarqueur >= 2 && nbreMarqueur < 100 ) {
523
				type = '1';
539
				type = '1';
524
				largeur = 53;
540
				largeur = 53;
525
				hauteur = 52;
541
				hauteur = 52;
526
			} else if (nbreMarqueur >= 100 && nbreMarqueur < 1000 ) {
542
			} else if (nbreMarqueur >= 100 && nbreMarqueur < 1000 ) {
527
				type = '2';
543
				type = '2';
528
				largeur = 56;
544
				largeur = 56;
529
				hauteur = 55;
545
				hauteur = 55;
530
			} else if (nbreMarqueur >= 1000 && nbreMarqueur < 10000 ) {
546
			} else if (nbreMarqueur >= 1000 && nbreMarqueur < 10000 ) {
531
				type = '3';
547
				type = '3';
532
				largeur = 66;
548
				largeur = 66;
533
				hauteur = 65;
549
				hauteur = 65;
534
			} else if (nbreMarqueur >= 10000 && nbreMarqueur < 20000 ) {
550
			} else if (nbreMarqueur >= 10000 && nbreMarqueur < 20000 ) {
535
				type = '4';
551
				type = '4';
536
				largeur = 78;
552
				largeur = 78;
537
				hauteur = 77;
553
				hauteur = 77;
538
			} else if (nbreMarqueur >= 20000) {
554
			} else if (nbreMarqueur >= 20000) {
539
				type = '5';
555
				type = '5';
540
				largeur = 66;
556
				largeur = 66;
541
				hauteur = 65;
557
				hauteur = 65;
542
			}
558
			}
543
		}
559
		}
544
		groupeImageUrl = groupeImageUrlTpl.replace(/\{type\}/, type);
560
		groupeImageUrl = groupeImageUrlTpl.replace(/\{type\}/, type);
545
		groupeImageUrl = groupeImageUrl.replace(/\{nbre\}/, nbreMarqueur);
561
		groupeImageUrl = groupeImageUrl.replace(/\{nbre\}/, nbreMarqueur);
546
		marqueurImage = new google.maps.MarkerImage(groupeImageUrl, new google.maps.Size(largeur, hauteur));
562
		marqueurImage = new google.maps.MarkerImage(groupeImageUrl, new google.maps.Size(largeur, hauteur));
547
	}
563
	}
548
	return marqueurImage
564
	return marqueurImage
549
}
565
}
550
 
566
 
551
function attribuerListenerClick(marqueur, id) {
567
function attribuerListenerClick(marqueur, id) {
552
	if (etreMarqueurCommune(id) || etreMarqueurStation(id)) {
568
	if (etreMarqueurCommune(id) || etreMarqueurStation(id)) {
553
		google.maps.event.addListener(marqueur, 'click', surClickMarqueur);
569
		google.maps.event.addListener(marqueur, 'click', surClickMarqueur);
554
	} else if (etreMarqueurGroupe(id)) {
570
	} else if (etreMarqueurGroupe(id)) {
555
		google.maps.event.addListener(marqueur, 'click', surClickGroupe);
571
		google.maps.event.addListener(marqueur, 'click', surClickGroupe);
556
	}
572
	}
557
}
573
}
558
 
574
 
559
var pointCentreAvantAffichageInfoBulle = null;
575
var pointCentreAvantAffichageInfoBulle = null;
560
function surClickMarqueur(event) {
576
function surClickMarqueur(event) {
561
	pointCentreAvantAffichageInfoBulle = map.getCenter();
577
	pointCentreAvantAffichageInfoBulle = map.getCenter();
562
 
578
 
563
	if(infoBulleOuverte) {
579
	if(infoBulleOuverte) {
564
		infoBulle.close();
580
		infoBulle.close();
565
	}
581
	}
566
 
582
 
567
	pointClique = this;
583
	pointClique = this;
568
	infoBulle.open(map, this);
584
	infoBulle.open(map, this);
569
	actualiserPagineur();
585
	actualiserPagineur();
570
 
586
 
571
	var limites = map.getBounds(),
587
	var limites = map.getBounds(),
572
		centre = limites.getCenter(),
588
		centre = limites.getCenter(),
573
		nordEst = limites.getNorthEast(),
589
		nordEst = limites.getNorthEast(),
574
		centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
590
		centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
575
	map.panTo(centreSudLatLng);
591
	map.panTo(centreSudLatLng);
576
	
592
	
577
	afficherInfoBulle();
593
	afficherInfoBulle();
578
}
594
}
579
 
595
 
580
function surClickGroupe() {
596
function surClickGroupe() {
581
	map.setCenter(this.getPosition());
597
	map.setCenter(this.getPosition());
582
	var nouveauZoom = map.getZoom() + 2;
598
	var nouveauZoom = map.getZoom() + 2;
583
	map.setZoom(nouveauZoom);
599
	map.setZoom(nouveauZoom);
584
	mgr.clearMarkers();
600
	mgr.clearMarkers();
585
}
601
}
586
 
602
 
587
function etreMarqueurGroupe(id) {
603
function etreMarqueurGroupe(id) {
588
	var groupe = false,
604
	var groupe = false,
589
		motif = /^GROUPE/;
605
		motif = /^GROUPE/;
590
	if (motif.test(id)) {
606
	if (motif.test(id)) {
591
		groupe = true;
607
		groupe = true;
592
	}
608
	}
593
	return groupe;
609
	return groupe;
594
}
610
}
595
 
611
 
596
function etreMarqueurCommune(id) {
612
function etreMarqueurCommune(id) {
597
	var commune = false,
613
	var commune = false,
598
		motif = /^COMMUNE:/;
614
		motif = /^COMMUNE:/;
599
	if (motif.test(id)) {
615
	if (motif.test(id)) {
600
		commune = true;
616
		commune = true;
601
	}
617
	}
602
	return commune;
618
	return commune;
603
}
619
}
604
 
620
 
605
function etreMarqueurStation(id) {
621
function etreMarqueurStation(id) {
606
	var station = false,
622
	var station = false,
607
		motif = /^STATION:/;
623
		motif = /^STATION:/;
608
	if (motif.test(id)) {
624
	if (motif.test(id)) {
609
		station = true;
625
		station = true;
610
	}
626
	}
611
	return station;
627
	return station;
612
}
628
}
613
 
629
 
614
function deplacerCarteSurPointClique() {
630
function deplacerCarteSurPointClique() {
615
	map.panTo(pointClique.position);
631
	map.panTo(pointClique.position);
616
}
632
}
617
 
633
 
618
/*+--------------------------------------------------------------------------------------------------------+*/
634
/*+--------------------------------------------------------------------------------------------------------+*/
619
// INFO BULLE
635
// INFO BULLE
620
var infoBulleOuverte = false;
636
var infoBulleOuverte = false;
621
function initialiserInfoBulle() {
637
function initialiserInfoBulle() {
622
	google.maps.event.addListener(infoBulle, 'domready', initialiserContenuInfoBulle);
638
	google.maps.event.addListener(infoBulle, 'domready', initialiserContenuInfoBulle);
623
	google.maps.event.addListener(infoBulle, 'closeclick', surFermetureInfoBulle);
639
	google.maps.event.addListener(infoBulle, 'closeclick', surFermetureInfoBulle);
624
	google.maps.event.addListener(infoBulle, 'content_changed', definirLargeurInfoBulle);
640
	google.maps.event.addListener(infoBulle, 'content_changed', definirLargeurInfoBulle);
625
	attribuerListenerLienSaisie();
641
	attribuerListenerLienSaisie();
626
}
642
}
627
 
643
 
628
function attribuerListenerLienSaisie() {
644
function attribuerListenerLienSaisie() {
629
	$('.lien-widget-saisie').live('click', function(event) {
645
	$('.lien-widget-saisie').live('click', function(event) {
630
		event.preventDefault();
646
		event.preventDefault();
631
		window.open($(this).attr('href'), '_blank');
647
		window.open($(this).attr('href'), '_blank');
632
		return false;
648
		return false;
633
	});
649
	});
634
}
650
}
635
 
651
 
636
function surFermetureInfoBulle() {
652
function surFermetureInfoBulle() {
637
	infoBulleOuverte = false;
653
	infoBulleOuverte = false;
638
	map.panTo(pointCentreAvantAffichageInfoBulle);
654
	map.panTo(pointCentreAvantAffichageInfoBulle);
639
	programmerRafraichissementCarte();
655
	programmerRafraichissementCarte();
640
}
656
}
641
 
657
 
642
function centrerInfoBulle() {
658
function centrerInfoBulle() {
643
	var limites = map.getBounds(),
659
	var limites = map.getBounds(),
644
		centre = limites.getCenter(),
660
		centre = limites.getCenter(),
645
		nordEst = limites.getNorthEast(),
661
		nordEst = limites.getNorthEast(),
646
		centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
662
		centreSudLatLng = new google.maps.LatLng(nordEst.lat(), centre.lng());
647
	map.panTo(centreSudLatLng);
663
	map.panTo(centreSudLatLng);
648
}
664
}
649
 
665
 
650
function afficherInfoBulle() {
666
function afficherInfoBulle() {
651
	var obsHtml = $('#tpl-obs').html(),
667
	var obsHtml = $('#tpl-obs').html(),
652
		largeur = definirLargeurInfoBulle(),
668
		largeur = definirLargeurInfoBulle(),
653
		taillePolice = definirTaillePoliceInfoBulle();
669
		taillePolice = definirTaillePoliceInfoBulle();
654
	obsHtml = obsHtml.replace(/\{largeur\}/, largeur);
670
	obsHtml = obsHtml.replace(/\{largeur\}/, largeur);
655
	infoBulle.setContent(obsHtml);
671
	infoBulle.setContent(obsHtml);
656
	$('#observations').css('font-size', taillePolice + 'em');
672
	$('#observations').css('font-size', taillePolice + 'em');
657
	chargerObs(0, 0);
673
	chargerObs(0, 0);
658
	infoBulleOuverte = true;
674
	infoBulleOuverte = true;
659
}
675
}
660
 
676
 
661
//TODO utiliser cette fonction lors des remplacements de 
677
//TODO utiliser cette fonction lors des remplacements de 
662
//paramètres url sur changement de filtre
678
//paramètres url sur changement de filtre
663
function parserFiltre(filtre) {
679
function parserFiltre(filtre) {
664
	var nvpair = {},
680
	var nvpair = {},
665
		qs = filtre.replace('?', ''),
681
		qs = filtre.replace('?', ''),
666
		pairs = qs.split('&');
682
		pairs = qs.split('&');
667
	$.each(pairs, function(i, v){
683
	$.each(pairs, function(i, v){
668
		var pair = v.split('=');
684
		var pair = v.split('=');
669
		nvpair[pair[0]] = pair[1];
685
		nvpair[pair[0]] = pair[1];
670
	});
686
	});
671
	return nvpair;
687
	return nvpair;
672
}
688
}
673
 
689
 
674
function mettreAJourUrlSaisie(obs) {
690
function mettreAJourUrlSaisie(obs) {
675
	if (obs.observations.length > 0) {
691
	if (obs.observations.length > 0) {
676
		var filtreTableau = parserFiltre(filtreCommun),
692
		var filtreTableau = parserFiltre(filtreCommun),
677
			filtresGardes = new Array()
693
			filtresGardes = new Array()
678
			idObs = obs.observations[0].idObs;
694
			idObs = obs.observations[0].idObs;
679
		filtre = '';
695
		filtre = '';
680
		for (i in filtreTableau) {
696
		for (i in filtreTableau) {
681
			if (filtreTableau[i] != undefined && filtreTableau[i] != '' && decodeURIComponent(filtreTableau[i]) != '*') {
697
			if (filtreTableau[i] != undefined && filtreTableau[i] != '' && decodeURIComponent(filtreTableau[i]) != '*') {
682
				console.log(i + '  ' + filtreTableau[i]);
698
				console.log(i + '  ' + filtreTableau[i]);
683
				filtresGardes.push(i + '=' + filtreTableau[i]);
699
				filtresGardes.push(i + '=' + filtreTableau[i]);
684
			}
700
			}
685
		}
701
		}
686
		filtresGardes.push('id-obs=' + idObs);
702
		filtresGardes.push('id-obs=' + idObs);
687
		if (filtresGardes.length > 0) {
703
		if (filtresGardes.length > 0) {
688
			filtre = '?' + filtresGardes.join('&');
704
			filtre = '?' + filtresGardes.join('&');
689
		}
705
		}
690
		var urlAvecFiltre = urlWidgetSaisie + filtre;
706
		var urlAvecFiltre = urlWidgetSaisie + filtre;
691
		$('.lien-widget-saisie').attr('href', urlAvecFiltre).parents('.conteneur-lien-saisie').show();
707
		$('.lien-widget-saisie').attr('href', urlAvecFiltre).parents('.conteneur-lien-saisie').show();
692
	}
708
	}
693
}
709
}
694
 
710
 
695
function definirLargeurInfoBulle() {
711
function definirLargeurInfoBulle() {
696
	var largeurViewPort = $(window).width(),
712
	var largeurViewPort = $(window).width(),
697
		largeurInfoBulle = null;
713
		largeurInfoBulle = null;
698
	if (largeurViewPort < 400) {
714
	if (largeurViewPort < 400) {
699
		largeurInfoBulle = 300;
715
		largeurInfoBulle = 300;
700
	} else if (largeurViewPort < 800) {
716
	} else if (largeurViewPort < 800) {
701
		largeurInfoBulle = 400;
717
		largeurInfoBulle = 400;
702
	} else if (largeurViewPort >= 800 && largeurViewPort < 1200) {
718
	} else if (largeurViewPort >= 800 && largeurViewPort < 1200) {
703
		largeurInfoBulle = 500;
719
		largeurInfoBulle = 500;
704
	} else if (largeurViewPort >= 1200) {
720
	} else if (largeurViewPort >= 1200) {
705
		largeurInfoBulle = 600;
721
		largeurInfoBulle = 600;
706
	}
722
	}
707
	return largeurInfoBulle;
723
	return largeurInfoBulle;
708
}
724
}
709
 
725
 
710
function definirTaillePoliceInfoBulle() {
726
function definirTaillePoliceInfoBulle() {
711
	var largeurViewPort = $(window).width(),
727
	var largeurViewPort = $(window).width(),
712
		taillePolice = null;
728
		taillePolice = null;
713
	if (largeurViewPort < 400) {
729
	if (largeurViewPort < 400) {
714
		taillePolice = 0.8;
730
		taillePolice = 0.8;
715
	} else if (largeurViewPort < 800) {
731
	} else if (largeurViewPort < 800) {
716
		taillePolice = 1;
732
		taillePolice = 1;
717
	}
733
	}
718
	return taillePolice;
734
	return taillePolice;
719
}
735
}
720
 
736
 
721
function afficherMessageChargement(element) {
737
function afficherMessageChargement(element) {
722
	if ($('#chargement').get() == '') {
738
	if ($('#chargement').get() == '') {
723
		$('#tpl-chargement').tmpl().appendTo(element);
739
		$('#tpl-chargement').tmpl().appendTo(element);
724
	}
740
	}
725
}
741
}
726
 
742
 
727
function afficherMessageChargementTitreInfoBulle() {
743
function afficherMessageChargementTitreInfoBulle() {
728
	$("#obs-station-titre").text("Chargement des observations");	
744
	$("#obs-station-titre").text("Chargement des observations");	
729
}
745
}
730
 
746
 
731
function supprimerMessageChargement() {
747
function supprimerMessageChargement() {
732
	$('#chargement').remove();
748
	$('#chargement').remove();
733
}
749
}
734
 
750
 
735
function chargerObs(depart, total) {
751
function chargerObs(depart, total) {
736
	if (depart == 0 || depart < total) {
752
	if (depart == 0 || depart < total) {
737
		var limite = 300;
753
		var limite = 300;
738
		if (depart == 0) {
754
		if (depart == 0) {
739
			viderTableauObs();
755
			viderTableauObs();
740
		}
756
		}
741
		
757
		
742
		var urlObs = observationsUrl+'&start={start}&limit='+limite;
758
		var urlObs = observationsUrl+'&start={start}&limit='+limite;
743
		urlObs = urlObs.replace(/\{stationId\}/g, encodeURIComponent(pointClique.stationInfos.id));
759
		urlObs = urlObs.replace(/\{stationId\}/g, encodeURIComponent(pointClique.stationInfos.id));
744
		if (pointClique.stationInfos.type_emplacement == 'communes') {
760
		if (pointClique.stationInfos.type_emplacement == 'communes') {
745
			urlObs = urlObs.replace(/commune=%2A/g, formaterParametreCommunePourRequete(pointClique.stationInfos.nom));
761
			urlObs = urlObs.replace(/commune=%2A/g, formaterParametreCommunePourRequete(pointClique.stationInfos.nom));
746
		}
762
		}
747
		// Ajout de la zone geo
763
		// Ajout de la zone geo
748
		if (pointClique.stationInfos.zonegeo) {
764
		if (pointClique.stationInfos.zonegeo) {
749
			urlObs += '&zonegeo=' + pointClique.stationInfos.zonegeo;
765
			urlObs += '&zonegeo=' + pointClique.stationInfos.zonegeo;
750
		}
766
		}
751
 
767
 
752
		urlObs = urlObs.replace(/\{nt\}/g, nt);
768
		urlObs = urlObs.replace(/\{nt\}/g, nt);
753
		urlObs = urlObs.replace(/\{start\}/g, depart);
769
		urlObs = urlObs.replace(/\{start\}/g, depart);
754
		
770
		
755
		$.getJSON(urlObs, function(observations){
771
		$.getJSON(urlObs, function(observations){
756
			surRetourChargementObs(observations, depart, total);
772
			surRetourChargementObs(observations, depart, total);
757
			chargerObs(depart+limite, observations.total);
773
			chargerObs(depart+limite, observations.total);
758
		});
774
		});
759
	}
775
	}
760
}
776
}
761
 
777
 
762
function formaterParametreCommunePourRequete(nomCommune) {
778
function formaterParametreCommunePourRequete(nomCommune) {
763
	var chaineRequete = "";
779
	var chaineRequete = "";
764
	if(nomCommune.indexOf("(", 0) !== false) {
780
	if(nomCommune.indexOf("(", 0) !== false) {
765
		var infosCommune = nomCommune.split("(");
781
		var infosCommune = nomCommune.split("(");
766
		var commune = infosCommune[0];
782
		var commune = infosCommune[0];
767
		chaineRequete = 'commune='+encodeURIComponent($.trim(commune));
783
		chaineRequete = 'commune='+encodeURIComponent($.trim(commune));
768
	} else {
784
	} else {
769
		chaineRequete = 'commune='+encodeURIComponent($.trim(nomCommune));
785
		chaineRequete = 'commune='+encodeURIComponent($.trim(nomCommune));
770
	}
786
	}
771
	return chaineRequete;
787
	return chaineRequete;
772
}
788
}
773
 
789
 
774
function viderTableauObs() {
790
function viderTableauObs() {
775
	obsStation = new Array();	
791
	obsStation = new Array();	
776
	surClicPagePagination(0, null);
792
	surClicPagePagination(0, null);
777
}
793
}
778
 
794
 
779
function surRetourChargementObs(observations, depart, total) {
795
function surRetourChargementObs(observations, depart, total) {
780
	obsStation = obsStation.concat(observations.observations);
796
	obsStation = obsStation.concat(observations.observations);
781
	if (depart == 0) {
797
	if (depart == 0) {
782
		actualiserInfosStation(observations);
798
		actualiserInfosStation(observations);
783
		creerTitreInfoBulle();
799
		creerTitreInfoBulle();
784
		surClicPagePagination(0, null);
800
		surClicPagePagination(0, null);
785
		console.log(observations);
801
		console.log(observations);
786
		mettreAJourUrlSaisie(observations);
802
		mettreAJourUrlSaisie(observations);
787
	}
803
	}
788
	
804
	
789
	afficherPagination();
805
	afficherPagination();
790
	actualiserPagineur();
806
	actualiserPagineur();
791
	selectionnerOnglet("#obs-vue-"+pagineur.format);
807
	selectionnerOnglet("#obs-vue-"+pagineur.format);
792
}
808
}
793
 
809
 
794
function actualiserInfosStation(infos) {
810
function actualiserInfosStation(infos) {
795
	pointClique.stationInfos.commune = infos.commune;
811
	pointClique.stationInfos.commune = infos.commune;
796
	pointClique.stationInfos.obsNbre = infos.total;
812
	pointClique.stationInfos.obsNbre = infos.total;
797
}
813
}
798
 
814
 
799
function creerTitreInfoBulle() {
815
function creerTitreInfoBulle() {
800
	$('#obs-total').text(station.obsNbre);
816
	$('#obs-total').text(station.obsNbre);
801
	$('#obs-commune').text(station.commune);
817
	$('#obs-commune').text(station.commune);
802
	var titre = '';
818
	var titre = '';
803
	titre += pointClique.stationInfos.obsNbre+' observation';
819
	titre += pointClique.stationInfos.obsNbre+' observation';
804
	titre += (pointClique.stationInfos.obsNbre > 1) ? 's': '' ;
820
	titre += (pointClique.stationInfos.obsNbre > 1) ? 's': '' ;
805
	titre += ' pour ';
821
	titre += ' pour ';
806
	if (etreMarqueurCommune(pointClique.stationInfos.id)) {
822
	if (etreMarqueurCommune(pointClique.stationInfos.id)) {
807
		nomStation = 'la commune : ';
823
		nomStation = 'la commune : ';
808
	} else {
824
	} else {
809
		nomStation = 'la station : ';
825
		nomStation = 'la station : ';
810
	}
826
	}
811
	titre += pointClique.stationInfos.nom;
827
	titre += pointClique.stationInfos.nom;
812
	$('#obs-station-titre').text(titre);	
828
	$('#obs-station-titre').text(titre);	
813
}
829
}
814
 
830
 
815
function actualiserPagineur() {
831
function actualiserPagineur() {
816
	pagineur.stationId = pointClique.stationInfos.id;
832
	pagineur.stationId = pointClique.stationInfos.id;
817
	pagineur.total = pointClique.stationInfos.obsNbre;
833
	pagineur.total = pointClique.stationInfos.obsNbre;
818
	// Si on est en mode photo on reste en mode liste quelque soit le 
834
	// Si on est en mode photo on reste en mode liste quelque soit le 
819
	// nombre de résultats
835
	// nombre de résultats
820
	if (pagineur.total > 4 && photos != 1) {
836
	if (pagineur.total > 4 && photos != 1) {
821
		pagineur.format = 'tableau';
837
		pagineur.format = 'tableau';
822
	} else {
838
	} else {
823
		pagineur.format = 'liste';
839
		pagineur.format = 'liste';
824
	}
840
	}
825
}
841
}
826
 
842
 
827
function afficherPagination(observations) {
843
function afficherPagination(observations) {
828
	$('.navigation').pagination(pagineur.total, {
844
	$('.navigation').pagination(pagineur.total, {
829
		items_per_page:pagineur.limite,
845
		items_per_page:pagineur.limite,
830
		callback:surClicPagePagination,
846
		callback:surClicPagePagination,
831
		next_text:'Suivant',
847
		next_text:'Suivant',
832
		prev_text:'Précédent',
848
		prev_text:'Précédent',
833
		prev_show_always:false,
849
		prev_show_always:false,
834
		num_edge_entries:1,
850
		num_edge_entries:1,
835
		num_display_entries:4,
851
		num_display_entries:4,
836
		load_first_page:true
852
		load_first_page:true
837
	});
853
	});
838
}
854
}
839
 
855
 
840
function surClicPagePagination(pageIndex, paginationConteneur) {
856
function surClicPagePagination(pageIndex, paginationConteneur) {
841
	var index = pageIndex * pagineur.limite,
857
	var index = pageIndex * pagineur.limite,
842
		indexMax = index + pagineur.limite;
858
		indexMax = index + pagineur.limite;
843
	pagineur.depart = index;
859
	pagineur.depart = index;
844
	obsPage = new Array();
860
	obsPage = new Array();
845
	for (index; index < indexMax; index++) {
861
	for (index; index < indexMax; index++) {
846
		obsPage.push(obsStation[index]);
862
		obsPage.push(obsStation[index]);
847
	}
863
	}
848
 
864
 
849
	supprimerMessageChargement();
865
	supprimerMessageChargement();
850
	mettreAJourObservations();
866
	mettreAJourObservations();
851
	return false;
867
	return false;
852
}
868
}
853
 
869
 
854
function mettreAJourObservations() {
870
function mettreAJourObservations() {
855
	$('#obs-'+pagineur.format+'-lignes').empty();
871
	$('#obs-'+pagineur.format+'-lignes').empty();
856
	$('#obs-vue-'+pagineur.format).css('display', 'block');
872
	$('#obs-vue-'+pagineur.format).css('display', 'block');
857
	$('.obs-conteneur').css('counter-reset', 'item '+pagineur.depart);
873
	$('.obs-conteneur').css('counter-reset', 'item '+pagineur.depart);
858
	$('#tpl-obs-'+pagineur.format).tmpl(obsPage).appendTo('#obs-'+pagineur.format+'-lignes');
874
	$('#tpl-obs-'+pagineur.format).tmpl(obsPage).appendTo('#obs-'+pagineur.format+'-lignes');
859
	
875
	
860
	// Actualisation de Fancybox
876
	// Actualisation de Fancybox
861
	ajouterFormulaireContact('a.contact');
877
	ajouterFormulaireContact('a.contact');
862
	if (pagineur.format == 'liste') {
878
	if (pagineur.format == 'liste') {
863
		ajouterGaleriePhoto('a.cel-img');
879
		ajouterGaleriePhoto('a.cel-img');
864
	}
880
	}
865
}
881
}
866
 
882
 
867
function initialiserContenuInfoBulle() {
883
function initialiserContenuInfoBulle() {
868
	afficherMessageChargement('#observations');
884
	afficherMessageChargement('#observations');
869
	cacherContenuOnglets();
885
	cacherContenuOnglets();
870
	afficherOnglets();
886
	afficherOnglets();
871
	ajouterTableauTriable('#obs-tableau');
887
	ajouterTableauTriable('#obs-tableau');
872
	afficherTextStationId();
888
	afficherTextStationId();
873
	corrigerLargeurInfoWindow();
889
	corrigerLargeurInfoWindow();
874
}
890
}
875
 
891
 
876
function cacherContenuOnglets() {
892
function cacherContenuOnglets() {
877
	$('#obs-vue-tableau').css('display', 'none');
893
	$('#obs-vue-tableau').css('display', 'none');
878
	$('#obs-vue-liste').css('display', 'none');
894
	$('#obs-vue-liste').css('display', 'none');
879
}
895
}
880
 
896
 
881
function afficherOnglets() {
897
function afficherOnglets() {
882
	var $tabs = $('#obs').tabs();
898
	var $tabs = $('#obs').tabs();
883
	$('#obs').bind('tabsselect', function(event, ui) {
899
	$('#obs').bind('tabsselect', function(event, ui) {
884
		if (ui.panel.id == 'obs-vue-tableau') {
900
		if (ui.panel.id == 'obs-vue-tableau') {
885
			surClicAffichageTableau();
901
			surClicAffichageTableau();
886
		} else if (ui.panel.id == 'obs-vue-liste') {
902
		} else if (ui.panel.id == 'obs-vue-liste') {
887
			surClicAffichageListe();
903
			surClicAffichageListe();
888
		}
904
		}
889
	});
905
	});
890
	if (pointClique.stationInfos.nbre > 4) {
906
	if (pointClique.stationInfos.nbre > 4) {
891
		$tabs.tabs('select', "#obs-vue-tableau");
907
		$tabs.tabs('select', "#obs-vue-tableau");
892
	} else {
908
	} else {
893
		$tabs.tabs('select', "#obs-vue-liste");
909
		$tabs.tabs('select', "#obs-vue-liste");
894
	}
910
	}
895
	
911
	
896
}
912
}
897
 
913
 
898
function selectionnerOnglet(onglet) {
914
function selectionnerOnglet(onglet) {
899
	$(onglet).css('display', 'block');
915
	$(onglet).css('display', 'block');
900
	$('#obs').tabs('select', onglet);
916
	$('#obs').tabs('select', onglet);
901
}
917
}
902
 
918
 
903
function afficherTextStationId() {
919
function afficherTextStationId() {
904
	$('#obs-station-id').text(pointClique.stationInfos.id);
920
	$('#obs-station-id').text(pointClique.stationInfos.id);
905
}
921
}
906
 
922
 
907
function corrigerLargeurInfoWindow() {
923
function corrigerLargeurInfoWindow() {
908
	$("#info-bulle").width($("#info-bulle").width() - 17);
924
	$("#info-bulle").width($("#info-bulle").width() - 17);
909
}
925
}
910
 
926
 
911
function surClicAffichageTableau(event) {
927
function surClicAffichageTableau(event) {
912
	pagineur.format = 'tableau';
928
	pagineur.format = 'tableau';
913
	mettreAJourObservations();
929
	mettreAJourObservations();
914
	mettreAJourTableauTriable("#obs-tableau");
930
	mettreAJourTableauTriable("#obs-tableau");
915
}
931
}
916
 
932
 
917
function surClicAffichageListe(event) {
933
function surClicAffichageListe(event) {
918
	pagineur.format = 'liste';
934
	pagineur.format = 'liste';
919
	mettreAJourObservations();
935
	mettreAJourObservations();
920
	ajouterGaleriePhoto("a.cel-img");
936
	ajouterGaleriePhoto("a.cel-img");
921
}
937
}
922
 
938
 
923
function ajouterTableauTriable(element) {
939
function ajouterTableauTriable(element) {
924
	// add parser through the tablesorter addParser method 
940
	// add parser through the tablesorter addParser method 
925
	$.tablesorter.addParser({ 
941
	$.tablesorter.addParser({ 
926
		// Définition d'un id unique pour ce parsseur 
942
		// Définition d'un id unique pour ce parsseur 
927
		id: 'date_cel', 
943
		id: 'date_cel', 
928
		is: function(s) { 
944
		is: function(s) { 
929
			// doit retourner false si le parsseur n'est pas autodétecté
945
			// doit retourner false si le parsseur n'est pas autodétecté
930
			return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s);
946
			return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s);
931
		}, 
947
		}, 
932
		format: function(date) { 
948
		format: function(date) { 
933
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
949
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
934
			date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3/$2/$1");
950
			date = date.replace(/^\s*(\d{2})[\/-](\d{2})[\/-](\d{4})\s*$/, "$3/$2/$1");
935
			// Remplace la date par un nombre de millisecondes pour trier numériquement
951
			// Remplace la date par un nombre de millisecondes pour trier numériquement
936
			return $.tablesorter.formatFloat(new Date(date).getTime());
952
			return $.tablesorter.formatFloat(new Date(date).getTime());
937
		}, 
953
		}, 
938
		// set type, either numeric or text 
954
		// set type, either numeric or text 
939
		type: 'numeric' 
955
		type: 'numeric' 
940
	});
956
	});
941
	$(element).tablesorter({ 
957
	$(element).tablesorter({ 
942
		headers: { 
958
		headers: { 
943
			1: { 
959
			1: { 
944
				sorter: 'date_cel' 
960
				sorter: 'date_cel' 
945
			} 
961
			} 
946
		}
962
		}
947
	});
963
	});
948
}
964
}
949
 
965
 
950
function mettreAJourTableauTriable(element) {
966
function mettreAJourTableauTriable(element) {
951
	$(element).trigger('update');
967
	$(element).trigger('update');
952
}
968
}
953
 
969
 
954
function ajouterGaleriePhoto(element) {
970
function ajouterGaleriePhoto(element) {
955
	$(element).fancybox({
971
	$(element).fancybox({
956
		transitionIn: 'elastic',
972
		transitionIn: 'elastic',
957
		transitionOut: 'elastic',
973
		transitionOut: 'elastic',
958
		speedIn: 600, 
974
		speedIn: 600, 
959
		speedOut: 200,
975
		speedOut: 200,
960
		overlayShow: true,
976
		overlayShow: true,
961
		titleShow: true,
977
		titleShow: true,
962
		titlePosition: 'inside',
978
		titlePosition: 'inside',
963
		titleFormat: function (titre, currentArray, currentIndex, currentOpts) {
979
		titleFormat: function (titre, currentArray, currentIndex, currentOpts) {
964
			var motif = /urn:lsid:tela-botanica[.]org:cel:img([0-9]+)$/;
980
			var motif = /urn:lsid:tela-botanica[.]org:cel:img([0-9]+)$/;
965
			motif.exec(titre);
981
			motif.exec(titre);
966
			var id = RegExp.$1,
982
			var id = RegExp.$1,
967
				info = $('#cel-info-'+id).clone().html(),
983
				info = $('#cel-info-'+id).clone().html(),
968
				tpl = 
984
				tpl = 
969
					'<div class="cel-legende">'+
985
					'<div class="cel-legende">'+
970
					'<p class="cel-legende-vei">'+'Image n°' + (currentIndex + 1) + ' sur ' + currentArray.length +'<\/p>'+	
986
					'<p class="cel-legende-vei">'+'Image n°' + (currentIndex + 1) + ' sur ' + currentArray.length +'<\/p>'+	
971
					(titre && titre.length ? '<p>'+info+'<\/p>' : '' )+
987
					(titre && titre.length ? '<p>'+info+'<\/p>' : '' )+
972
					'<\/div>';
988
					'<\/div>';
973
			return tpl;
989
			return tpl;
974
		}
990
		}
975
	}).live('click', function(e) {
991
	}).live('click', function(e) {
976
		if (e.stopPropagation) {
992
		if (e.stopPropagation) {
977
			e.stopPropagation();
993
			e.stopPropagation();
978
		}
994
		}
979
		return false;
995
		return false;
980
	});
996
	});
981
}
997
}
982
 
998
 
983
function ajouterFormulaireContact(element) {
999
function ajouterFormulaireContact(element) {
984
	$(element).fancybox({
1000
	$(element).fancybox({
985
		transitionIn:'elastic',
1001
		transitionIn:'elastic',
986
		transitionOut:'elastic',
1002
		transitionOut:'elastic',
987
		speedIn	:600, 
1003
		speedIn	:600, 
988
		speedOut:200,
1004
		speedOut:200,
989
		scrolling: 'no',
1005
		scrolling: 'no',
990
		titleShow: false,
1006
		titleShow: false,
991
		onStart: function(selectedArray, selectedIndex, selectedOpts) {
1007
		onStart: function(selectedArray, selectedIndex, selectedOpts) {
992
			var element = selectedArray[selectedIndex];
1008
			var element = selectedArray[selectedIndex];
993
			var motif = / contributeur-([0-9]+)$/;
1009
			var motif = / contributeur-([0-9]+)$/;
994
			motif.exec($(element).attr('class'));
1010
			motif.exec($(element).attr('class'));
995
			// si la classe ne contient pas d'id contributeur
1011
			// si la classe ne contient pas d'id contributeur
996
			// alors il faut stocker le numéro d'observation
1012
			// alors il faut stocker le numéro d'observation
997
			var id = RegExp.$1;
1013
			var id = RegExp.$1;
998
			if(id == "") {
1014
			if(id == "") {
999
				$("#fc_type_envoi").attr('value', 'non-inscrit');
1015
				$("#fc_type_envoi").attr('value', 'non-inscrit');
1000
				var motif = / obs-([0-9]+)$/;
1016
				var motif = / obs-([0-9]+)$/;
1001
				motif.exec($(element).attr('class'));
1017
				motif.exec($(element).attr('class'));
1002
				var id = RegExp.$1;
1018
				var id = RegExp.$1;
1003
			} else {
1019
			} else {
1004
				$("#fc_type_envoi").attr('value', 'inscrit');
1020
				$("#fc_type_envoi").attr('value', 'inscrit');
1005
			}
1021
			}
1006
 
1022
 
1007
			$("#fc_destinataire_id").attr('value', id);
1023
			$("#fc_destinataire_id").attr('value', id);
1008
		
1024
		
1009
			var motif = / obs-([0-9]+)/;
1025
			var motif = / obs-([0-9]+)/;
1010
			motif.exec($(element).attr('class'));
1026
			motif.exec($(element).attr('class'));
1011
			var id = RegExp.$1;
1027
			var id = RegExp.$1;
1012
			//console.log('Obs id : '+id);
1028
			//console.log('Obs id : '+id);
1013
			chargerInfoObsPourMessage(id);
1029
			chargerInfoObsPourMessage(id);
1014
		},
1030
		},
1015
		onCleanup: function() {
1031
		onCleanup: function() {
1016
			//console.log('Avant fermeture fancybox');
1032
			//console.log('Avant fermeture fancybox');
1017
			$("#fc_destinataire_id").attr('value', '');
1033
			$("#fc_destinataire_id").attr('value', '');
1018
			$("#fc_sujet").attr('value', '');
1034
			$("#fc_sujet").attr('value', '');
1019
			$("#fc_message").text('');
1035
			$("#fc_message").text('');
1020
		},
1036
		},
1021
		onClosed: function(e) {
1037
		onClosed: function(e) {
1022
			//console.log('Fermeture fancybox');
1038
			//console.log('Fermeture fancybox');
1023
			if (e.stopPropagation) {
1039
			if (e.stopPropagation) {
1024
				e.stopPropagation();
1040
				e.stopPropagation();
1025
			}
1041
			}
1026
			return false;
1042
			return false;
1027
		}
1043
		}
1028
	});
1044
	});
1029
}
1045
}
1030
 
1046
 
1031
function chargerInfoObsPourMessage(idObs) {
1047
function chargerInfoObsPourMessage(idObs) {
1032
	var nomSci = jQuery.trim($(".cel-obs-"+idObs+" .nom-sci:eq(0)").text());
1048
	var nomSci = jQuery.trim($(".cel-obs-"+idObs+" .nom-sci:eq(0)").text());
1033
	var date = jQuery.trim($(".cel-obs-"+idObs+" .date:eq(0)").text());
1049
	var date = jQuery.trim($(".cel-obs-"+idObs+" .date:eq(0)").text());
1034
	var lieu = jQuery.trim($(".cel-obs-"+idObs+" .lieu:eq(0)").text());
1050
	var lieu = jQuery.trim($(".cel-obs-"+idObs+" .lieu:eq(0)").text());
1035
	var sujet = "Observation #"+idObs+" de "+nomSci;
1051
	var sujet = "Observation #"+idObs+" de "+nomSci;
1036
	var message = "\n\n\n\n\n\n\n\n--\nConcerne l'observation de \""+nomSci+'" du "'+date+'" au lieu "'+lieu+'".';
1052
	var message = "\n\n\n\n\n\n\n\n--\nConcerne l'observation de \""+nomSci+'" du "'+date+'" au lieu "'+lieu+'".';
1037
	$("#fc_sujet").attr('value', sujet);
1053
	$("#fc_sujet").attr('value', sujet);
1038
	$("#fc_message").text(message);
1054
	$("#fc_message").text(message);
1039
}
1055
}
1040
 
1056
 
1041
function initialiserFormulaireContact() {
1057
function initialiserFormulaireContact() {
1042
	//console.log('Initialisation du form contact');
1058
	//console.log('Initialisation du form contact');
1043
	$("#form-contact").validate({
1059
	$("#form-contact").validate({
1044
		rules: {
1060
		rules: {
1045
			fc_sujet : "required",
1061
			fc_sujet : "required",
1046
			fc_message : "required",
1062
			fc_message : "required",
1047
			fc_utilisateur_courriel : {
1063
			fc_utilisateur_courriel : {
1048
				required : true,
1064
				required : true,
1049
				email : true}
1065
				email : true}
1050
		}
1066
		}
1051
	});
1067
	});
1052
	$("#form-contact").bind("submit", envoyerCourriel);
1068
	$("#form-contact").bind("submit", envoyerCourriel);
1053
	$("#fc_annuler").bind("click", function() {$.fancybox.close();});
1069
	$("#fc_annuler").bind("click", function() {$.fancybox.close();});
1054
	
1070
	
1055
}
1071
}
1056
 
1072
 
1057
function envoyerCourriel() {
1073
function envoyerCourriel() {
1058
	//console.log('Formulaire soumis');
1074
	//console.log('Formulaire soumis');
1059
	if ($("#form-contact").valid()) {
1075
	if ($("#form-contact").valid()) {
1060
		//console.log('Formulaire valide');
1076
		//console.log('Formulaire valide');
1061
		//$.fancybox.showActivity();
1077
		//$.fancybox.showActivity();
1062
		var destinataireId = $("#fc_destinataire_id").attr('value');
1078
		var destinataireId = $("#fc_destinataire_id").attr('value');
1063
		var typeEnvoi = $("#fc_type_envoi").attr('value');
1079
		var typeEnvoi = $("#fc_type_envoi").attr('value');
1064
		if(typeEnvoi == "non-inscrit") {
1080
		if(typeEnvoi == "non-inscrit") {
1065
			// l'envoi au non inscrits passe par le service intermédiaire du cel
1081
			// l'envoi au non inscrits passe par le service intermédiaire du cel
1066
			// qui va récupérer le courriel associé à l'obs indiquée
1082
			// qui va récupérer le courriel associé à l'obs indiquée
1067
			var urlMessage = "http://www.tela-botanica.org/service:cel:celMessage/obs/"+destinataireId;
1083
			var urlMessage = "http://www.tela-botanica.org/service:cel:celMessage/obs/"+destinataireId;
1068
		} else {
1084
		} else {
1069
			var urlMessage = "http://www.tela-botanica.org/service:annuaire:Utilisateur/"+destinataireId+"/message";
1085
			var urlMessage = "http://www.tela-botanica.org/service:annuaire:Utilisateur/"+destinataireId+"/message";
1070
		}
1086
		}
1071
		var erreurMsg = "";
1087
		var erreurMsg = "";
1072
		var donnees = new Array();
1088
		var donnees = new Array();
1073
		$.each($(this).serializeArray(), function (index, champ) {
1089
		$.each($(this).serializeArray(), function (index, champ) {
1074
			var cle = champ.name;
1090
			var cle = champ.name;
1075
			cle = cle.replace(/^fc_/, '');
1091
			cle = cle.replace(/^fc_/, '');
1076
			
1092
			
1077
			if (cle == 'sujet') {
1093
			if (cle == 'sujet') {
1078
				champ.value += " - Carnet en ligne - Tela Botanica";
1094
				champ.value += " - Carnet en ligne - Tela Botanica";
1079
			}
1095
			}
1080
			if (cle == 'message') {
1096
			if (cle == 'message') {
1081
				champ.value += "\n--\n"+
1097
				champ.value += "\n--\n"+
1082
					"Ce message vous est envoyé par l'intermédiaire du widget carto "+
1098
					"Ce message vous est envoyé par l'intermédiaire du widget carto "+
1083
					"du Carnet en Ligne du réseau Tela Botanica.\n"+
1099
					"du Carnet en Ligne du réseau Tela Botanica.\n"+
1084
					"http://www.tela-botanica.org/widget:cel:carto";
1100
					"http://www.tela-botanica.org/widget:cel:carto";
1085
			}
1101
			}
1086
			
1102
			
1087
			donnees[index] = {'name':cle,'value':champ.value};
1103
			donnees[index] = {'name':cle,'value':champ.value};
1088
		});
1104
		});
1089
		$.ajax({
1105
		$.ajax({
1090
			type : "POST",
1106
			type : "POST",
1091
			cache : false,
1107
			cache : false,
1092
			url : urlMessage,
1108
			url : urlMessage,
1093
			data : donnees,
1109
			data : donnees,
1094
			beforeSend : function() {
1110
			beforeSend : function() {
1095
				$(".msg").remove();
1111
				$(".msg").remove();
1096
			},
1112
			},
1097
			success : function(data) {
1113
			success : function(data) {
1098
				$("#fc-zone-dialogue").append('<pre class="msg info">'+data.message+'</pre>');
1114
				$("#fc-zone-dialogue").append('<pre class="msg info">'+data.message+'</pre>');
1099
			},
1115
			},
1100
			error : function(jqXHR, textStatus, errorThrown) {
1116
			error : function(jqXHR, textStatus, errorThrown) {
1101
				erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
1117
				erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
1102
				reponse = jQuery.parseJSON(jqXHR.responseText);
1118
				reponse = jQuery.parseJSON(jqXHR.responseText);
1103
				if (reponse != null) {
1119
				if (reponse != null) {
1104
					$.each(reponse, function (cle, valeur) {
1120
					$.each(reponse, function (cle, valeur) {
1105
						erreurMsg += valeur + "\n";
1121
						erreurMsg += valeur + "\n";
1106
					});
1122
					});
1107
				}				
1123
				}				
1108
			},
1124
			},
1109
			complete : function(jqXHR, textStatus) {
1125
			complete : function(jqXHR, textStatus) {
1110
				var debugMsg = '';
1126
				var debugMsg = '';
1111
				if (jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
1127
				if (jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
1112
					debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
1128
					debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
1113
					if (debugInfos != null) {
1129
					if (debugInfos != null) {
1114
						$.each(debugInfos, function (cle, valeur) {
1130
						$.each(debugInfos, function (cle, valeur) {
1115
							debugMsg += valeur + "\n";
1131
							debugMsg += valeur + "\n";
1116
						});
1132
						});
1117
					}
1133
					}
1118
				}
1134
				}
1119
				if (erreurMsg != '') {
1135
				if (erreurMsg != '') {
1120
					$("#fc-zone-dialogue").append('<p class="msg">'+
1136
					$("#fc-zone-dialogue").append('<p class="msg">'+
1121
							'Une erreur est survenue lors de la transmission de votre message.'+'<br />'+
1137
							'Une erreur est survenue lors de la transmission de votre message.'+'<br />'+
1122
							'Vous pouvez signaler le disfonctionnement à <a href="'+
1138
							'Vous pouvez signaler le disfonctionnement à <a href="'+
1123
							'mailto:cel@tela-botanica.org'+'?'+
1139
							'mailto:cel@tela-botanica.org'+'?'+
1124
							'subject=Disfonctionnement du widget carto'+
1140
							'subject=Disfonctionnement du widget carto'+
1125
							"&body="+erreurMsg+"\nDébogage :\n"+debugMsg+
1141
							"&body="+erreurMsg+"\nDébogage :\n"+debugMsg+
1126
							'">cel@tela-botanica.org</a>.'+
1142
							'">cel@tela-botanica.org</a>.'+
1127
							'</p>');
1143
							'</p>');
1128
				}
1144
				}
1129
				if (DEBUG) {
1145
				if (DEBUG) {
1130
					console.log('Débogage : '+debugMsg);
1146
					console.log('Débogage : '+debugMsg);
1131
				}
1147
				}
1132
				//console.log('Débogage : '+debugMsg);
1148
				//console.log('Débogage : '+debugMsg);
1133
				//console.log('Erreur : '+erreurMsg);
1149
				//console.log('Erreur : '+erreurMsg);
1134
			}
1150
			}
1135
		});
1151
		});
1136
	}
1152
	}
1137
	return false;
1153
	return false;
1138
}
1154
}
1139
/*+--------------------------------------------------------------------------------------------------------+*/
1155
/*+--------------------------------------------------------------------------------------------------------+*/
1140
// PANNEAU LATÉRAL
1156
// PANNEAU LATÉRAL
1141
var nbTaxons = 0;
1157
var nbTaxons = 0;
1142
function initialiserAffichagePanneauLateral() {	
1158
function initialiserAffichagePanneauLateral() {	
1143
	if (nt == '*') {
1159
	if (nt == '*') {
1144
		$('#pl-ouverture').bind('click', afficherPanneauLateral);
1160
		$('#pl-ouverture').bind('click', afficherPanneauLateral);
1145
		$('#pl-fermeture').bind('click', cacherPanneauLateral);
1161
		$('#pl-fermeture').bind('click', cacherPanneauLateral);
1146
	} else {
1162
	} else {
1147
		$('#panneau-lateral').width(0);
1163
		$('#panneau-lateral').width(0);
1148
		$('#carte').width('100%');
1164
		$('#carte').width('100%');
1149
	}
1165
	}
1150
	attribuerListenersFiltreUtilisateur();
1166
	attribuerListenersFiltreUtilisateur();
1151
	chargerTaxons(0, 0);
1167
	chargerTaxons(0, 0);
1152
}
1168
}
1153
 
1169
 
1154
function attribuerListenersFiltreUtilisateur() {
1170
function attribuerListenersFiltreUtilisateur() {
1155
	$('#valider-filtre-utilisateur').click(function() {
1171
	$('#valider-filtre-utilisateur').click(function() {
1156
		var utilisateur = $('#filtre-utilisateur').val();
1172
		var utilisateur = $('#filtre-utilisateur').val();
1157
		filtrerParUtilisateur(utilisateur);
1173
		filtrerParUtilisateur(utilisateur);
1158
		$('#raz-filtre-utilisateur').show();
1174
		$('#raz-filtre-utilisateur').show();
1159
	});
1175
	});
1160
	
1176
	
1161
	$('#filtre-utilisateur').keypress(function(e) {
1177
	$('#filtre-utilisateur').keypress(function(e) {
1162
		if (e.which == 13) {
1178
		if (e.which == 13) {
1163
			var utilisateur = $('#filtre-utilisateur').val();
1179
			var utilisateur = $('#filtre-utilisateur').val();
1164
			filtrerParUtilisateur(utilisateur);
1180
			filtrerParUtilisateur(utilisateur);
1165
			$('#raz-filtre-utilisateur').show();
1181
			$('#raz-filtre-utilisateur').show();
1166
		}
1182
		}
1167
	});
1183
	});
1168
	
1184
	
1169
	$('#raz-filtre-utilisateur').click(function() {
1185
	$('#raz-filtre-utilisateur').click(function() {
1170
		$('#filtre-utilisateur').val('');
1186
		$('#filtre-utilisateur').val('');
1171
		filtrerParUtilisateur('*');
1187
		filtrerParUtilisateur('*');
1172
		afficherCacherFiltreUtilisateur();
1188
		afficherCacherFiltreUtilisateur();
1173
		$('#raz-filtre-utilisateur').hide();
1189
		$('#raz-filtre-utilisateur').hide();
1174
	});
1190
	});
1175
	
1191
	
1176
	$('#lien-affichage-filtre-utilisateur').click(function() {
1192
	$('#lien-affichage-filtre-utilisateur').click(function() {
1177
		afficherCacherFiltreUtilisateur();
1193
		afficherCacherFiltreUtilisateur();
1178
	});
1194
	});
1179
 
1195
 
1180
	$('#raz-filtre-utilisateur').hide();
1196
	$('#raz-filtre-utilisateur').hide();
1181
	$('#formulaire-filtre-utilisateur').hide();
1197
	$('#formulaire-filtre-utilisateur').hide();
1182
}
1198
}
1183
 
1199
 
1184
function afficherCacherFiltreUtilisateur() {
1200
function afficherCacherFiltreUtilisateur() {
1185
	$('#formulaire-filtre-utilisateur').slideToggle();
1201
	$('#formulaire-filtre-utilisateur').slideToggle();
1186
	$('#conteneur-filtre-utilisateur').toggleClass('ferme');
1202
	$('#conteneur-filtre-utilisateur').toggleClass('ferme');
1187
	if (!$('#conteneur-filtre-utilisateur').hasClass('ferme')) {
1203
	if (!$('#conteneur-filtre-utilisateur').hasClass('ferme')) {
1188
		$('#conteneur-filtre-utilisateur').width(tailleMaxFiltreUtilisateur);
1204
		$('#conteneur-filtre-utilisateur').width(tailleMaxFiltreUtilisateur);
1189
	} else {
1205
	} else {
1190
		$('#conteneur-filtre-utilisateur').width('auto');
1206
		$('#conteneur-filtre-utilisateur').width('auto');
1191
	}
1207
	}
1192
}
1208
}
1193
 
1209
 
1194
function filtrerParUtilisateur(utilisateurFiltre) {
1210
function filtrerParUtilisateur(utilisateurFiltre) {
1195
	if (utilisateurFiltre == '') {	
1211
	if (utilisateurFiltre == '') {	
1196
		utilisateurFiltre = '*';
1212
		utilisateurFiltre = '*';
1197
	}
1213
	}
1198
	utilisateur = utilisateurFiltre;
1214
	utilisateur = utilisateurFiltre;
1199
	var pattern = /utilisateur=[^&]*/i,
1215
	var pattern = /utilisateur=[^&]*/i,
1200
		utilisateurCourant = pattern.exec(stationsUrl);
1216
		utilisateurCourant = pattern.exec(stationsUrl);
1201
	stationsUrl = stationsUrl.replace(utilisateurCourant, "utilisateur="+utilisateurFiltre);
1217
	stationsUrl = stationsUrl.replace(utilisateurCourant, "utilisateur="+utilisateurFiltre);
1202
	taxonsUrl = taxonsUrl.replace(utilisateurCourant, "utilisateur="+utilisateurFiltre);
1218
	taxonsUrl = taxonsUrl.replace(utilisateurCourant, "utilisateur="+utilisateurFiltre);
1203
	observationsUrl = observationsUrl.replace(utilisateurCourant, "utilisateur="+utilisateurFiltre);
1219
	observationsUrl = observationsUrl.replace(utilisateurCourant, "utilisateur="+utilisateurFiltre);
1204
	filtreCommun = filtreCommun.replace(utilisateurCourant, "utilisateur="+utilisateurFiltre);
1220
	filtreCommun = filtreCommun.replace(utilisateurCourant, "utilisateur="+utilisateurFiltre);
1205
	$("#taxons").html('');
1221
	$("#taxons").html('');
1206
	chargerTaxons(0,0);
1222
	chargerTaxons(0,0);
1207
	programmerRafraichissementCarte();
1223
	programmerRafraichissementCarte();
1208
}
1224
}
1209
 
1225
 
1210
function chargerTaxons(depart, total) {
1226
function chargerTaxons(depart, total) {
1211
	if (depart == 0 || depart < total) {
1227
	if (depart == 0 || depart < total) {
1212
		if(depart == 0) {
1228
		if(depart == 0) {
1213
			nbTaxons = 0;
1229
			nbTaxons = 0;
1214
			taxonsCarte = new Array();
1230
			taxonsCarte = new Array();
1215
		}
1231
		}
1216
		
1232
		
1217
		var limite = 2000;
1233
		var limite = 2000;
1218
		//console.log("Chargement des taxons de "+depart+" à "+(depart+limite));
1234
		//console.log("Chargement des taxons de "+depart+" à "+(depart+limite));
1219
		var urlTax = taxonsUrl+'&start={start}&limit='+limite;
1235
		var urlTax = taxonsUrl+'&start={start}&limit='+limite;
1220
		urlTax = urlTax.replace(/\{start\}/g, depart);
1236
		urlTax = urlTax.replace(/\{start\}/g, depart);
1221
		//console.log(urlTax);
1237
		//console.log(urlTax);
1222
		$.getJSON(urlTax, function(infos) {
1238
		$.getJSON(urlTax, function(infos) {
1223
			nbTaxons += infos.taxons.length;
1239
			nbTaxons += infos.taxons.length;
1224
			$('.plantes-nbre').text(nbTaxons);
1240
			$('.plantes-nbre').text(nbTaxons);
1225
			$('#tpl-taxons-liste').tmpl({'taxons': infos.taxons}).appendTo('#taxons');
1241
			$('#tpl-taxons-liste').tmpl({'taxons': infos.taxons}).appendTo('#taxons');
1226
			taxonsCarte = taxonsCarte.concat(infos.taxons);
1242
			taxonsCarte = taxonsCarte.concat(infos.taxons);
1227
			//console.log("Nbre taxons :"+taxonsCarte.length);
1243
			//console.log("Nbre taxons :"+taxonsCarte.length);
1228
			chargerTaxons(depart+limite, infos.total);
1244
			chargerTaxons(depart+limite, infos.total);
1229
		});
1245
		});
1230
	} else {
1246
	} else {
1231
		if (nt == '*') {
1247
		if (nt == '*') {
1232
			afficherTaxons();
1248
			afficherTaxons();
1233
		}
1249
		}
1234
		afficherTitreCarteEtStats();
1250
		afficherTitreCarteEtStats();
1235
	}
1251
	}
1236
}
1252
}
1237
 
1253
 
1238
function afficherTaxons() {
1254
function afficherTaxons() {
1239
	$('.taxon').live('click', filtrerParTaxon);
1255
	$('.taxon').live('click', filtrerParTaxon);
1240
	$('.raz-filtre-taxons').live('click', viderFiltreTaxon);
1256
	$('.raz-filtre-taxons').live('click', viderFiltreTaxon);
1241
}
1257
}
1242
 
1258
 
1243
var largeurPanneauLateralFerme = null;
1259
var largeurPanneauLateralFerme = null;
1244
function afficherPanneauLateral() {
1260
function afficherPanneauLateral() {
1245
	// fixer la hauteur
1261
	// fixer la hauteur
1246
	$('#panneau-lateral').height($(window).height() - $('#panneau-lateral').offset().top);
1262
	$('#panneau-lateral').height($(window).height() - $('#panneau-lateral').offset().top);
1247
	largeurPanneauLateralFerme = $('#panneau-lateral').width();
1263
	largeurPanneauLateralFerme = $('#panneau-lateral').width();
1248
	$('#panneau-lateral').width(300);
1264
	$('#panneau-lateral').width(300);
1249
	$('#pl-contenu').css('display', 'block');
1265
	$('#pl-contenu').css('display', 'block');
1250
	$('#pl-ouverture').css('display', 'none');
1266
	$('#pl-ouverture').css('display', 'none');
1251
	$('#pl-fermeture').css('display', 'block');
1267
	$('#pl-fermeture').css('display', 'block');
1252
	// correction pour la taille de la liste des taxons
1268
	// correction pour la taille de la liste des taxons
1253
	$('#pl-corps').height($(window).height() - $('#pl-corps').offset().top);
1269
	$('#pl-corps').height($(window).height() - $('#pl-corps').offset().top);
1254
 
1270
 
1255
	google.maps.event.trigger(map, 'resize');
1271
	google.maps.event.trigger(map, 'resize');
1256
};
1272
};
1257
 
1273
 
1258
function cacherPanneauLateral() {
1274
function cacherPanneauLateral() {
1259
	$('#panneau-lateral').height(25 + 'px');
1275
	$('#panneau-lateral').height(25 + 'px');
1260
	$('#panneau-lateral').width(largeurPanneauLateralFerme + 'px');
1276
	$('#panneau-lateral').width(largeurPanneauLateralFerme + 'px');
1261
	$('#pl-contenu').css('display', 'none');
1277
	$('#pl-contenu').css('display', 'none');
1262
	$('#pl-ouverture').css('display', 'block');
1278
	$('#pl-ouverture').css('display', 'block');
1263
	$('#pl-fermeture').css('display', 'none');
1279
	$('#pl-fermeture').css('display', 'none');
1264
	
1280
	
1265
	google.maps.event.trigger(map, 'resize');
1281
	google.maps.event.trigger(map, 'resize');
1266
};
1282
};
1267
 
1283
 
1268
function viderFiltreTaxon() {
1284
function viderFiltreTaxon() {
1269
	$('.taxon-actif .taxon').click();
1285
	$('.taxon-actif .taxon').click();
1270
}
1286
}
1271
 
1287
 
1272
function filtrerParTaxon() {
1288
function filtrerParTaxon() {
1273
	var ntAFiltrer = $('.nt', this).text();
1289
	var ntAFiltrer = $('.nt', this).text();
1274
	infoBulle.close();
1290
	infoBulle.close();
1275
	var zoom = map.getZoom();
1291
	var zoom = map.getZoom();
1276
	var NELatLng = map.getBounds().getNorthEast().lat()+'|'+map.getBounds().getNorthEast().lng();
1292
	var NELatLng = map.getBounds().getNorthEast().lat()+'|'+map.getBounds().getNorthEast().lng();
1277
	var SWLatLng = map.getBounds().getSouthWest().lat()+'|'+map.getBounds().getSouthWest().lng();
1293
	var SWLatLng = map.getBounds().getSouthWest().lat()+'|'+map.getBounds().getSouthWest().lng();
1278
	
1294
	
1279
	$('.raz-filtre-taxons').removeClass('taxon-actif');
1295
	$('.raz-filtre-taxons').removeClass('taxon-actif');
1280
	$('#taxon-'+nt).removeClass('taxon-actif');
1296
	$('#taxon-'+nt).removeClass('taxon-actif');
1281
	
1297
	
1282
	if (nt == ntAFiltrer) {
1298
	if (nt == ntAFiltrer) {
1283
		nt = '*';
1299
		nt = '*';
1284
		stationsUrl = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+nt);
1300
		stationsUrl = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+nt);
1285
		chargerMarqueurs(zoom, NELatLng, SWLatLng);
1301
		chargerMarqueurs(zoom, NELatLng, SWLatLng);
1286
	} else {
1302
	} else {
1287
		stationsUrl = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+ntAFiltrer);
1303
		stationsUrl = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+ntAFiltrer);
1288
		url = stationsUrl;
1304
		url = stationsUrl;
1289
		url += '&zoom='+zoom+
1305
		url += '&zoom='+zoom+
1290
			'&ne='+NELatLng+
1306
			'&ne='+NELatLng+
1291
			'&sw='+SWLatLng;
1307
			'&sw='+SWLatLng;
1292
		requeteChargementPoints = $.getJSON(url, function (stationsFiltrees) {
1308
		requeteChargementPoints = $.getJSON(url, function (stationsFiltrees) {
1293
			stations = stationsFiltrees;
1309
			stations = stationsFiltrees;
1294
			nt = ntAFiltrer;
1310
			nt = ntAFiltrer;
1295
			$('#taxon-'+nt).addClass('taxon-actif');
1311
			$('#taxon-'+nt).addClass('taxon-actif');
1296
			rafraichirMarqueurs(stations);
1312
			rafraichirMarqueurs(stations);
1297
		});
1313
		});
1298
	}
1314
	}
1299
};
1315
};
1300
 
1316
 
1301
/*+--------------------------------------------------------------------------------------------------------+*/
1317
/*+--------------------------------------------------------------------------------------------------------+*/
1302
// FONCTIONS UTILITAIRES
1318
// FONCTIONS UTILITAIRES
1303
 
1319
 
1304
function ouvrirPopUp(element, nomPopUp, event) {
1320
function ouvrirPopUp(element, nomPopUp, event) {
1305
	var options = 
1321
	var options = 
1306
		'width=650,'+
1322
		'width=650,'+
1307
		'height=600,'+
1323
		'height=600,'+
1308
		'scrollbars=yes,'+
1324
		'scrollbars=yes,'+
1309
		'directories=no,'+
1325
		'directories=no,'+
1310
		'location=no,'+
1326
		'location=no,'+
1311
		'menubar=no,'+
1327
		'menubar=no,'+
1312
		'status=no,'+
1328
		'status=no,'+
1313
		'toolbar=no';
1329
		'toolbar=no';
1314
	var popUp = window.open(element.href, nomPopUp, options);
1330
	var popUp = window.open(element.href, nomPopUp, options);
1315
	if (window.focus) {
1331
	if (window.focus) {
1316
		popUp.focus();
1332
		popUp.focus();
1317
	}
1333
	}
1318
	return arreter(event);
1334
	return arreter(event);
1319
};
1335
};
1320
 
1336
 
1321
function ouvrirNouvelleFenetre(element, event) {
1337
function ouvrirNouvelleFenetre(element, event) {
1322
	window.open(element.href);
1338
	window.open(element.href);
1323
	return arreter(event);
1339
	return arreter(event);
1324
}
1340
}
1325
 
1341
 
1326
function arreter(event) {
1342
function arreter(event) {
1327
	if (event.stopPropagation) {
1343
	if (event.stopPropagation) {
1328
		event.stopPropagation();
1344
		event.stopPropagation();
1329
	} else if (window.event) {
1345
	} else if (window.event) {
1330
		window.event.cancelBubble = true;
1346
		window.event.cancelBubble = true;
1331
	}
1347
	}
1332
	if (event.preventDefault) {
1348
	if (event.preventDefault) {
1333
		event.preventDefault();
1349
		event.preventDefault();
1334
	}
1350
	}
1335
	event.returnValue = false;
1351
	event.returnValue = false;
1336
	return false;
1352
	return false;
1337
}
1353
}
1338
 
1354
 
1339
/**
1355
/**
1340
 * +-------------------------------------+
1356
 * +-------------------------------------+
1341
 * Number.prototype.formaterNombre
1357
 * Number.prototype.formaterNombre
1342
 * +-------------------------------------+
1358
 * +-------------------------------------+
1343
 * Params (facultatifs):
1359
 * Params (facultatifs):
1344
 * - Int decimales: nombre de decimales (exemple: 2)
1360
 * - Int decimales: nombre de decimales (exemple: 2)
1345
 * - String signe: le signe precedent les decimales (exemple: "," ou ".")
1361
 * - String signe: le signe precedent les decimales (exemple: "," ou ".")
1346
 * - String separateurMilliers: comme son nom l'indique
1362
 * - String separateurMilliers: comme son nom l'indique
1347
 * Returns:
1363
 * Returns:
1348
 * - String chaine formatee
1364
 * - String chaine formatee
1349
 * @author	::mastahbenus::
1365
 * @author	::mastahbenus::
1350
 * @author	Jean-Pascal MILCENT <jpm@tela-botanica.org> : ajout détection auto entier/flotant
1366
 * @author	Jean-Pascal MILCENT <jpm@tela-botanica.org> : ajout détection auto entier/flotant
1351
 * @souce	http://www.javascriptfr.com/codes/FORMATER-NOMBRE-FACON-NUMBER-FORMAT-PHP_40060.aspx
1367
 * @souce	http://www.javascriptfr.com/codes/FORMATER-NOMBRE-FACON-NUMBER-FORMAT-PHP_40060.aspx
1352
 */
1368
 */
1353
Number.prototype.formaterNombre = function (decimales, signe, separateurMilliers) {
1369
Number.prototype.formaterNombre = function (decimales, signe, separateurMilliers) {
1354
	var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
1370
	var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
1355
	
1371
	
1356
	function is_int(nbre) {
1372
	function is_int(nbre) {
1357
		nbre = nbre.replace(',', '.');
1373
		nbre = nbre.replace(',', '.');
1358
		return !(parseFloat(nbre)-parseInt(nbre) > 0);
1374
		return !(parseFloat(nbre)-parseInt(nbre) > 0);
1359
	}
1375
	}
1360
 
1376
 
1361
	if (decimales == undefined) {
1377
	if (decimales == undefined) {
1362
		if (is_int(_sNombre)) {
1378
		if (is_int(_sNombre)) {
1363
			decimales = 0;
1379
			decimales = 0;
1364
		} else {
1380
		} else {
1365
			decimales = 2;
1381
			decimales = 2;
1366
		}
1382
		}
1367
	}
1383
	}
1368
	if (signe == undefined) {
1384
	if (signe == undefined) {
1369
		if (is_int(_sNombre)) {
1385
		if (is_int(_sNombre)) {
1370
			signe = '';
1386
			signe = '';
1371
		} else {
1387
		} else {
1372
			signe = '.';
1388
			signe = '.';
1373
		}
1389
		}
1374
	}
1390
	}
1375
	if (separateurMilliers == undefined) {
1391
	if (separateurMilliers == undefined) {
1376
		separateurMilliers = ' ';
1392
		separateurMilliers = ' ';
1377
	}
1393
	}
1378
	
1394
	
1379
	function separeMilliers (sNombre) {
1395
	function separeMilliers (sNombre) {
1380
		var sRetour = "";
1396
		var sRetour = "";
1381
		while (sNombre.length % 3 != 0) {
1397
		while (sNombre.length % 3 != 0) {
1382
			sNombre = "0"+sNombre;
1398
			sNombre = "0"+sNombre;
1383
		}
1399
		}
1384
		for (i = 0; i < sNombre.length; i += 3) {
1400
		for (i = 0; i < sNombre.length; i += 3) {
1385
			if (i == sNombre.length-1) separateurMilliers = '';
1401
			if (i == sNombre.length-1) separateurMilliers = '';
1386
			sRetour += sNombre.substr(i, 3) + separateurMilliers;
1402
			sRetour += sNombre.substr(i, 3) + separateurMilliers;
1387
		}
1403
		}
1388
		while (sRetour.substr(0, 1) == "0") {
1404
		while (sRetour.substr(0, 1) == "0") {
1389
			sRetour = sRetour.substr(1);
1405
			sRetour = sRetour.substr(1);
1390
		}
1406
		}
1391
		return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
1407
		return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
1392
	}
1408
	}
1393
	
1409
	
1394
	if (_sNombre.indexOf('.') == -1) {
1410
	if (_sNombre.indexOf('.') == -1) {
1395
		for (i = 0; i < decimales; i++) {
1411
		for (i = 0; i < decimales; i++) {
1396
			_sDecimales += '0';
1412
			_sDecimales += '0';
1397
		}
1413
		}
1398
		_sRetour = separeMilliers(_sNombre) + signe + _sDecimales;
1414
		_sRetour = separeMilliers(_sNombre) + signe + _sDecimales;
1399
	} else {
1415
	} else {
1400
		var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
1416
		var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
1401
		if (sDecimalesTmp.length > decimales) {
1417
		if (sDecimalesTmp.length > decimales) {
1402
			var nDecimalesManquantes = sDecimalesTmp.length - decimales;
1418
			var nDecimalesManquantes = sDecimalesTmp.length - decimales;
1403
			var nDiv = 1;
1419
			var nDiv = 1;
1404
			for (i = 0; i < nDecimalesManquantes; i++) {
1420
			for (i = 0; i < nDecimalesManquantes; i++) {
1405
				nDiv *= 10;
1421
				nDiv *= 10;
1406
			}
1422
			}
1407
			_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
1423
			_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
1408
		}
1424
		}
1409
		_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
1425
		_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
1410
	}
1426
	}
1411
	return _sRetour;
1427
	return _sRetour;
1412
}
1428
}
1413
 
1429
 
1414
function debug(objet) {
1430
function debug(objet) {
1415
	var msg = '';
1431
	var msg = '';
1416
	if (objet != null) {
1432
	if (objet != null) {
1417
		$.each(objet, function (cle, valeur) {
1433
		$.each(objet, function (cle, valeur) {
1418
			msg += cle+':'+valeur + "\n";
1434
			msg += cle+':'+valeur + "\n";
1419
		});
1435
		});
1420
	} else {
1436
	} else {
1421
		msg = 'La variable vaut null.';
1437
		msg = 'La variable vaut null.';
1422
	}
1438
	}
1423
	console.log(msg);
1439
	console.log(msg);
1424
}
1440
}