Subversion Repositories eFlore/Applications.cel

Rev

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

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