
//--------------------------------------------------------------------
//-- Variables globales pour le slide show
//--------------------------------------------------------------------

	//-- Set slideShowSpeed (milliseconds)
	var slideShowSpeed = 4500;

	//-- Duration of crossfade (seconds)
	var crossFadeDuration = 3;

	//-- Specify the image files
	var Pic = new Array();	
	Pic[0] = './images/diapo/cerceaux.jpg';
	Pic[1] = './images/diapo/dos.jpg';
	Pic[2] = './images/diapo/saut-longueur.jpg';	
	Pic[3] = './images/diapo/poteaux.jpg';
	Pic[4] = './images/diapo/escabeau.jpg';
	Pic[5] = './images/diapo/salutation.jpg';
	Pic[6] = './images/diapo/agilite.jpg';

	var t;
	var j = 0;
	var p = Pic.length;


	//-- pre-Load slide show images.
	var preLoad = new Array();
	for (var i = 0; i < p; i++)
	{
		preLoad[i] = new Image();
		preLoad[i].src = Pic[i];
	}


//--------------------------------------------------------------------
//-- Defilement d'image (slide show)
//--------------------------------------------------------------------
function runSlideShow()
{
	var oBrowserElem = GetBrowserElem("SlideShow");

	if (oBrowserElem != null)
	{
	  oBrowserElem.style.filter="blendTrans(duration=2)";
	  oBrowserElem.style.filter="blendTrans(duration=crossFadeDuration)";
	  oBrowserElem.filters.blendTrans.Apply() ;
	}

	document.images.SlideShow.src = preLoad[j].src;

	if (oBrowserElem != null)
	{
	  oBrowserElem.filters.blendTrans.Play();
	}

	j = j + 1;
	if (j > (p-1)) j=0
	t = setTimeout('runSlideShow()', slideShowSpeed);
}


//--------------------------------------------------------------------
//-- Get the browser type element.
//--------------------------------------------------------------------
function GetBrowserElem(sElem)
{	
	//-- Netscape 6, Explorer 5	
	if (document.getElementById)
		{ return(document.getElementById(sElem)); }

	//-- IE4
	else if (document.all)
		{ return(document.all[sElem]); }
		
	//-- Netscape 4
	else if (document.layers)
		{ return(document.layers[sElem]); }
		
	//-- Nothing found.
	else
		{ return null; }
}

//--------------------------------------
//--------------------------------------
//-- album photo script
//--------------------------------------
//--------------------------------------

/* needed in standard mode */
px = function(x)
{
	return Math.round(x) + "px";
}

/* center image  - do not resize for perf. reason */
img_center = function(o)
{
	with(img[o])
	{
		style.left = px( - (width - Wi) / 2);
		style.top = px( - (height - Hi) / 2);
	}
}

//------------------------------------------
//------------------------------------------
function Cobj(o, x, y)
{
	this.o = o;
	this.ix = Math.min(Nx - Tx, Math.max(0, Math.round(x - (Tx / 2))));
	this.iy = Math.min(Ny - Ty, Math.max(0, Math.round(y - (Ty / 2))));
	this.li = ((this.ix * M + this.ix * Sx) - (x * M + x * Sx)) / SP;
	this.ti = ((this.iy * M + this.iy * Sy) - (y * M + y * Sy)) / SP;
	this.l = 0;
	this.t = 0;
	this.w = 0;
	this.h = 0;
	this.s = 0;
	this.mv = false;
	this.spa = spa[o].style;
	this.img = img[o];
	this.txt = img[o].alt;
	img[o].alt = "";

	/* zooming loop */
	this.zoom = function()
	{
		/* *** Centrer l'image a grossir *** */
		img_center(o);
		
		with(this)
		{
			l += li * s;
			t += ti * s;
			w += wi * s;
			h += hi * s;

			if ((s > 0 && w < Wi) || (s < 0 && w > Sx))
			{
				/* force window.event */
				window.focus();
				/* loop */
				setTimeout("obj[" + o + "].zoom()", 16);
			}
			else
			{
				/* finished */
				mv = false;
				/* set final position */

				/* *** Initialiser la position de l'image reduite *** */
				if (s == -2)
				{ 
					setImagePos(o);
					cap.innerHTML = captxt;

				}

				if (s > 0)
				{
					l = ix * M + ix * Sx;
					t = iy * M + iy * Sy;
					w = Wi;
					h = Hi;
				}
				else
				{
					l = x * M + x * Sx; // * 1.1;
					t = y * M + y * Sy; // * 1.1;
					w = Sx; // * 1.5;
					h = Sy; // * 1.5;
				}
			}

			/* html animation */
			with(spa)
			{
				left = px(l);
				top = px(t);
				width = px(w);
				height = px(h);
				zIndex = Math.round(w);
			}
		}
	}

	this.click = function()
	{
		with(this)
		{
			/* centrer l'image a grossir */
			img_center(o);

			/* zooming logic */
			if ( ! mv || cl)
			{
				if (s > 0)
				{
					if (cl || Math.abs(xm - xb) > Sx * .4 || Math.abs(ym - yb) > Sy * .4)
					{
						s =  - 2;
						mv = true;
						zoom();
						cap.innerHTML = txt;
					}
				}
				else
				{
					if (cl || ob != o)
					{
						if (ob >= 0)
						{
							with(obj[ob])
							{
								s =  - 2;
								mv = true;
								zoom();
							}
						}
					
						ob = o;
						s = 1;
						xb = xm;
						yb = ym;
						mv = true;
						zoom();
						cap.innerHTML = txt;
					}
				}
			}
		}
	}
	
	/* hook up events */
	//img[o].onmouseover = img[o].onmousemove = img[o].onmouseout = new Function("cl=false;obj[" + o + "].click()");
	img[o].onclick = new Function("cl=true;obj[" + o + "].click()");
	img[o].onload = new Function("img_center(" + o + ")");


	/* initial display */
	this.zoom();
}

//------------------------------------------
//-- mouse
//------------------------------------------
document.onmousemove = function(e)
{
	if ( ! e)
	{
		e = window.event;
	}
	xm = (e.x || e.clientX);
	ym = (e.y || e.clientY);
}

//------------------------------------------
//-- init
//------------------------------------------
function load()
{
	/* html elements */
	scr = document.getElementById("screen");
	spa = scr.getElementsByTagName("span");
	img = scr.getElementsByTagName("img");
	cap = document.getElementById("caption");
	captxt = cap.innerHTML;
	
	/* mouseover border */ 
	//document.getElementById("border").onmouseover = function()
	//{
	//	cl = true;
	//	if(ob >= 0 && obj[ob].s > 0) obj[ob].click();
	//	ob = -1;
	//}

	/* global variables */
	W = parseInt(scr.style.width);
	H = parseInt(scr.style.height);
	M = W / Mg;
	Sx = (W - (Nx - 1) * M) / Nx;
	Sy = (H - (Ny - 1) * M) / Ny;
	Wi = Tx * Sx + (Tx - 1) * M;
	Hi = Ty * Sy + (Ty - 1) * M;
	SP = M * Tx * SP;
	wi = (Wi - Sx) / SP;
	hi = (Hi - Sy) / SP;
	
	/* create objects */
	for (k = 0, i = 0; i < Nx; i ++)
	{
		for (j = 0; j < Ny; j ++)
		{
			obj[k] = new Cobj(k ++, i, j);
		}
	}
}


//--------------------------------------
//-- Pass -1 in intNoImg to affect all image
//--------------------------------------
function setImagePos(intNoImg)
{
  // all image
  if (intNoImg == -1)
  {
	var k=0;
	for (j = 0; j < Nx; j ++)
	{
		for (i = 0; i < Ny; i ++)
		{	
		  img[k].style.top="-30px";
		  img[k].style.left="-90px";	
		  k++;
		}
	}
  }
  // specific image
  else
  {
     img[intNoImg].style.top="-30px";
     img[intNoImg].style.left="-90px";
  }
}

// --------------------------
// -- Progress bar
// -- www.dhteumeuleu.com 
// --------------------------
function images_loading_bar(){
	m02=0;
	for(i=0;i<m01;i++)
	{
		m02+=(m00[i].complete)?1:0;
		document.getElementById("PB1").style.width=Math.round(m02/m01*150)+'px';
	}

	if(m02==m01) 
	{
		setTimeout("document.getElementById('PB0').style.display='none'",128); 
		document.getElementById('screen').style.display='block';
	}
	else 
	{
		setTimeout("images_loading_bar()", 64);
	}
};


//--------------------------------------
//-- END album photo script
//--------------------------------------

