var DEPARTEMENT = '';
var LISTE_DEPARTMENT_EN_DIV = false; // Si liste departement en div et non en selec
var count = 1;

window.addEvent('domready', function() {

	var myImages = new Asset.images(
		['/media/site/image/box/bt-etape.gif',
		'/media/site/image/box/n1.png',
		'/media/site/image/box/n2.png',
		'/media/site/image/box/n3.png',
		'/media/site/image/box/n4.png',
		'/media/site/image/box/bt-valider.gif',
		'/media/site/image/box/bt-ajout-trajet.gif',
		'/media/site/image/box/bt-ajout-vehic.gif']
	);

	// Instanciation de l'objet ecoov
	var options = {
		libMonCompte: 'Mon compte ...'
	}

	// Calendrier
	if(!$('corps')) {
		ecoov = new eModule();

		ecoov.critereDate();

		var el = $('slider'), stateSilder = 0;

		// Create the new slider instance
		var slideRayon = new Slider(el, el.getElement('.curseur'), {
			steps: 9,
			range: [1, 11],
			wheel: true,
			onChange: function(value){
				$('affichePerimetre').set('text', value);
			},
			onComplete: function(value){

				radiusA = value;
				radiusB = value;

				$('rayonDepart').getChildren().each(function(el){
					if(el.value == value) el.setProperty('selected', 'selected');
				});

				$('rayonDestination').getChildren().each(function(el){
					if(el.value == value) el.setProperty('selected', 'selected');
				});

				// On supprimer la couche de rayon
				if(stateSilder != 0) {

					if(searchAreaHighlight_depart)  {
						map.removeOverlay(searchAreaHighlight_depart);
						map.removeOverlay(searchAreaHighlight_destination);
					}

					if(waypoints[0]) {
						var circlePoints_depart = drawCircle(waypoints[0].getLatLng(),value,'KM');
						searchAreaHighlight_depart = new GPolygon(circlePoints_depart, 'blue', 2 , 0.5 , '#CCC000', 0.10);
						map.addOverlay(searchAreaHighlight_depart);

						var circlePoints_destination = drawCircle(waypoints[waypoints.length-1].getLatLng(),value,'KM');
						searchAreaHighlight_destination = new GPolygon(circlePoints_destination, 'green', 2 , 0.5 , '#00C000', 0.10);
						map.addOverlay(searchAreaHighlight_destination);

						mgr.clearMarkers();

						ecoov.trouverParCarte((waypoints[0].getLatLng()).lat(), (waypoints[0].getLatLng()).lng(), (waypoints[waypoints.length-1].getLatLng()).lat(), (waypoints[waypoints.length-1].getLatLng()).lng(), value, value);
						ecoov.covDansRayon((waypoints[0].getLatLng()).lat(), (waypoints[0].getLatLng()).lng(), (waypoints[waypoints.length-1].getLatLng()).lat(), (waypoints[waypoints.length-1].getLatLng()).lng(), value, value);
					}
				}

				stateSilder = 5;

			}
		});

		slideRayon.set(5);

		$('rayonDepart').addEvent('change', function(e) {
			slideRayon.set($('rayonDepart').value);
		});

		$('rayonDestination').addEvent('change', function(e) {
			slideRayon.set($('rayonDestination').value);
		});

	}
	
	
	if($('zone_actu_flash')) {
  
		var doMany = function() {
		
			var count_ = count;
		
			var request = new Request({
				url: '/includus/php/gestion_actu_bandeau.php?count='+count_,
				method: 'get',
				update: 'zone_actu_flash',
				onComplete: function(response) {
					if(response != '') {
						count++;
					} else {
						count = 1;
						response = 'Site de covoiturage du Conseil g&eacute;n&eacute;ral du Gers';
					}
					$('zone_actu_flash').set('html',response);
				}
			}).send();
		};

		doMany.periodical(6000);
	
	}
	
		//ouverture fermeture carto CG29
// CLICK SUR RECHERCHE
		if($('rechercheCarte')) {
			$('rechercheCarte').addEvent('click', function() {
				$('carte').style.display = 'block';
				$('affinerRayon').style.display = 'block';
				$('carte2').style.display = 'none';
				$('rechercheCarte').style.color 	 = '#000';
				$('rechercheCarte').style.background = 'none';
				$('affichageCarte').style.color 	 = '#FFF';
				$('affichageCarte').style.background = 'transparent url(/media/site/image/fond-carte-affichage.gif) no-repeat scroll 0 0';
			}.bind(this));
		}
		
// CLICK SUR Affichage
		if($('affichageCarte')) {
			$('affichageCarte').addEvent('click', function() {										   
				$('carte').style.display = 'none';
				$('affinerRayon').style.display = 'none';
				$('carte2').style.display = 'block';

				
				$('rechercheCarte').style.color 	 = '#FFF';
				$('rechercheCarte').style.background = 'transparent url(/media/site/image/fond-carte-recherche.gif) no-repeat scroll 0 0';
				$('affichageCarte').style.color 	 = '#000';
				$('affichageCarte').style.background = 'none';
				
			}.bind(this));
		}	
	
	//fin ouverture fermeture carto
		
	if($('retourAccueil')) {
		$('retourAccueil').addEvent('click', function() {
			
			
			//window.location.replace('http://www.cg32.fr/');
			 window.open('http://www.cg32.fr/',"CG32","menubar=yes, status=yes, scrollbars=yes, menubar=yes, width=900, height=800");
		}.bind(this));
	};
	
});

