	//---
	// Document chargé
	//---
	function thumbnailHoverIn() {
		$(this).find('span').fadeIn(350);
	}
	function thumbnailHoverOut() {
		$(this).find("span").fadeOut(180);
	}
	jQuery.fn.fadeToggle = function(speed, easing, callback) {
		return this.animate({opacity: 'toggle'}, speed, easing, callback);  
	};
	
	$(document).ready(function() {

		//---
		// Click sur "back/retour"
		//---
		$('.linkBack').click(function () {
			history.go(-1);
		});

		//---
		// Click sur "imprimer"
		//---
		$('.articleToolPrint').click(function () {
			window.print();
		});


		//---
		// Click sur une langue = switch d'une langue à l'autre
		//---
		$(".change_langue").click(function(){
			nouvelle_langue = $(this).attr('value');
			$.ajax({
				type: "POST",
				url: "_ajaxrequest/saveData.php",
				data: "action=switch_langue&langue=" + nouvelle_langue,
				success: function(msg) {
					self.location.reload();
				},
				error : function (data) {
					alert('Erreur Ajax :: reload langue' + data.error());
				}
			});
		});

		//---
		// Thumbnail Hover View
		//---
/*
		$(".vignette").click(function(){
			return false;
		});
*/
		var thumbnailHoverConfig = {    
			sensitivity: 9, // number = sensitivity threshold (must be 1 or higher)    
			interval: 100, // number = milliseconds for onMouseOver polling interval    
			over: thumbnailHoverIn, // function = onMouseOver callback (REQUIRED)    
			timeout: 100, // number = milliseconds delay before onMouseOut    
			out: thumbnailHoverOut // function = onMouseOut callback (REQUIRED)    
		};
		$(".vignette").hoverIntent(thumbnailHoverConfig);

		//---
		// Categories Expandable tag-lists
		//---
		$(".photothequeCategory").treeview({
			animated: "350",
			persist: "cookie",
			cookieId: "treeview-black",
			collapsed: true
		});
			
		
		//---
		// Search Filter Options Toggle View
		//---
		$(".photothequeSearchFilter").click(function() {
			if ($.trim($("#photothequeSearch dd").text()) == "") {
				$("#photothequeSearch dd").load("plusOptionMoteur.php", {}, function() {
					//--
					// on change
					//---
					$('select.categorieSelect').change(function () {
						var categorieMereId = $(this).val();
						var newNiveau = 0;

						if( $(this).attr('id') == "categoriesNiveau1" ) {
							newNiveau = 2;
						} else if( $(this).attr('id') == "categoriesNiveau2" ) {
							newNiveau = 3;
						} else if ( $(this).attr('id') == "categoriesNiveau3" ) {
							newNiveau = 4;
						}

						if( newNiveau == 0 ) {
							return;	// Rien à faire pour les catégories de niveau 4 vu que pas de sous enfant
						}

						for(i = newNiveau; i <= 4; i++) {
							$('#categoriesNiveau' + i).html('');	// vide
						}

						if( categorieMereId != -1 ) {
							//---
							// Appel ajax pour sourcer depuis la catégorie sélectionnée
							//---
							$.ajax({
								type	:	"POST",
								url		:	"_ajaxrequest/loadData.php",
								data	:	"action=getCategoriesFilles&categorieMereId=" + categorieMereId + "&selectName=categorie_id" + newNiveau + "&selectId=categoriesNiveau" + newNiveau + "&newNiveau=" + newNiveau,
								success: function(result) {
									if( result != -1 ) {
										if ( result != '' ) {
											$('#categoriesNiveau' + newNiveau).html( result );
										}
									} else {
										alert('Erreur :'+ result);
									}
								}
							});
						}
					});
				});
			}
			$("#photothequeSearch dl").fadeToggle();
			$(".photothequeSearchFilter span").fadeToggle();
//			if ($("#photothequeSearch dl").is(":hidden")) {
//				$(".photothequeSearchFilter").text("Moins d'options");
//			} 
			return false;
		});		

/*
		//---
		// Hover sur la colonne gauche
		//---
		$(".col_gauche_mp, .col_gauche_mo").hover(function(){
				$(this).addClass("mhover"); 
			}, function(){
				$(this).removeClass("mhover"); 
			});
*/

		//---
		// Click sur un filtre de recherche = change le statut de la checkbox + change une vrai checkbox hidden
		//---
		$(".search_wrapper a").click(function(){
			$(this).toggleClass("active");
			var hiddenCheckbox = $(this).next("input:checkbox");
			if ( $(hiddenCheckbox).is(':checked')) {
				$(hiddenCheckbox).attr("checked","");
			} else {
				$(hiddenCheckbox).attr("checked",true);
			}
			return false;
		});

	});
