var tfoto;
var fotoload;

var MyIMG;


document.observe( "dom:loaded" , configFoto )

function configFoto()
{

	$("MyThumbs").select("a").each(function(vLink) {

		vURL = vLink.readAttribute("href");
		vLink.writeAttribute("href" , "#album" );
		vLink.writeAttribute("Figura" , vURL );

		vLink.observe('click', function(event){

			myOBJ = Event.element(event);

			if( myOBJ.inspect() == "<img>" ) 
			{
				myOBJ = myOBJ.up("a");
			}

			vURL = myOBJ.readAttribute("Figura");
			MudaFoto(vURL)
		 });

	});

	setTimeout( "checkInit()" , 1 );

}


function checkInit()
{
	/* retorna true se todos os thumbs estiverem  carregador */

	if( $("MyThumbs").select("img").all( function( Imagem ) { return Imagem.complete } ) )
		{$("LoadThumb").style.display = "none";}		
	else 
		{setTimeout( "checkInit()" , 100 );}
}

function MudaFoto( caminho )
{

	if(fotoload)
	   	{clearTimeout(fotoload);}
	$("LoadFoto").style.display = "block";
	MyIMG = new Image()
	MyIMG.src = caminho;
	
	tfoto = setTimeout( "checkload()" , 1 );

}


function checkload() {
	if( MyIMG.complete )
		{
			$("foto_principal").src = MyIMG.src;
			$("LoadFoto").style.display = "none";
		}
	else
		{tfoto = setTimeout( "checkload()" , 20 );}
}