

//------------------------------------------
//------------------------------------------
function OpenWin(strTargetPage, strPageName)
{
  var strFeature = "status=no,location=no,toolbar=yes," +
                   "directories=no,resizable=yes," +
                   "scrollbars=yes,width=800,height=600";

  window.open(strTargetPage,strPageName,strFeature);
}

//------------------------------------------
//------------------------------------------
function CloseWin()
{
  window.close();
}

//------------------------------------------
//------------------------------------------
function Button_mouseOver(strName)
{
	var strSrc;
	var oButton;
	
	strSrc = './images/m-' + strName + '-in.gif';
	oButton = GetBrowserElem(strName); 
	
	oButton.src = strSrc;
}

//------------------------------------------
//------------------------------------------
function Button_mouseOut(strName)
{
	var strSrc;
	var oButton;

	strSrc = './images/m-' + strName + '.gif';
	oButton = GetBrowserElem(strName); 

	oButton.src = strSrc;
}

//------------------------------------------
//-- 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; }
}

//------------------------------------------
//------------------------------------------
function DisplayPhoto(strName)
{
	var oElem;
	var strScr;

	strSrc = './images/albumphotos/' + strName;
	oElem = GetBrowserElem('imgphoto'); 
	oElem.src = strSrc;
	oElem.alt = strName + " ...";
	
	oElem= GetBrowserElem('photoone');
	oElem.style.display = "block";
	
	oElem= GetBrowserElem('photoall'); 
	oElem.style.display = "none";

}

//------------------------------------------
//------------------------------------------
function HidePhoto()
{
	var oElem;
	oElem= GetBrowserElem('photoone'); 
	oElem.style.display = "none";

	oElem= GetBrowserElem('photoall'); 
	oElem.style.display = "block";

	strSrc = "";
	oElem = GetBrowserElem('imgphoto'); 
	oElem.src = strSrc;

}

//------------------------------------------
//------------------------------------------
function PreviousNextPhoto(strPreviousNext)
{
	var oElem;
	var strScr;
      var intPreviousNext;

	oElem= GetBrowserElem('imgphoto');
	strSrc = oElem.src;

      intPreviousNext = 1;
	if (strPreviousNext.toLowerCase() == "p") { intPreviousNext = -1; }
	strSrc = FindPreviousNextFile(strSrc, intPreviousNext)
     
	oElem.src = strSrc;
	oElem.alt = "Photo - Bad Dogs ...";
}


//------------------------------------------
//------------------------------------------
function FindPreviousNextFile(strSrc, intPreviousNext)
{
	var strFileNameNumber;
	var intFileNameNumber;
	var strNextNumber;
	
	//-- Find photo number
      strFileNameNumber = strSrc.substring(strSrc.lastIndexOf("/")+2, strSrc.lastIndexOf("."));

	//-- Build next photo url
	intFileNumber = parseInt(strFileNameNumber) + intPreviousNext;

	if (intFileNumber  < 100)
	{ strNextNumber = "0" + intFileNumber; }

	if (intFileNumber  < 10)
	{ strNextNumber = "0" + strNextNumber; }

	strSrc = strSrc.replace(strFileNameNumber , strNextNumber );
	return(strSrc);
}


//--------------------------------------
//--------------------------------------
//-- 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="-90px";
		  img[k].style.left="-100px";	
		  k++;
		}
	}
  }
  // specific image
  else
  {
     img[intNoImg].style.top="-90px";
     img[intNoImg].style.left="-100px";
  }
}

// --------------------------
// -- 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
//--------------------------------------

