Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 2284 Rev 2285
1
/*+--------------------------------------------------------------------------------------------------------+*/
1
/*+--------------------------------------------------------------------------------------------------------+*/
2
// PARAMÊTRES et CONSTANTES
2
// PARAMÊTRES et CONSTANTES
3
/**
3
/**
4
* Indication de certaines variables ajoutée par php
4
* Indication de certaines variables ajoutée par php
5
* var communeImageUrl ;
5
* var communeImageUrl ;
6
* var pointImageUrl ;
6
* var pointImageUrl ;
7
* var groupeImageUrlTpl ;
7
* var groupeImageUrlTpl ;
8
*/
8
*/
9
var DEBUG = false,// Mettre à true pour afficher les messages de débogage 
9
var DEBUG = false,// Mettre à true pour afficher les messages de débogage 
10
	pointsOrigine = null,
10
	pointsOrigine = null,
11
	boundsOrigine = null,
11
	boundsOrigine = null,
12
	markerClusterer = null,
12
	markerClusterer = null,
13
	map = null,
13
	map = null,
14
	infoBulle = new google.maps.InfoWindow(),
14
	infoBulle = new google.maps.InfoWindow(),
15
	stations = null,
15
	stations = null,
16
	pointClique = null,
16
	pointClique = null,
17
	carteCentre = new google.maps.LatLng(25, 10),
17
	carteCentre = new google.maps.LatLng(25, 10),
18
	carteOptions = {
18
	carteOptions = {
19
		zoom: 3,
19
		zoom: 3,
20
		center:carteCentre,
20
		center:carteCentre,
21
		mapTypeId: 'OSM',
21
		mapTypeId: 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
747
		// Ajout de la zone geo
748
		if (pointClique.stationInfos.zonegeo) {
748
		if (pointClique.stationInfos.zonegeo) {
749
			urlObs += '&zonegeo=' + pointClique.stationInfos.zonegeo;
749
			urlObs += '&zonegeo=' + pointClique.stationInfos.zonegeo;
750
		}
750
		}
751
 
751
 
752
		urlObs = urlObs.replace(/\{nt\}/g, nt);
752
		urlObs = urlObs.replace(/\{nt\}/g, nt);
753
		urlObs = urlObs.replace(/\{start\}/g, depart);
753
		urlObs = urlObs.replace(/\{start\}/g, depart);
754
		
754
		
755
		$.getJSON(urlObs, function(observations){
755
		$.getJSON(urlObs, function(observations){
756
			surRetourChargementObs(observations, depart, total);
756
			surRetourChargementObs(observations, depart, total);
757
			chargerObs(depart+limite, observations.total);
757
			chargerObs(depart+limite, observations.total);
758
		});
758
		});
759
	}
759
	}
760
}
760
}
761
 
761
 
762
function formaterParametreCommunePourRequete(nomCommune) {
762
function formaterParametreCommunePourRequete(nomCommune) {
763
	var chaineRequete = "";
763
	var chaineRequete = "";
764
	if(nomCommune.indexOf("(", 0) !== false) {
764
	if(nomCommune.indexOf("(", 0) !== false) {
765
		var infosCommune = nomCommune.split("(");
765
		var infosCommune = nomCommune.split("(");
766
		var commune = infosCommune[0];
766
		var commune = infosCommune[0];
767
		chaineRequete = 'commune='+encodeURIComponent($.trim(commune));
767
		chaineRequete = 'commune='+encodeURIComponent($.trim(commune));
768
	} else {
768
	} else {
769
		chaineRequete = 'commune='+encodeURIComponent($.trim(nomCommune));
769
		chaineRequete = 'commune='+encodeURIComponent($.trim(nomCommune));
770
	}
770
	}
771
	return chaineRequete;
771
	return chaineRequete;
772
}
772
}
773
 
773
 
774
function viderTableauObs() {
774
function viderTableauObs() {
775
	obsStation = new Array();	
775
	obsStation = new Array();	
776
	surClicPagePagination(0, null);
776
	surClicPagePagination(0, null);
777
}
777
}
778
 
778
 
779
function surRetourChargementObs(observations, depart, total) {
779
function surRetourChargementObs(observations, depart, total) {
780
	obsStation = obsStation.concat(observations.observations);
780
	obsStation = obsStation.concat(observations.observations);
781
	if (depart == 0) {
781
	if (depart == 0) {
782
		actualiserInfosStation(observations);
782
		actualiserInfosStation(observations);
783
		creerTitreInfoBulle();
783
		creerTitreInfoBulle();
784
		surClicPagePagination(0, null);
784
		surClicPagePagination(0, null);
785
		console.log(observations);
785
		console.log(observations);
786
		mettreAJourUrlSaisie(observations);
786
		mettreAJourUrlSaisie(observations);
787
	}
787
	}
788
	
788
	
789
	afficherPagination();
789
	afficherPagination();
790
	actualiserPagineur();
790
	actualiserPagineur();
791
	selectionnerOnglet("#obs-vue-"+pagineur.format);
791
	selectionnerOnglet("#obs-vue-"+pagineur.format);
792
}
792
}
793
 
793
 
794
function actualiserInfosStation(infos) {
794
function actualiserInfosStation(infos) {
795
	pointClique.stationInfos.commune = infos.commune;
795
	pointClique.stationInfos.commune = infos.commune;
796
	pointClique.stationInfos.obsNbre = infos.total;
796
	pointClique.stationInfos.obsNbre = infos.total;
797
}
797
}
798
 
798
 
799
function creerTitreInfoBulle() {
799
function creerTitreInfoBulle() {
800
	$('#obs-total').text(station.obsNbre);
800
	$('#obs-total').text(station.obsNbre);
801
	$('#obs-commune').text(station.commune);
801
	$('#obs-commune').text(station.commune);
802
	var titre = '';
802
	var titre = '';
803
	titre += pointClique.stationInfos.obsNbre+' observation';
803
	titre += pointClique.stationInfos.obsNbre+' observation';
804
	titre += (pointClique.stationInfos.obsNbre > 1) ? 's': '' ;
804
	titre += (pointClique.stationInfos.obsNbre > 1) ? 's': '' ;
805
	titre += ' pour ';
805
	titre += ' pour ';
806
	if (etreMarqueurCommune(pointClique.stationInfos.id)) {
806
	if (etreMarqueurCommune(pointClique.stationInfos.id)) {
807
		nomStation = 'la commune : ';
807
		nomStation = 'la commune : ';
808
	} else {
808
	} else {
809
		nomStation = 'la station : ';
809
		nomStation = 'la station : ';
810
	}
810
	}
811
	titre += pointClique.stationInfos.nom;
811
	titre += pointClique.stationInfos.nom;
812
	$('#obs-station-titre').text(titre);	
812
	$('#obs-station-titre').text(titre);	
813
}
813
}
814
 
814
 
815
function actualiserPagineur() {
815
function actualiserPagineur() {
816
	pagineur.stationId = pointClique.stationInfos.id;
816
	pagineur.stationId = pointClique.stationInfos.id;
817
	pagineur.total = pointClique.stationInfos.obsNbre;
817
	pagineur.total = pointClique.stationInfos.obsNbre;
818
	// 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 
819
	// nombre de résultats
819
	// nombre de résultats
820
	if (pagineur.total > 4 && photos != 1) {
820
	if (pagineur.total > 4 && photos != 1) {
821
		pagineur.format = 'tableau';
821
		pagineur.format = 'tableau';
822
	} else {
822
	} else {
823
		pagineur.format = 'liste';
823
		pagineur.format = 'liste';
824
	}
824
	}
825
}
825
}
826
 
826
 
827
function afficherPagination(observations) {
827
function afficherPagination(observations) {
828
	$('.navigation').pagination(pagineur.total, {
828
	$('.navigation').pagination(pagineur.total, {
829
		items_per_page:pagineur.limite,
829
		items_per_page:pagineur.limite,
830
		callback:surClicPagePagination,
830
		callback:surClicPagePagination,
831
		next_text:'Suivant',
831
		next_text:'Suivant',
832
		prev_text:'Précédent',
832
		prev_text:'Précédent',
833
		prev_show_always:false,
833
		prev_show_always:false,
834
		num_edge_entries:1,
834
		num_edge_entries:1,
835
		num_display_entries:4,
835
		num_display_entries:4,
836
		load_first_page:true
836
		load_first_page:true
837
	});
837
	});
838
}
838
}
839
 
839
 
840
function surClicPagePagination(pageIndex, paginationConteneur) {
840
function surClicPagePagination(pageIndex, paginationConteneur) {
841
	var index = pageIndex * pagineur.limite,
841
	var index = pageIndex * pagineur.limite,
842
		indexMax = index + pagineur.limite;
842
		indexMax = index + pagineur.limite;
843
	pagineur.depart = index;
843
	pagineur.depart = index;
844
	obsPage = new Array();
844
	obsPage = new Array();
845
	for (index; index < indexMax; index++) {
845
	for (index; index < indexMax; index++) {
846
		obsPage.push(obsStation[index]);
846
		obsPage.push(obsStation[index]);
847
	}
847
	}
848
 
848
 
849
	supprimerMessageChargement();
849
	supprimerMessageChargement();
850
	mettreAJourObservations();
850
	mettreAJourObservations();
851
	return false;
851
	return false;
852
}
852
}
853
 
853
 
854
function mettreAJourObservations() {
854
function mettreAJourObservations() {
855
	$('#obs-'+pagineur.format+'-lignes').empty();
855
	$('#obs-'+pagineur.format+'-lignes').empty();
856
	$('#obs-vue-'+pagineur.format).css('display', 'block');
856
	$('#obs-vue-'+pagineur.format).css('display', 'block');
857
	$('.obs-conteneur').css('counter-reset', 'item '+pagineur.depart);
857
	$('.obs-conteneur').css('counter-reset', 'item '+pagineur.depart);
858
	$('#tpl-obs-'+pagineur.format).tmpl(obsPage).appendTo('#obs-'+pagineur.format+'-lignes');
858
	$('#tpl-obs-'+pagineur.format).tmpl(obsPage).appendTo('#obs-'+pagineur.format+'-lignes');
859
	
859
	
860
	// Actualisation de Fancybox
860
	// Actualisation de Fancybox
861
	ajouterFormulaireContact('a.contact');
861
	ajouterFormulaireContact('a.contact');
862
	if (pagineur.format == 'liste') {
862
	if (pagineur.format == 'liste') {
863
		ajouterGaleriePhoto('a.cel-img');
863
		ajouterGaleriePhoto('a.cel-img');
864
	}
864
	}
865
}
865
}
866
 
866
 
867
function initialiserContenuInfoBulle() {
867
function initialiserContenuInfoBulle() {
868
	afficherMessageChargement('#observations');
868
	afficherMessageChargement('#observations');
869
	cacherContenuOnglets();
869
	cacherContenuOnglets();
870
	afficherOnglets();
870
	afficherOnglets();
871
	ajouterTableauTriable('#obs-tableau');
871
	ajouterTableauTriable('#obs-tableau');
872
	afficherTextStationId();
872
	afficherTextStationId();
873
	corrigerLargeurInfoWindow();
873
	corrigerLargeurInfoWindow();
874
}
874
}
875
 
875
 
876
function cacherContenuOnglets() {
876
function cacherContenuOnglets() {
877
	$('#obs-vue-tableau').css('display', 'none');
877
	$('#obs-vue-tableau').css('display', 'none');
878
	$('#obs-vue-liste').css('display', 'none');
878
	$('#obs-vue-liste').css('display', 'none');
879
}
879
}
880
 
880
 
881
function afficherOnglets() {
881
function afficherOnglets() {
882
	var $tabs = $('#obs').tabs();
882
	var $tabs = $('#obs').tabs();
883
	$('#obs').bind('tabsselect', function(event, ui) {
883
	$('#obs').bind('tabsselect', function(event, ui) {
884
		if (ui.panel.id == 'obs-vue-tableau') {
884
		if (ui.panel.id == 'obs-vue-tableau') {
885
			surClicAffichageTableau();
885
			surClicAffichageTableau();
886
		} else if (ui.panel.id == 'obs-vue-liste') {
886
		} else if (ui.panel.id == 'obs-vue-liste') {
887
			surClicAffichageListe();
887
			surClicAffichageListe();
888
		}
888
		}
889
	});
889
	});
890
	if (pointClique.stationInfos.nbre > 4) {
890
	if (pointClique.stationInfos.nbre > 4) {
891
		$tabs.tabs('select', "#obs-vue-tableau");
891
		$tabs.tabs('select', "#obs-vue-tableau");
892
	} else {
892
	} else {
893
		$tabs.tabs('select', "#obs-vue-liste");
893
		$tabs.tabs('select', "#obs-vue-liste");
894
	}
894
	}
895
	
895
	
896
}
896
}
897
 
897
 
898
function selectionnerOnglet(onglet) {
898
function selectionnerOnglet(onglet) {
899
	$(onglet).css('display', 'block');
899
	$(onglet).css('display', 'block');
900
	$('#obs').tabs('select', onglet);
900
	$('#obs').tabs('select', onglet);
901
}
901
}
902
 
902
 
903
function afficherTextStationId() {
903
function afficherTextStationId() {
904
	$('#obs-station-id').text(pointClique.stationInfos.id);
904
	$('#obs-station-id').text(pointClique.stationInfos.id);
905
}
905
}
906
 
906
 
907
function corrigerLargeurInfoWindow() {
907
function corrigerLargeurInfoWindow() {
908
	$("#info-bulle").width($("#info-bulle").width() - 17);
908
	$("#info-bulle").width($("#info-bulle").width() - 17);
909
}
909
}
910
 
910
 
911
function surClicAffichageTableau(event) {
911
function surClicAffichageTableau(event) {
912
	pagineur.format = 'tableau';
912
	pagineur.format = 'tableau';
913
	mettreAJourObservations();
913
	mettreAJourObservations();
914
	mettreAJourTableauTriable("#obs-tableau");
914
	mettreAJourTableauTriable("#obs-tableau");
915
}
915
}
916
 
916
 
917
function surClicAffichageListe(event) {
917
function surClicAffichageListe(event) {
918
	pagineur.format = 'liste';
918
	pagineur.format = 'liste';
919
	mettreAJourObservations();
919
	mettreAJourObservations();
920
	ajouterGaleriePhoto("a.cel-img");
920
	ajouterGaleriePhoto("a.cel-img");
921
}
921
}
922
 
922
 
923
function ajouterTableauTriable(element) {
923
function ajouterTableauTriable(element) {
924
	// add parser through the tablesorter addParser method 
924
	// add parser through the tablesorter addParser method 
925
	$.tablesorter.addParser({ 
925
	$.tablesorter.addParser({ 
926
		// Définition d'un id unique pour ce parsseur 
926
		// Définition d'un id unique pour ce parsseur 
927
		id: 'date_cel', 
927
		id: 'date_cel', 
928
		is: function(s) { 
928
		is: function(s) { 
929
			// doit retourner false si le parsseur n'est pas autodétecté
929
			// doit retourner false si le parsseur n'est pas autodétecté
930
			return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s);
930
			return /^\s*\d{2}[\/-]\d{2}[\/-]\d{4}\s*$/.test(s);
931
		}, 
931
		}, 
932
		format: function(date) { 
932
		format: function(date) { 
933
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
933
			// Transformation date jj/mm/aaaa en aaaa/mm/jj
934
			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");
935
			// 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
936
			return $.tablesorter.formatFloat(new Date(date).getTime());
936
			return $.tablesorter.formatFloat(new Date(date).getTime());
937
		}, 
937
		}, 
938
		// set type, either numeric or text 
938
		// set type, either numeric or text 
939
		type: 'numeric' 
939
		type: 'numeric' 
940
	});
940
	});
941
	$(element).tablesorter({ 
941
	$(element).tablesorter({ 
942
		headers: { 
942
		headers: { 
943
			1: { 
943
			1: { 
944
				sorter: 'date_cel' 
944
				sorter: 'date_cel' 
945
			} 
945
			} 
946
		}
946
		}
947
	});
947
	});
948
}
948
}
949
 
949
 
950
function mettreAJourTableauTriable(element) {
950
function mettreAJourTableauTriable(element) {
951
	$(element).trigger('update');
951
	$(element).trigger('update');
952
}
952
}
953
 
953
 
954
function ajouterGaleriePhoto(element) {
954
function ajouterGaleriePhoto(element) {
955
	$(element).fancybox({
955
	$(element).fancybox({
956
		transitionIn: 'elastic',
956
		transitionIn: 'elastic',
957
		transitionOut: 'elastic',
957
		transitionOut: 'elastic',
958
		speedIn: 600, 
958
		speedIn: 600, 
959
		speedOut: 200,
959
		speedOut: 200,
960
		overlayShow: true,
960
		overlayShow: true,
961
		titleShow: true,
961
		titleShow: true,
962
		titlePosition: 'inside',
962
		titlePosition: 'inside',
963
		titleFormat: function (titre, currentArray, currentIndex, currentOpts) {
963
		titleFormat: function (titre, currentArray, currentIndex, currentOpts) {
964
			var motif = /urn:lsid:tela-botanica[.]org:cel:img([0-9]+)$/;
964
			var motif = /urn:lsid:tela-botanica[.]org:cel:img([0-9]+)$/;
965
			motif.exec(titre);
965
			motif.exec(titre);
966
			var id = RegExp.$1,
966
			var id = RegExp.$1,
967
				info = $('#cel-info-'+id).clone().html(),
967
				info = $('#cel-info-'+id).clone().html(),
968
				tpl = 
968
				tpl = 
969
					'<div class="cel-legende">'+
969
					'<div class="cel-legende">'+
970
					'<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>'+	
971
					(titre && titre.length ? '<p>'+info+'<\/p>' : '' )+
971
					(titre && titre.length ? '<p>'+info+'<\/p>' : '' )+
972
					'<\/div>';
972
					'<\/div>';
973
			return tpl;
973
			return tpl;
974
		}
974
		}
975
	}).live('click', function(e) {
975
	}).live('click', function(e) {
976
		if (e.stopPropagation) {
976
		if (e.stopPropagation) {
977
			e.stopPropagation();
977
			e.stopPropagation();
978
		}
978
		}
979
		return false;
979
		return false;
980
	});
980
	});
981
}
981
}
982
 
982
 
983
function ajouterFormulaireContact(element) {
983
function ajouterFormulaireContact(element) {
984
	$(element).fancybox({
984
	$(element).fancybox({
985
		transitionIn:'elastic',
985
		transitionIn:'elastic',
986
		transitionOut:'elastic',
986
		transitionOut:'elastic',
987
		speedIn	:600, 
987
		speedIn	:600, 
988
		speedOut:200,
988
		speedOut:200,
989
		scrolling: 'no',
989
		scrolling: 'no',
990
		titleShow: false,
990
		titleShow: false,
991
		onStart: function(selectedArray, selectedIndex, selectedOpts) {
991
		onStart: function(selectedArray, selectedIndex, selectedOpts) {
992
			var element = selectedArray[selectedIndex];
992
			var element = selectedArray[selectedIndex];
993
			var motif = / contributeur-([0-9]+)$/;
993
			var motif = / contributeur-([0-9]+)$/;
994
			motif.exec($(element).attr('class'));
994
			motif.exec($(element).attr('class'));
995
			// si la classe ne contient pas d'id contributeur
995
			// si la classe ne contient pas d'id contributeur
996
			// alors il faut stocker le numéro d'observation
996
			// alors il faut stocker le numéro d'observation
997
			var id = RegExp.$1;
997
			var id = RegExp.$1;
998
			if(id == "") {
998
			if(id == "") {
999
				$("#fc_type_envoi").attr('value', 'non-inscrit');
999
				$("#fc_type_envoi").attr('value', 'non-inscrit');
1000
				var motif = / obs-([0-9]+)$/;
1000
				var motif = / obs-([0-9]+)$/;
1001
				motif.exec($(element).attr('class'));
1001
				motif.exec($(element).attr('class'));
1002
				var id = RegExp.$1;
1002
				var id = RegExp.$1;
1003
			} else {
1003
			} else {
1004
				$("#fc_type_envoi").attr('value', 'inscrit');
1004
				$("#fc_type_envoi").attr('value', 'inscrit');
1005
			}
1005
			}
1006
 
1006
 
1007
			$("#fc_destinataire_id").attr('value', id);
1007
			$("#fc_destinataire_id").attr('value', id);
1008
		
1008
		
1009
			var motif = / obs-([0-9]+)/;
1009
			var motif = / obs-([0-9]+)/;
1010
			motif.exec($(element).attr('class'));
1010
			motif.exec($(element).attr('class'));
1011
			var id = RegExp.$1;
1011
			var id = RegExp.$1;
1012
			//console.log('Obs id : '+id);
1012
			//console.log('Obs id : '+id);
1013
			chargerInfoObsPourMessage(id);
1013
			chargerInfoObsPourMessage(id);
1014
		},
1014
		},
1015
		onCleanup: function() {
1015
		onCleanup: function() {
1016
			//console.log('Avant fermeture fancybox');
1016
			//console.log('Avant fermeture fancybox');
1017
			$("#fc_destinataire_id").attr('value', '');
1017
			$("#fc_destinataire_id").attr('value', '');
1018
			$("#fc_sujet").attr('value', '');
1018
			$("#fc_sujet").attr('value', '');
1019
			$("#fc_message").text('');
1019
			$("#fc_message").text('');
1020
		},
1020
		},
1021
		onClosed: function(e) {
1021
		onClosed: function(e) {
1022
			//console.log('Fermeture fancybox');
1022
			//console.log('Fermeture fancybox');
1023
			if (e.stopPropagation) {
1023
			if (e.stopPropagation) {
1024
				e.stopPropagation();
1024
				e.stopPropagation();
1025
			}
1025
			}
1026
			return false;
1026
			return false;
1027
		}
1027
		}
1028
	});
1028
	});
1029
}
1029
}
1030
 
1030
 
1031
function chargerInfoObsPourMessage(idObs) {
1031
function chargerInfoObsPourMessage(idObs) {
1032
	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());
1033
	var date = jQuery.trim($(".cel-obs-"+idObs+" .date:eq(0)").text());
1033
	var date = jQuery.trim($(".cel-obs-"+idObs+" .date:eq(0)").text());
1034
	var lieu = jQuery.trim($(".cel-obs-"+idObs+" .lieu:eq(0)").text());
1034
	var lieu = jQuery.trim($(".cel-obs-"+idObs+" .lieu:eq(0)").text());
1035
	var sujet = "Observation #"+idObs+" de "+nomSci;
1035
	var sujet = "Observation #"+idObs+" de "+nomSci;
1036
	var message = "\n\n\n\n\n\n\n\n--\nConcerne l'observation de \""+nomSci+'" du "'+date+'" au lieu "'+lieu+'".';
1036
	var message = "\n\n\n\n\n\n\n\n--\nConcerne l'observation de \""+nomSci+'" du "'+date+'" au lieu "'+lieu+'".';
1037
	$("#fc_sujet").attr('value', sujet);
1037
	$("#fc_sujet").attr('value', sujet);
1038
	$("#fc_message").text(message);
1038
	$("#fc_message").text(message);
1039
}
1039
}
1040
 
1040
 
1041
function initialiserFormulaireContact() {
1041
function initialiserFormulaireContact() {
1042
	//console.log('Initialisation du form contact');
1042
	//console.log('Initialisation du form contact');
1043
	$("#form-contact").validate({
1043
	$("#form-contact").validate({
1044
		rules: {
1044
		rules: {
1045
			fc_sujet : "required",
1045
			fc_sujet : "required",
1046
			fc_message : "required",
1046
			fc_message : "required",
1047
			fc_utilisateur_courriel : {
1047
			fc_utilisateur_courriel : {
1048
				required : true,
1048
				required : true,
1049
				email : true}
1049
				email : true}
1050
		}
1050
		}
1051
	});
1051
	});
1052
	$("#form-contact").bind("submit", envoyerCourriel);
1052
	$("#form-contact").bind("submit", envoyerCourriel);
1053
	$("#fc_annuler").bind("click", function() {$.fancybox.close();});
1053
	$("#fc_annuler").bind("click", function() {$.fancybox.close();});
1054
	
1054
	
1055
}
1055
}
1056
 
1056
 
1057
function envoyerCourriel() {
1057
function envoyerCourriel() {
1058
	//console.log('Formulaire soumis');
1058
	//console.log('Formulaire soumis');
1059
	if ($("#form-contact").valid()) {
1059
	if ($("#form-contact").valid()) {
1060
		//console.log('Formulaire valide');
1060
		//console.log('Formulaire valide');
1061
		//$.fancybox.showActivity();
1061
		//$.fancybox.showActivity();
1062
		var destinataireId = $("#fc_destinataire_id").attr('value');
1062
		var destinataireId = $("#fc_destinataire_id").attr('value');
1063
		var typeEnvoi = $("#fc_type_envoi").attr('value');
1063
		var typeEnvoi = $("#fc_type_envoi").attr('value');
1064
		if(typeEnvoi == "non-inscrit") {
1064
		if(typeEnvoi == "non-inscrit") {
1065
			// 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
1066
			// 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
1067
			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;
1068
		} else {
1068
		} else {
1069
			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";
1070
		}
1070
		}
1071
		var erreurMsg = "";
1071
		var erreurMsg = "";
1072
		var donnees = new Array();
1072
		var donnees = new Array();
1073
		$.each($(this).serializeArray(), function (index, champ) {
1073
		$.each($(this).serializeArray(), function (index, champ) {
1074
			var cle = champ.name;
1074
			var cle = champ.name;
1075
			cle = cle.replace(/^fc_/, '');
1075
			cle = cle.replace(/^fc_/, '');
1076
			
1076
			
1077
			if (cle == 'sujet') {
1077
			if (cle == 'sujet') {
1078
				champ.value += " - Carnet en ligne - Tela Botanica";
1078
				champ.value += " - Carnet en ligne - Tela Botanica";
1079
			}
1079
			}
1080
			if (cle == 'message') {
1080
			if (cle == 'message') {
1081
				champ.value += "\n--\n"+
1081
				champ.value += "\n--\n"+
1082
					"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 "+
1083
					"du Carnet en Ligne du réseau Tela Botanica.\n"+
1083
					"du Carnet en Ligne du réseau Tela Botanica.\n"+
1084
					"http://www.tela-botanica.org/widget:cel:carto";
1084
					"http://www.tela-botanica.org/widget:cel:carto";
1085
			}
1085
			}
1086
			
1086
			
1087
			donnees[index] = {'name':cle,'value':champ.value};
1087
			donnees[index] = {'name':cle,'value':champ.value};
1088
		});
1088
		});
1089
		$.ajax({
1089
		$.ajax({
1090
			type : "POST",
1090
			type : "POST",
1091
			cache : false,
1091
			cache : false,
1092
			url : urlMessage,
1092
			url : urlMessage,
1093
			data : donnees,
1093
			data : donnees,
1094
			beforeSend : function() {
1094
			beforeSend : function() {
1095
				$(".msg").remove();
1095
				$(".msg").remove();
1096
			},
1096
			},
1097
			success : function(data) {
1097
			success : function(data) {
1098
				$("#fc-zone-dialogue").append('<pre class="msg info">'+data.message+'</pre>');
1098
				$("#fc-zone-dialogue").append('<pre class="msg info">'+data.message+'</pre>');
1099
			},
1099
			},
1100
			error : function(jqXHR, textStatus, errorThrown) {
1100
			error : function(jqXHR, textStatus, errorThrown) {
1101
				erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
1101
				erreurMsg += "Erreur Ajax :\ntype : "+textStatus+' '+errorThrown+"\n";
1102
				reponse = jQuery.parseJSON(jqXHR.responseText);
1102
				reponse = jQuery.parseJSON(jqXHR.responseText);
1103
				if (reponse != null) {
1103
				if (reponse != null) {
1104
					$.each(reponse, function (cle, valeur) {
1104
					$.each(reponse, function (cle, valeur) {
1105
						erreurMsg += valeur + "\n";
1105
						erreurMsg += valeur + "\n";
1106
					});
1106
					});
1107
				}				
1107
				}				
1108
			},
1108
			},
1109
			complete : function(jqXHR, textStatus) {
1109
			complete : function(jqXHR, textStatus) {
1110
				var debugMsg = '';
1110
				var debugMsg = '';
1111
				if (jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
1111
				if (jqXHR.getResponseHeader("X-DebugJrest-Data") != '') {
1112
					debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
1112
					debugInfos = jQuery.parseJSON(jqXHR.getResponseHeader("X-DebugJrest-Data"));
1113
					if (debugInfos != null) {
1113
					if (debugInfos != null) {
1114
						$.each(debugInfos, function (cle, valeur) {
1114
						$.each(debugInfos, function (cle, valeur) {
1115
							debugMsg += valeur + "\n";
1115
							debugMsg += valeur + "\n";
1116
						});
1116
						});
1117
					}
1117
					}
1118
				}
1118
				}
1119
				if (erreurMsg != '') {
1119
				if (erreurMsg != '') {
1120
					$("#fc-zone-dialogue").append('<p class="msg">'+
1120
					$("#fc-zone-dialogue").append('<p class="msg">'+
1121
							'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 />'+
1122
							'Vous pouvez signaler le disfonctionnement à <a href="'+
1122
							'Vous pouvez signaler le disfonctionnement à <a href="'+
1123
							'mailto:cel@tela-botanica.org'+'?'+
1123
							'mailto:cel@tela-botanica.org'+'?'+
1124
							'subject=Disfonctionnement du widget carto'+
1124
							'subject=Disfonctionnement du widget carto'+
1125
							"&body="+erreurMsg+"\nDébogage :\n"+debugMsg+
1125
							"&body="+erreurMsg+"\nDébogage :\n"+debugMsg+
1126
							'">cel@tela-botanica.org</a>.'+
1126
							'">cel@tela-botanica.org</a>.'+
1127
							'</p>');
1127
							'</p>');
1128
				}
1128
				}
1129
				if (DEBUG) {
1129
				if (DEBUG) {
1130
					console.log('Débogage : '+debugMsg);
1130
					console.log('Débogage : '+debugMsg);
1131
				}
1131
				}
1132
				//console.log('Débogage : '+debugMsg);
1132
				//console.log('Débogage : '+debugMsg);
1133
				//console.log('Erreur : '+erreurMsg);
1133
				//console.log('Erreur : '+erreurMsg);
1134
			}
1134
			}
1135
		});
1135
		});
1136
	}
1136
	}
1137
	return false;
1137
	return false;
1138
}
1138
}
1139
/*+--------------------------------------------------------------------------------------------------------+*/
1139
/*+--------------------------------------------------------------------------------------------------------+*/
1140
// PANNEAU LATÉRAL
1140
// PANNEAU LATÉRAL
1141
var nbTaxons = 0;
1141
var nbTaxons = 0;
1142
function initialiserAffichagePanneauLateral() {	
1142
function initialiserAffichagePanneauLateral() {	
1143
	if (nt == '*') {
1143
	if (nt == '*') {
1144
		$('#pl-ouverture').bind('click', afficherPanneauLateral);
1144
		$('#pl-ouverture').bind('click', afficherPanneauLateral);
1145
		$('#pl-fermeture').bind('click', cacherPanneauLateral);
1145
		$('#pl-fermeture').bind('click', cacherPanneauLateral);
1146
	} else {
1146
	} else {
1147
		$('#panneau-lateral').width(0);
1147
		$('#panneau-lateral').width(0);
1148
		$('#carte').width('100%');
1148
		$('#carte').width('100%');
1149
	}
1149
	}
1150
	attribuerListenersFiltreUtilisateur();
1150
	attribuerListenersFiltreUtilisateur();
1151
	chargerTaxons(0, 0);
1151
	chargerTaxons(0, 0);
1152
}
1152
}
1153
 
1153
 
1154
function attribuerListenersFiltreUtilisateur() {
1154
function attribuerListenersFiltreUtilisateur() {
1155
	$('#valider-filtre-utilisateur').click(function() {
1155
	$('#valider-filtre-utilisateur').click(function() {
1156
		var utilisateur = $('#filtre-utilisateur').val();
1156
		var utilisateur = $('#filtre-utilisateur').val();
1157
		filtrerParUtilisateur(utilisateur);
1157
		filtrerParUtilisateur(utilisateur);
1158
		$('#raz-filtre-utilisateur').show();
1158
		$('#raz-filtre-utilisateur').show();
1159
	});
1159
	});
1160
	
1160
	
1161
	$('#filtre-utilisateur').keypress(function(e) {
1161
	$('#filtre-utilisateur').keypress(function(e) {
1162
		if (e.which == 13) {
1162
		if (e.which == 13) {
1163
			var utilisateur = $('#filtre-utilisateur').val();
1163
			var utilisateur = $('#filtre-utilisateur').val();
1164
			filtrerParUtilisateur(utilisateur);
1164
			filtrerParUtilisateur(utilisateur);
1165
			$('#raz-filtre-utilisateur').show();
1165
			$('#raz-filtre-utilisateur').show();
1166
		}
1166
		}
1167
	});
1167
	});
1168
	
1168
	
1169
	$('#raz-filtre-utilisateur').click(function() {
1169
	$('#raz-filtre-utilisateur').click(function() {
1170
		$('#filtre-utilisateur').val('');
1170
		$('#filtre-utilisateur').val('');
1171
		filtrerParUtilisateur('*');
1171
		filtrerParUtilisateur('*');
1172
		afficherCacherFiltreUtilisateur();
1172
		afficherCacherFiltreUtilisateur();
1173
		$('#raz-filtre-utilisateur').hide();
1173
		$('#raz-filtre-utilisateur').hide();
1174
	});
1174
	});
1175
	
1175
	
1176
	$('#lien-affichage-filtre-utilisateur').click(function() {
1176
	$('#lien-affichage-filtre-utilisateur').click(function() {
1177
		afficherCacherFiltreUtilisateur();
1177
		afficherCacherFiltreUtilisateur();
1178
	});
1178
	});
1179
 
1179
 
1180
	$('#raz-filtre-utilisateur').hide();
1180
	$('#raz-filtre-utilisateur').hide();
1181
	$('#formulaire-filtre-utilisateur').hide();
1181
	$('#formulaire-filtre-utilisateur').hide();
1182
}
1182
}
1183
 
1183
 
1184
function afficherCacherFiltreUtilisateur() {
1184
function afficherCacherFiltreUtilisateur() {
1185
	$('#formulaire-filtre-utilisateur').slideToggle();
1185
	$('#formulaire-filtre-utilisateur').slideToggle();
1186
	$('#conteneur-filtre-utilisateur').toggleClass('ferme');
1186
	$('#conteneur-filtre-utilisateur').toggleClass('ferme');
1187
	if (!$('#conteneur-filtre-utilisateur').hasClass('ferme')) {
1187
	if (!$('#conteneur-filtre-utilisateur').hasClass('ferme')) {
1188
		$('#conteneur-filtre-utilisateur').width(tailleMaxFiltreUtilisateur);
1188
		$('#conteneur-filtre-utilisateur').width(tailleMaxFiltreUtilisateur);
1189
	} else {
1189
	} else {
1190
		$('#conteneur-filtre-utilisateur').width('auto');
1190
		$('#conteneur-filtre-utilisateur').width('auto');
1191
	}
1191
	}
1192
}
1192
}
1193
 
1193
 
1194
function filtrerParUtilisateur(utilisateurFiltre) {
1194
function filtrerParUtilisateur(utilisateurFiltre) {
1195
	if (utilisateurFiltre == '') {	
1195
	if (utilisateurFiltre == '') {	
1196
		utilisateurFiltre = '*';
1196
		utilisateurFiltre = '*';
1197
	}
1197
	}
1198
	utilisateur = utilisateurFiltre;
1198
	utilisateur = utilisateurFiltre;
1199
	var pattern = /utilisateur=[^&]*/i,
1199
	var pattern = /utilisateur=[^&]*/i,
1200
		utilisateurCourant = pattern.exec(stationsUrl);
1200
		utilisateurCourant = pattern.exec(stationsUrl);
1201
	stationsUrl = stationsUrl.replace(utilisateurCourant, "utilisateur="+utilisateurFiltre);
1201
	stationsUrl = stationsUrl.replace(utilisateurCourant, "utilisateur="+utilisateurFiltre);
1202
	taxonsUrl = taxonsUrl.replace(utilisateurCourant, "utilisateur="+utilisateurFiltre);
1202
	taxonsUrl = taxonsUrl.replace(utilisateurCourant, "utilisateur="+utilisateurFiltre);
1203
	observationsUrl = observationsUrl.replace(utilisateurCourant, "utilisateur="+utilisateurFiltre);
1203
	observationsUrl = observationsUrl.replace(utilisateurCourant, "utilisateur="+utilisateurFiltre);
1204
	filtreCommun = filtreCommun.replace(utilisateurCourant, "utilisateur="+utilisateurFiltre);
1204
	filtreCommun = filtreCommun.replace(utilisateurCourant, "utilisateur="+utilisateurFiltre);
1205
	$("#taxons").html('');
1205
	$("#taxons").html('');
1206
	chargerTaxons(0,0);
1206
	chargerTaxons(0,0);
1207
	programmerRafraichissementCarte();
1207
	programmerRafraichissementCarte();
1208
}
1208
}
1209
 
1209
 
1210
function chargerTaxons(depart, total) {
1210
function chargerTaxons(depart, total) {
1211
	if (depart == 0 || depart < total) {
1211
	if (depart == 0 || depart < total) {
1212
		if(depart == 0) {
1212
		if(depart == 0) {
1213
			nbTaxons = 0;
1213
			nbTaxons = 0;
1214
			taxonsCarte = new Array();
1214
			taxonsCarte = new Array();
1215
		}
1215
		}
1216
		
1216
		
1217
		var limite = 2000;
1217
		var limite = 2000;
1218
		//console.log("Chargement des taxons de "+depart+" à "+(depart+limite));
1218
		//console.log("Chargement des taxons de "+depart+" à "+(depart+limite));
1219
		var urlTax = taxonsUrl+'&start={start}&limit='+limite;
1219
		var urlTax = taxonsUrl+'&start={start}&limit='+limite;
1220
		urlTax = urlTax.replace(/\{start\}/g, depart);
1220
		urlTax = urlTax.replace(/\{start\}/g, depart);
1221
		//console.log(urlTax);
1221
		//console.log(urlTax);
1222
		$.getJSON(urlTax, function(infos) {
1222
		$.getJSON(urlTax, function(infos) {
1223
			nbTaxons += infos.taxons.length;
1223
			nbTaxons += infos.taxons.length;
1224
			$('.plantes-nbre').text(nbTaxons);
1224
			$('.plantes-nbre').text(nbTaxons);
1225
			$('#tpl-taxons-liste').tmpl({'taxons': infos.taxons}).appendTo('#taxons');
1225
			$('#tpl-taxons-liste').tmpl({'taxons': infos.taxons}).appendTo('#taxons');
1226
			taxonsCarte = taxonsCarte.concat(infos.taxons);
1226
			taxonsCarte = taxonsCarte.concat(infos.taxons);
1227
			//console.log("Nbre taxons :"+taxonsCarte.length);
1227
			//console.log("Nbre taxons :"+taxonsCarte.length);
1228
			chargerTaxons(depart+limite, infos.total);
1228
			chargerTaxons(depart+limite, infos.total);
1229
		});
1229
		});
1230
	} else {
1230
	} else {
1231
		if (nt == '*') {
1231
		if (nt == '*') {
1232
			afficherTaxons();
1232
			afficherTaxons();
1233
		}
1233
		}
1234
		afficherTitreCarteEtStats();
1234
		afficherTitreCarteEtStats();
1235
	}
1235
	}
1236
}
1236
}
1237
 
1237
 
1238
function afficherTaxons() {
1238
function afficherTaxons() {
1239
	$('.taxon').live('click', filtrerParTaxon);
1239
	$('.taxon').live('click', filtrerParTaxon);
1240
	$('.raz-filtre-taxons').live('click', viderFiltreTaxon);
1240
	$('.raz-filtre-taxons').live('click', viderFiltreTaxon);
1241
}
1241
}
1242
 
1242
 
1243
var largeurPanneauLateralFerme = null;
1243
var largeurPanneauLateralFerme = null;
1244
function afficherPanneauLateral() {
1244
function afficherPanneauLateral() {
1245
	// fixer la hauteur
1245
	// fixer la hauteur
1246
	$('#panneau-lateral').height($(window).height() - $('#panneau-lateral').offset().top);
1246
	$('#panneau-lateral').height($(window).height() - $('#panneau-lateral').offset().top);
1247
	largeurPanneauLateralFerme = $('#panneau-lateral').width();
1247
	largeurPanneauLateralFerme = $('#panneau-lateral').width();
1248
	$('#panneau-lateral').width(300);
1248
	$('#panneau-lateral').width(300);
1249
	$('#pl-contenu').css('display', 'block');
1249
	$('#pl-contenu').css('display', 'block');
1250
	$('#pl-ouverture').css('display', 'none');
1250
	$('#pl-ouverture').css('display', 'none');
1251
	$('#pl-fermeture').css('display', 'block');
1251
	$('#pl-fermeture').css('display', 'block');
1252
	// correction pour la taille de la liste des taxons
1252
	// correction pour la taille de la liste des taxons
1253
	$('#pl-corps').height($(window).height() - $('#pl-corps').offset().top);
1253
	$('#pl-corps').height($(window).height() - $('#pl-corps').offset().top);
1254
 
1254
 
1255
	google.maps.event.trigger(map, 'resize');
1255
	google.maps.event.trigger(map, 'resize');
1256
};
1256
};
1257
 
1257
 
1258
function cacherPanneauLateral() {
1258
function cacherPanneauLateral() {
1259
	$('#panneau-lateral').height(25 + 'px');
1259
	$('#panneau-lateral').height(25 + 'px');
1260
	$('#panneau-lateral').width(largeurPanneauLateralFerme + 'px');
1260
	$('#panneau-lateral').width(largeurPanneauLateralFerme + 'px');
1261
	$('#pl-contenu').css('display', 'none');
1261
	$('#pl-contenu').css('display', 'none');
1262
	$('#pl-ouverture').css('display', 'block');
1262
	$('#pl-ouverture').css('display', 'block');
1263
	$('#pl-fermeture').css('display', 'none');
1263
	$('#pl-fermeture').css('display', 'none');
1264
	
1264
	
1265
	google.maps.event.trigger(map, 'resize');
1265
	google.maps.event.trigger(map, 'resize');
1266
};
1266
};
1267
 
1267
 
1268
function viderFiltreTaxon() {
1268
function viderFiltreTaxon() {
1269
	$('.taxon-actif .taxon').click();
1269
	$('.taxon-actif .taxon').click();
1270
}
1270
}
1271
 
1271
 
1272
function filtrerParTaxon() {
1272
function filtrerParTaxon() {
1273
	var ntAFiltrer = $('.nt', this).text();
1273
	var ntAFiltrer = $('.nt', this).text();
1274
	infoBulle.close();
1274
	infoBulle.close();
1275
	var zoom = map.getZoom();
1275
	var zoom = map.getZoom();
1276
	var NELatLng = map.getBounds().getNorthEast().lat()+'|'+map.getBounds().getNorthEast().lng();
1276
	var NELatLng = map.getBounds().getNorthEast().lat()+'|'+map.getBounds().getNorthEast().lng();
1277
	var SWLatLng = map.getBounds().getSouthWest().lat()+'|'+map.getBounds().getSouthWest().lng();
1277
	var SWLatLng = map.getBounds().getSouthWest().lat()+'|'+map.getBounds().getSouthWest().lng();
1278
	
1278
	
1279
	$('.raz-filtre-taxons').removeClass('taxon-actif');
1279
	$('.raz-filtre-taxons').removeClass('taxon-actif');
1280
	$('#taxon-'+nt).removeClass('taxon-actif');
1280
	$('#taxon-'+nt).removeClass('taxon-actif');
1281
	
1281
	
1282
	if (nt == ntAFiltrer) {
1282
	if (nt == ntAFiltrer) {
1283
		nt = '*';
1283
		nt = '*';
1284
		stationsUrl = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+nt);
1284
		stationsUrl = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+nt);
1285
		chargerMarqueurs(zoom, NELatLng, SWLatLng);
1285
		chargerMarqueurs(zoom, NELatLng, SWLatLng);
1286
	} else {
1286
	} else {
1287
		stationsUrl = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+ntAFiltrer);
1287
		stationsUrl = stationsUrl.replace(/num_taxon=[*0-9]+/, 'num_taxon='+ntAFiltrer);
1288
		url = stationsUrl;
1288
		url = stationsUrl;
1289
		url += '&zoom='+zoom+
1289
		url += '&zoom='+zoom+
1290
			'&ne='+NELatLng+
1290
			'&ne='+NELatLng+
1291
			'&sw='+SWLatLng;
1291
			'&sw='+SWLatLng;
1292
		requeteChargementPoints = $.getJSON(url, function (stationsFiltrees) {
1292
		requeteChargementPoints = $.getJSON(url, function (stationsFiltrees) {
1293
			stations = stationsFiltrees;
1293
			stations = stationsFiltrees;
1294
			nt = ntAFiltrer;
1294
			nt = ntAFiltrer;
1295
			$('#taxon-'+nt).addClass('taxon-actif');
1295
			$('#taxon-'+nt).addClass('taxon-actif');
1296
			rafraichirMarqueurs(stations);
1296
			rafraichirMarqueurs(stations);
1297
		});
1297
		});
1298
	}
1298
	}
1299
};
1299
};
1300
 
1300
 
1301
/*+--------------------------------------------------------------------------------------------------------+*/
1301
/*+--------------------------------------------------------------------------------------------------------+*/
1302
// FONCTIONS UTILITAIRES
1302
// FONCTIONS UTILITAIRES
1303
 
1303
 
1304
function ouvrirPopUp(element, nomPopUp, event) {
1304
function ouvrirPopUp(element, nomPopUp, event) {
1305
	var options = 
1305
	var options = 
1306
		'width=650,'+
1306
		'width=650,'+
1307
		'height=600,'+
1307
		'height=600,'+
1308
		'scrollbars=yes,'+
1308
		'scrollbars=yes,'+
1309
		'directories=no,'+
1309
		'directories=no,'+
1310
		'location=no,'+
1310
		'location=no,'+
1311
		'menubar=no,'+
1311
		'menubar=no,'+
1312
		'status=no,'+
1312
		'status=no,'+
1313
		'toolbar=no';
1313
		'toolbar=no';
1314
	var popUp = window.open(element.href, nomPopUp, options);
1314
	var popUp = window.open(element.href, nomPopUp, options);
1315
	if (window.focus) {
1315
	if (window.focus) {
1316
		popUp.focus();
1316
		popUp.focus();
1317
	}
1317
	}
1318
	return arreter(event);
1318
	return arreter(event);
1319
};
1319
};
1320
 
1320
 
1321
function ouvrirNouvelleFenetre(element, event) {
1321
function ouvrirNouvelleFenetre(element, event) {
1322
	window.open(element.href);
1322
	window.open(element.href);
1323
	return arreter(event);
1323
	return arreter(event);
1324
}
1324
}
1325
 
1325
 
1326
function arreter(event) {
1326
function arreter(event) {
1327
	if (event.stopPropagation) {
1327
	if (event.stopPropagation) {
1328
		event.stopPropagation();
1328
		event.stopPropagation();
1329
	} else if (window.event) {
1329
	} else if (window.event) {
1330
		window.event.cancelBubble = true;
1330
		window.event.cancelBubble = true;
1331
	}
1331
	}
1332
	if (event.preventDefault) {
1332
	if (event.preventDefault) {
1333
		event.preventDefault();
1333
		event.preventDefault();
1334
	}
1334
	}
1335
	event.returnValue = false;
1335
	event.returnValue = false;
1336
	return false;
1336
	return false;
1337
}
1337
}
1338
 
1338
 
1339
/**
1339
/**
1340
 * +-------------------------------------+
1340
 * +-------------------------------------+
1341
 * Number.prototype.formaterNombre
1341
 * Number.prototype.formaterNombre
1342
 * +-------------------------------------+
1342
 * +-------------------------------------+
1343
 * Params (facultatifs):
1343
 * Params (facultatifs):
1344
 * - Int decimales: nombre de decimales (exemple: 2)
1344
 * - Int decimales: nombre de decimales (exemple: 2)
1345
 * - String signe: le signe precedent les decimales (exemple: "," ou ".")
1345
 * - String signe: le signe precedent les decimales (exemple: "," ou ".")
1346
 * - String separateurMilliers: comme son nom l'indique
1346
 * - String separateurMilliers: comme son nom l'indique
1347
 * Returns:
1347
 * Returns:
1348
 * - String chaine formatee
1348
 * - String chaine formatee
1349
 * @author	::mastahbenus::
1349
 * @author	::mastahbenus::
1350
 * @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
1351
 * @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
1352
 */
1352
 */
1353
Number.prototype.formaterNombre = function (decimales, signe, separateurMilliers) {
1353
Number.prototype.formaterNombre = function (decimales, signe, separateurMilliers) {
1354
	var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
1354
	var _sNombre = String(this), i, _sRetour = "", _sDecimales = "";
1355
	
1355
	
1356
	function is_int(nbre) {
1356
	function is_int(nbre) {
1357
		nbre = nbre.replace(',', '.');
1357
		nbre = nbre.replace(',', '.');
1358
		return !(parseFloat(nbre)-parseInt(nbre) > 0);
1358
		return !(parseFloat(nbre)-parseInt(nbre) > 0);
1359
	}
1359
	}
1360
 
1360
 
1361
	if (decimales == undefined) {
1361
	if (decimales == undefined) {
1362
		if (is_int(_sNombre)) {
1362
		if (is_int(_sNombre)) {
1363
			decimales = 0;
1363
			decimales = 0;
1364
		} else {
1364
		} else {
1365
			decimales = 2;
1365
			decimales = 2;
1366
		}
1366
		}
1367
	}
1367
	}
1368
	if (signe == undefined) {
1368
	if (signe == undefined) {
1369
		if (is_int(_sNombre)) {
1369
		if (is_int(_sNombre)) {
1370
			signe = '';
1370
			signe = '';
1371
		} else {
1371
		} else {
1372
			signe = '.';
1372
			signe = '.';
1373
		}
1373
		}
1374
	}
1374
	}
1375
	if (separateurMilliers == undefined) {
1375
	if (separateurMilliers == undefined) {
1376
		separateurMilliers = ' ';
1376
		separateurMilliers = ' ';
1377
	}
1377
	}
1378
	
1378
	
1379
	function separeMilliers (sNombre) {
1379
	function separeMilliers (sNombre) {
1380
		var sRetour = "";
1380
		var sRetour = "";
1381
		while (sNombre.length % 3 != 0) {
1381
		while (sNombre.length % 3 != 0) {
1382
			sNombre = "0"+sNombre;
1382
			sNombre = "0"+sNombre;
1383
		}
1383
		}
1384
		for (i = 0; i < sNombre.length; i += 3) {
1384
		for (i = 0; i < sNombre.length; i += 3) {
1385
			if (i == sNombre.length-1) separateurMilliers = '';
1385
			if (i == sNombre.length-1) separateurMilliers = '';
1386
			sRetour += sNombre.substr(i, 3) + separateurMilliers;
1386
			sRetour += sNombre.substr(i, 3) + separateurMilliers;
1387
		}
1387
		}
1388
		while (sRetour.substr(0, 1) == "0") {
1388
		while (sRetour.substr(0, 1) == "0") {
1389
			sRetour = sRetour.substr(1);
1389
			sRetour = sRetour.substr(1);
1390
		}
1390
		}
1391
		return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
1391
		return sRetour.substr(0, sRetour.lastIndexOf(separateurMilliers));
1392
	}
1392
	}
1393
	
1393
	
1394
	if (_sNombre.indexOf('.') == -1) {
1394
	if (_sNombre.indexOf('.') == -1) {
1395
		for (i = 0; i < decimales; i++) {
1395
		for (i = 0; i < decimales; i++) {
1396
			_sDecimales += '0';
1396
			_sDecimales += '0';
1397
		}
1397
		}
1398
		_sRetour = separeMilliers(_sNombre) + signe + _sDecimales;
1398
		_sRetour = separeMilliers(_sNombre) + signe + _sDecimales;
1399
	} else {
1399
	} else {
1400
		var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
1400
		var sDecimalesTmp = (_sNombre.substr(_sNombre.indexOf('.')+1));
1401
		if (sDecimalesTmp.length > decimales) {
1401
		if (sDecimalesTmp.length > decimales) {
1402
			var nDecimalesManquantes = sDecimalesTmp.length - decimales;
1402
			var nDecimalesManquantes = sDecimalesTmp.length - decimales;
1403
			var nDiv = 1;
1403
			var nDiv = 1;
1404
			for (i = 0; i < nDecimalesManquantes; i++) {
1404
			for (i = 0; i < nDecimalesManquantes; i++) {
1405
				nDiv *= 10;
1405
				nDiv *= 10;
1406
			}
1406
			}
1407
			_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
1407
			_sDecimales = Math.round(Number(sDecimalesTmp) / nDiv);
1408
		}
1408
		}
1409
		_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
1409
		_sRetour = separeMilliers(_sNombre.substr(0, _sNombre.indexOf('.')))+String(signe)+_sDecimales;
1410
	}
1410
	}
1411
	return _sRetour;
1411
	return _sRetour;
1412
}
1412
}
1413
 
1413
 
1414
function debug(objet) {
1414
function debug(objet) {
1415
	var msg = '';
1415
	var msg = '';
1416
	if (objet != null) {
1416
	if (objet != null) {
1417
		$.each(objet, function (cle, valeur) {
1417
		$.each(objet, function (cle, valeur) {
1418
			msg += cle+':'+valeur + "\n";
1418
			msg += cle+':'+valeur + "\n";
1419
		});
1419
		});
1420
	} else {
1420
	} else {
1421
		msg = 'La variable vaut null.';
1421
		msg = 'La variable vaut null.';
1422
	}
1422
	}
1423
	console.log(msg);
1423
	console.log(msg);
1424
}
1424
}