

var Pic = new Array();
var Pic2 = new Array();

function inizializza_slide(w,h){


	 $("#foto li a").each(function(i){
	   Pic2[i] = $(this).attr("href");
		
	});

	 $("#foto img").each(function(i){
		Pic[i] = $(this).attr("src");
		
	});



 
p = Pic.length;
preLoad = new Array()

for (i = 0; i < p; i++){
   preLoad[i] = new Image()
   preLoad[i].src = Pic[i]
   
   
}


		$("#foto").append("<a href=\""+Pic2[0]+"\"><div id=\"immagini\"><img  id=\"slide\" src=\""+Pic[0]+"\" /></div></a>");
	$("#immagini").animate({  width: w+"px",height:h+"px"}, 0,function(){});
	$("#immagini").append("<img  id=\"SlideShow\" src=\""+Pic[0]+"\" />");
	//$("#SlideShow").animate({  width: w+"px",height:h+"px"}, 0);
	//$("#slide").animate({  width: w+"px",height:h+"px"}, 0);
  $('#foto a').lightBox();
$("#foto").fadeIn();

	cambia2();
	
	}
  
  
var l = -1;
var i =-1;


var lx = -0;
var tx =0;


var vai =0;
function chiudi()
{
$("#slide").attr({ src: preLoad[l].src});

$('#slide').animate({left:lx,top:tx}, 0);


if(vai==0){window.setTimeout('cambia()',1000);}
}
 
function cambia(){
if(vai==0){$('#SlideShow').fadeOut("slow", cambia2);
			$('#SlideShow').animate({left:0, top:0}, 0);
	}

}

function cambia2(){
  l = l + 1
   if (l > (p-1)) l=0
   
$("#SlideShow").attr({ src: preLoad[l].src});
$("#foto a").attr({ href: Pic2[l]});
if(vai==0){$('#SlideShow').fadeIn("slow", function(){$('#SlideShow').animate({left:lx,top:tx,
       
        opacity: 1.0
      }, 1000, chiudi);
});}
}
