/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////  LE SAVIEZ-VOUS ?    /////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$(document).ready(function() {		
//Execute the slideShow
slideShow();
});
function slideShow() {
//Set the opacity of all images to 0
$('#leSaviezVous_div p').css({opacity: 0.0});
//Get the first image and display it (set it to full opacity)
$('#leSaviezVous_div p:first').css({opacity: 1.0});
//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
setInterval('gallery()',6000);
}
function gallery() {
//if no IMGs have the show class, grab the first image
var current = ($('#leSaviezVous_div p.show')?  $('#leSaviezVous_div p.show') : $('#leSaviezVous_div p:first'));
//Get next image, if it reached the end of the slideshow, rotate it back to the first image
var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#leSaviezVous_div p:first') :current.next()) : $('#leSaviezVous_div p:first'));	
//Set the fade in effect for the next image, show class has higher z-index
next.css({opacity: 0.0})
.addClass('show')
.animate({opacity: 1.0}, 1000);
//Hide the current image
current.animate({opacity: 0.0}, 1000)
.removeClass('show');
//Set the opacity to 0 and height to 1px
$('#leSaviezVous_div .caption').animate({opacity: 0.0}, { queue:false, duration:50 }).animate({height: '1px'}, { queue:true, duration:300 });	
//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
$('#leSaviezVous_div .caption').animate({opacity: 0.7},100 ).animate({height: '100px'},500 );
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/**
* Autocompletion
*/

// Lorsque la totalité de la page est chargée
	$(document).ready(function() {
		function formatItem(row) {
			return row[0] + " (<strong>id: " + row[1] + "</strong>)";
		}
		function formatResult(row) {
			return row[0].replace(/(<.+?>)/gi, '');
		}

		/**
		 * Autocomplétion ville de départ
		 */
		idChampValue_depart = '#villeDepart_bis';
		idChampHiddenValue_depart = '#idVilleDepart_bis';
		idChampPaysValue_depart = '#paysDepart_bis';

		if($(idChampHiddenValue_depart).val() != '') {

			// A voir avec Patrice
//				GetLieuPublic($(idChampHiddenValue_depart).val(), '#idLieuDepart');

				/*if(param_get['idLieuDepart'] != '') {
					$('#idLieuDepart option[value=' + param_get['idLieuDepart'] + ']').attr("selected", "selected");
				}*/
		}

		$(idChampValue_depart).autocomplete("/ajax/geonames.php?action=SearchCityMemory", {
			width: 260,
			minChars: 3,
			selectFirst: true,
			delay: 200,
			cacheLength: 1,
			max: 150
		}).focus();
		/*,
			extraParams: {
				pays: function() { return $("#paysDepart").val(); }
			}*/

		$(idChampValue_depart).result(function(event, data_depart, formatted) {
			if (data_depart) {
				//Valeur du champ input après sélection
				$(idChampValue_depart).val(data_depart[2]);
				//Valeur de l'idVille après sélection
				$(idChampHiddenValue_depart).val(data_depart[1]);
				//Valeur de l'idPays après sélection
				$(idChampPaysValue_depart).val(data_depart[3]);

				//Lieu correspondant au Depart
				//GetLieuPublic($(idChampHiddenValue_depart).val(), '#idLieuDepart');
			}
		});

		/**
		 * Autocomplétion ville d'arrivée
		 */
		idChampValue_arrivee = '#villeArrivee_bis';
		idChampHiddenValue_arrivee = '#idVilleArrivee_bis';
		idChampPaysValue_arrivee = '#paysArrivee_bis';

		if($(idChampHiddenValue_arrivee).val() != '') {
						// A voir avec Patrice
            //GetLieuPublic($(idChampHiddenValue_arrivee).val(), '#idLieuArrivee');

				/*if(param_get['idLieuArrivee'] != '') {
					$('#idLieuArrivee option[value=' + param_get['idLieuArrivee'] + ']').attr("selected", "selected");
				}*/
		}

		$(idChampValue_arrivee).autocomplete("/ajax/geonames.php?action=SearchCityMemory", {
			width: 260,
			minChars: 3,
			selectFirst: true,
			delay: 200,
			cacheLength: 1,
			max: 150
		}).focus();

		$(idChampValue_arrivee).result(function(event, data_arrivee, formatted) {
			if (data_arrivee) {
				//Valeur du champ input après sélection
				$(idChampValue_arrivee).val(data_arrivee[2]);
				//Valeur de l'idVille après sélection
				$(idChampHiddenValue_arrivee).val(data_arrivee[1]);
				//Valeur de l'idPays après sélection
				$(idChampPaysValue_arrivee).val(data_arrivee[3]);

				//Lieu correspondant au Arrivee
				//GetLieuPublic($(idChampHiddenValue_arrivee).val(), '#idLieuArrivee');
			}
		});
	});
						   