var $jQLightbox = jQuery.noConflict();

$jQLightbox(function(){
	
	//press key avanti indietro
	$jQLightbox(document).keydown(function(event){	
	
		var idchecked=$jQLightbox("input[name^='lb-gallery']:checked.lb-inputimg").attr("id");
		//console.log(idchecked);
			
		if(idchecked)
			{			
			var parentThumb=$jQLightbox("#"+idchecked).parents(".lb-thumb");

			if (event.keyCode == 37) 
				{ 
				//console.log("Indietro");					
				var inputimg=parentThumb.prev(".lb-thumb").find(".lb-inputimg").prop("checked", true);
				
				if(inputimg.length>0)
					{
					inputimg.prop("checked", true);
					}
				else
					{
					//console.log("fine riga");
					
					var parentAlbum=parentThumb.parents(".lb-album");
					var album=parentAlbum.prev(".lb-album");
					
					if(album.length==0)
						{
						//console.log("riga last");
							
						var album=parentAlbum.parents(".lb-gallery").find(".lb-album").last();
						}
						
					
					var inputimg=album.find("div.lb-thumb").last().find(".lb-inputimg");
					inputimg.prop("checked", true);
					}
				}
			if (event.keyCode == 39) 
				{ 
				//console.log("Avanti");		
				var inputimg=parentThumb.next(".lb-thumb").find(".lb-inputimg");
				
				if(inputimg.length>0)
					{
					inputimg.prop("checked", true);
					}
				else
					{
					//console.log("fine riga");
					
					var parentAlbum=parentThumb.parents(".lb-album");
					var album=parentAlbum.next(".lb-album");
					
					if(album.length==0)
						{
						//console.log("riga first");
							
						var album=parentAlbum.parents(".lb-gallery").find(".lb-album").first();
						}
						
					
					var inputimg=album.find("div.lb-thumb").first().find(".lb-inputimg");
					inputimg.prop("checked", true);
					}
				}
			}	
		
	});		
	
	
	

	$jQLightbox(".lb-gallery-slide-freccia").click(function (e)
		{	
		var Hchiuso=$jQLightbox( ".lb-gallery-slide").attr("data-Hchiuso");
			console.log(Hchiuso);	
		if ($jQLightbox( ".lb-gallery-slide-freccia").html()=="keyboard_arrow_down") 
			{
		  	$jQLightbox( ".lb-gallery-slide").css({"height":"auto"});
		  	$jQLightbox( ".lb-gallery-slide-freccia").html("keyboard_arrow_up");
			} 
		else
			{
		  	$jQLightbox( ".lb-gallery-slide").css({"height":Hchiuso});
		  	$jQLightbox( ".lb-gallery-slide-freccia").html("keyboard_arrow_down");
			}
		});
});