// JavaScript Document

$(document).ready(function(){
					  

					  
	$(".gauche .search .rechercheGauche").keyup(function() {
		if($(this).val() == "" || $(this).val() == "toutes..."){
			actuVignettes("##ALL##");
		}	
			autocompletion($(this).val(), ".gauche .search");
	
	})

	
	$(".proposition").css({cursor:'pointer'})

	$(".proposition").hover(function(){
		$(this).addClass("propositionHover");
	},function(){
   		$(this).removeClass("propositionHover");
 	});
	
	propositions();


	

	
})

	function propoCliquable(){
		$(".proposition").click(function(){
									
			if ($(this).html()!="fermer le menu")
			{
			  $("#galerie .album").html('<img src="plugins/galerie/img/ajax/barre-rose.gif" alt="Chargement en cours">');
			  actuVignettes($(this).html());
			}
			else
			{
			 $(".propositions").fadeOut();
		     $(".rechercheGauche").val("");
			}
		})
	}


	function actuVignettes(tag){
		if (tag=="toutes...")
		{
			tag="";
		}
		
		$.ajax({
			type: "POST",
			url: "plugins/galerie/scripts/getGallerieByTag.php",
			data: "tag="+tag,
			success: function(msg){
				$("#galerie .album").html(msg);
				$("a[rel^='prettyPhoto']").prettyPhoto({theme:'dark_rounded'});
				propositions();
				hackTailles();
				initAlbum();
				$(".propositions").fadeOut();
				$(".rechercheGauche").val("");
			}
		});
		
				
	}



	function autocompletion(tag, element) {
		$.ajax({
			type: "POST",
			url: "plugins/galerie/scripts/getListByTag.php",
			data: "tag="+tag,
			success: function(msg){
				var el = element+".propositions";
				$(element+" .propositions").html(msg);
				propositions();
			}
		});
	}



	function propositions(){
		
		$(".proposition").hover(function(){
			$(this).addClass("propositionHover");
		},function(){
   			$(this).removeClass("propositionHover");
 		});
		if($(".propositions").html() == ""){
			$(".propositions").fadeOut();
		}else{
			$(".propositions").fadeIn();
		}
		
		var propos = $(".proposition");
		
		if(propos.length >10) {
			$(".propositions").height(12+200)
		}else{
			$(".propositions").height(12+20*propos.length)
		}
		
		propoCliquable()
		
		
	}
