
object = new Array();
////////////////////
am = 40;
TEMPO = 4000;
///////////////////

LargeurDiv=600;//Recalculé à partir du calque PhotoCentrale
HauteurDiv=400;

LargeurDivVisu=600;//Recalculé à partir du calque Ciel
HauteurDivVisu=400;

AngleHoraire=0; //Angle global pour faire bouger les images en cercles

TailleMinPhoto=50;


K  = 0;
Kb = -1;



function IncrementAngle()
{
AngleHoraire+=.01
setTimeout("IncrementAngle()", 100);
}

function zoomIn(N)
{
	object[N].img.cursor="pointer";
	object[N].zoomIn();

}

function zoomOut(N)
{
	object[N].img.cursor="move";
	object[N].zoomOut();
}

function zyva(N)
{
	if(N!=Kb)
	{
	
	clearTimeout(object[Kb].TO);
	zoomIn(N);
	object[Kb].BR=true;
	zoomOut(Kb);
	Kb=N;
	}
}

function nextImg()
{
	if(Kb>=0)zoomOut(Kb);
	Kb=K%nbI;
	zoomIn(Kb);
	K++;
}

function CObj(N,img,NTotal)
{
	
	this.DecalageAngle=2*Math.PI*N/NTotal;

	this.k   = 0.1 * N;
	
	this.img = img.style;

	this.obj = "object["+N+"].";
	this.BR  = false;
	this.TO  = 0;
	this.TailleMinAtteinte=true;
	this.InitHeight = parseInt(img.height);	
	this.InitWidth = parseInt(img.width);

	this.Facteur= Math.min(TailleMinPhoto/this.InitHeight,TailleMinPhoto/this.InitWidth) ;	

	this.mainloop = function ()
	{
		with (this)
		{
			k += 0.001;
			
			
			with(img)
			{
				width  = Math.floor(InitWidth * Facteur);
				height = Math.floor(InitHeight * Facteur);
				if (TailleMinAtteinte) {
					top    = Math.floor((HauteurDiv-TailleMinPhoto)*(1+Math.cos(AngleHoraire+DecalageAngle))/2);
					left   = Math.floor((LargeurDiv-TailleMinPhoto)*(1+Math.sin(AngleHoraire+DecalageAngle))/2);
				}
				else	
				{//On centre progressivement l'image
					
					top = Math.floor( (HauteurDivVisu-parseInt(height))/2 );
					left= Math.floor( LargeurDiv+(LargeurDivVisu-parseInt(width))/2 );
				}

			}
			setTimeout(obj+"mainloop();", 100);
		}
	}
	this.zoomIn  = function()
	{
		with (this)
		{ 	
			TailleMinAtteinte=false;	
			if(!BR)
			{	
				if((parseInt(img.width)>(LargeurDivVisu-2*TailleMinPhoto))||(parseInt(img.height)>(HauteurDivVisu-2*TailleMinPhoto)))
				{
									
					TO=setTimeout("nextImg();", TEMPO);
				}
				else 
					{
					Facteur +=.1 ;
					
					setTimeout(obj+"zoomIn();", 32);
					}
			}
		}
	}
	this.zoomOut  = function()
	{
		with (this)
		{
			
			
			if((parseInt(img.width)>=TailleMinPhoto)&&(parseInt(img.height)>=TailleMinPhoto)) 
				{
				if (Facteur>0.11) Facteur -=.1 ;
				setTimeout(obj+"zoomOut();", 32);
				}
			else
			{	TailleMinAtteinte=true;	
				BR=false;
				//img.zIndex=1;
			}
		}
	}
	
	this.mainloop();
}


function DisplayPics()
{
	
	DivPhotoCentrale=document.getElementById("PhotoCentrale");
	DivCiel=document.getElementById("Ciel");
	DivArbre=document.getElementById("Arbre");

	LargeurDiv=parseInt(DivCiel.currentStyle.left);
	HauteurDiv=DivPhotoCentrale.clientHeight;


	LargeurDivVisu=DivCiel.clientWidth;
	HauteurDivVisu=DivPhotoCentrale.clientHeight;

	img = DivPhotoCentrale.getElementsByTagName("img");
	nbI = img.length;

	for(i=0;i<nbI;i++) 
		{
			object[i] = new CObj(i,img[i],nbI);
			//img[i].onclick=function(){"zyva("+i+")"};
			

		}
	nextImg();
	DivPhotoCentrale.style.visibility='visible';
	IncrementAngle();
}


