var valprevid = '';
var valnexid = '';
var succ = "succ";
var prev = 'prev';
var massimo = '';

function carica_gallery(id,idpuls){
	
	if(valprevid != '' && idpuls == 'prec'){
		id = valprevid;
	}
	
	if(valnexid != '' && idpuls == 'succ'){
		id = valnexid;
	}
	
	$.get("/tre/file_che_carica.php?IDGall="+id,function(res){
		
		
		t = 0;
		$(res).find('titolo').each(function(){
			if(t == 0){
				$("#titolo_gallery").text($(this).text());
				$("#titolo_gallery").attr("href","/sito/gallery/"+id+"/gallery.php");
			}			
		})
		
		$("#imgBigGallery").attr("src","/gallery/grandi/"+$(res).find("foto[n='0']").text());
		
		if($(res).find("foto[n='1']").text() != ''){
			$("#thumb-foto-1 a").attr("fotogrande","/gallery/grandi/"+$(res).find("foto[n='1']").text());
			$("#thumb-foto-1 img").attr("src","/tre/js/timthumb.php?src=/gallery/mini/"+$(res).find("foto[n='1']").text()+"&h=60&w=60&q=100&zc=1");	
		}else{
			$("#thumb-foto-1 a").attr("fotogrande","/gallery/grandi/nophotobig.gif");
			$("#thumb-foto-1 img").attr("src","/gallery/mini/nophoto.gif");	
		}
		
		if($(res).find("foto[n='2']").text() != ''){
			$("#thumb-foto-2 a").attr("fotogrande","/gallery/grandi/"+$(res).find("foto[n='2']").text());
			$("#thumb-foto-2 img").attr("src","/tre/js/timthumb.php?src=/gallery/mini/"+$(res).find("foto[n='2']").text()+"&h=60&w=60&q=100&zc=1");	
		}else{
			$("#thumb-foto-2 a").attr("fotogrande","/gallery/grandi/nophotobig.gif");
			$("#thumb-foto-2 img").attr("src","/gallery/mini/nophoto.gif");	
		}
		
		if($(res).find("foto[n='3']").text() != ''){
			$("#thumb-foto-3 a").attr("fotogrande","/gallery/grandi/"+$(res).find("foto[n='3']").text());
			$("#thumb-foto-3 img").attr("src","/tre/js/timthumb.php?src=/gallery/mini/"+$(res).find("foto[n='3']").text()+"&h=60&w=60&q=100&zc=1");	
		}else{
			$("#thumb-foto-3 a").attr("fotogrande","/gallery/grandi/nophotobig.gif");
			$("#thumb-foto-3 img").attr("src","/gallery/mini/nophoto.gif");	
		}
		
		if($(res).find("foto[n='4']").text() != ''){
			$("#thumb-foto-4 a").attr("fotogrande","/gallery/grandi/"+$(res).find("foto[n='4']").text());
			$("#thumb-foto-4 img").attr("src","/tre/js/timthumb.php?src=/gallery/mini/"+$(res).find("foto[n='4']").text()+"&h=60&w=60&q=100&zc=1");	
		}else{
			$("#thumb-foto-4 a").attr("fotogrande","/gallery/grandi/nophotobig.gif");
			$("#thumb-foto-4 img").attr("src","/gallery/mini/nophoto.gif");	
		}
		
		if($(res).find("foto[n='5']").text() != ''){
			$("#thumb-foto-5 a").attr("fotogrande","/gallery/grandi/"+$(res).find("foto[n='5']").text());
			$("#thumb-foto-5 img").attr("src","/tre/js/timthumb.php?src=/gallery/mini/"+$(res).find("foto[n='5']").text()+"&h=60&w=60&q=100&zc=1");	
		}else{
			$("#thumb-foto-5 a").attr("fotogrande","/gallery/grandi/nophotobig.gif");
			$("#thumb-foto-5 img").attr("src","/gallery/mini/nophoto.gif");	
		}
		
		if($(res).find("foto[n='6']").text() != ''){
			$("#thumb-foto-6 a").attr("fotogrande","/gallery/grandi/"+$(res).find("foto[n='6']").text());
			$("#thumb-foto-6 img").attr("src","/tre/js/timthumb.php?src=/gallery/mini/"+$(res).find("foto[n='6']").text()+"&h=60&w=60&q=100&zc=1");	
		}else{
			$("#thumb-foto-6 a").attr("fotogrande","/gallery/grandi/nophotobig.gif");
			$("#thumb-foto-6 img").attr("src","/gallery/mini/nophoto.gif");	
		}
		
		if($(res).find("foto[n='7']").text() != ''){
			$("#thumb-foto-7 a").attr("fotogrande","/gallery/grandi/"+$(res).find("foto[n='7']").text());
			$("#thumb-foto-7 img").attr("src","/tre/js/timthumb.php?src=/gallery/mini/"+$(res).find("foto[n='7']").text()+"&h=60&w=60&q=100&zc=1");	
		}else{
			$("#thumb-foto-7 a").attr("fotogrande","/gallery/grandi/nophotobig.gif");
			$("#thumb-foto-7 img").attr("src","/gallery/mini/nophoto.gif");	
		}
		
		if($(res).find("foto[n='8']").text() != ""){
			$("#thumb-foto-8 a").attr("fotogrande","/gallery/grandi/"+$(res).find("foto[n='8']").text());
			$("#thumb-foto-8 img").attr("src","/tre/js/timthumb.php?src=/gallery/mini/"+$(res).find("foto[n='8']").text()+"&h=60&w=60&q=100&zc=1");	
		}else{
			$("#thumb-foto-8 a").attr("fotogrande","/gallery/grandi/nophotobig.gif");
			$("#thumb-foto-8 img").attr("src","/gallery/mini/nophoto.gif");	
		}
		
		
		
		valprevid = $(res).find("previd").text();
		valnexid = $(res).find("nextid").text();
		massimo = $(res).find("maxid").text();
		
		if(valnexid != ''){
			
			$("#puls_next_id").html("<a href='javascript:void(0)' id='succ' onclick='carica_gallery("+valnexid+","+succ+")'><img src='/tre/images/nextgallery.gif' width='16' height='16' /></a>")
		}else{
			$("#puls_next_id").html("<a href='javascript:void(0)' id='succ' onclick='carica_gallery(9073,"+succ+")'><img src='/tre/images/nextgallery.gif' width='16' height='16' />");
		}
		
		if(valprevid != ''){
			
			$("#puls_prev_id").html("<a href='javascript:void(0)' id='prev' onclick='carica_gallery("+valprevid+","+prev+")'><img src='/tre/images/prevgallery.gif' width='16' height='16' /></a>")
		}else{
			$("#puls_prev_id").html("<a href='javascript:void(0)' id='succ' onclick='carica_gallery("+massimo+" ,"+prev+")'><img src='/tre/images/prevgallery.gif' width='16' height='16' /></a>");
		}
		
	})
	
}



