Subversion Repositories eFlore/Applications.cel

Rev

Rev 2383 | Rev 2998 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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