//__SCRIPT.JS__
//Controls the image fading

//Controls the time it takes to fade an image in
var time = 800;

/***********************************************************
**
**  fadeImage(imageSrc)
**
**  With thanks to http://www.brainerror.net/ for the script.
**  This fades one image into another, using fade() to set
**  the CSS transparency values.
**
**  Sets the div's background to that of the old image, hides the old image,
**  sets the SRC of the old image ot that of the new image and finally fades
**  that image back in using setTimeout.
**
**  imageSrc :  The new image that will fade in
**
***********************************************************/

function fadeImage(imageSrc)
{
var speed = Math.round(time/100);
var divElement=parent.document.getElementById('divSwap');
var imageElement=parent.document.getElementById('imageSwap');

//Set div's background to old image
divElement.style.backgroundImage = "url("+parent.document.getElementById('imageSwap').src+")";

//Hide old image
fade('imageSwap',0);

//Change old image's SRC to new SRC
imageElement.src = imageSrc;

//Fade new image in gradually
for(var i=0;i<=100;i++)
  {
  setTimeout("fade('imageSwap','"+i+"')",(i*speed));
  }
divElement.style.backgroundImage = "url(photos/"+parent.document.getElementById('imageSwap').src+")";
}

/***********************************************************
**  
**  fade(opacity)
**
**  With thanks to http://www.brainerror.net/ for the script.
**  Changes the various opacity styles of the element to the
**  value specified in newOpacity
**
**  opacity :  The new opacity for the element
**  
***********************************************************/

function fade(id,opacity)
{
element=parent.document.getElementById(id).style;
element.opacity=(opacity/99);
element.MozOpacity=(opacity/100);
element.KhtmlOpacity=(opacity/100);
element.filter="alpha(opacity="+opacity+")";
}