Subversion Repositories eFlore/Applications.cel

Rev

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

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