$(document).ready(function() {
	
	  $.blockUI.defaults.message = 'loading<br /><br /><img src="'+template_url+'/images/ajax-loader.gif" />';

	  $.blockUI.defaults.css = {
	    width: '250px',
	    padding: '10px',
	    textAlign: 'center',
	    backgroundColor: 'transparent',
	    color: '#808080',
	    'font-size': '14px',
	    'font-weight': 'bold'
	  };

	  $.blockUI.defaults.overlayCSS = {
	    backgroundColor: '#F1F1F3',
	    opacity: '0.9'
	  };	

	browse_images = function() {
		$('#int-forward').click(function() {
			var gallery_id = $("#int-forward").attr("rel");
			$(".img").block();
			
			$.ajax({
				type: "GET",
				url: $(this).attr("href"),
				data: { "ajax": "true" , "fangallery_id": gallery_id },
				success: function(data) {
					//foto.php mi ha costretto a scrivere questo :(
					$("#img").remove();
					$(".clear").remove();
					$(".clear high").remove();
					$(data).insertBefore('.adv-line');
					$("<div class='clear'></div><div class='clear high'></div>").insertAfter("#social");
					$("<div class='clear high'></div>").insertAfter("#foto-aperta");
					$("<div class='clear'></div>").insertAfter(".photo-info-right");
					$("<div class='clear high'></div>").insertAfter(".advbottom");
					$('.photo-info').before("<div class='clear high'></div>");
					
					//aggiorno iframe banner
					$(".ajax-iframe").each( function() {
						$(this).attr('src', $(this).attr("src"));
					});
					
					$(".img").unblock();
					
					browse_images();
				}
			});
			
			return false;
		});
		
		$('#int-back').click(function() {
			var gallery_id = $("#int-back").attr("rel");
			$(".img").block();
			
			$.ajax({
				type: "GET",
				url: $(this).attr("href"),
				data: { "ajax": "true" , "fangallery_id": gallery_id },
				success: function(data) {
					//foto.php mi ha costretto a scrivere questo :(
					$("#img").remove();
					$(".clear").remove();
					$(".clear high").remove();
					$(data).insertBefore('.adv-line');
					$("<div class='clear'></div><div class='clear high'></div>").insertAfter("#social");
					$("<div class='clear high'></div>").insertAfter("#foto-aperta");
					$("<div class='clear'></div>").insertAfter(".photo-info-right");
					$("<div class='clear high'></div>").insertAfter(".advbottom");
					$('.photo-info').before("<div class='clear high'></div>");
					
					//aggiorno iframe banner
					$(".ajax-iframe").each( function() {
						$(this).attr('src', $(this).attr("src"));
					});
					
					$(".img").unblock();
					
					browse_images();
				}
			});
			
			return false;
		});		
	}

	
	browse_images();
	
});