// JavaScript Document

function randomNumber(limit){
  return Math.floor(Math.random()*limit);
}


// <img src="originalImage1.gif" name="slide1">
var mySlideList1 = ['/images/sidebar/1.jpg', '/images/sidebar/2.jpg', '/images/sidebar/3.jpg', '/images/sidebar/4.jpg', '/images/sidebar/5.jpg'];
var mySlideShow1 = new SlideShow(mySlideList1, 'image1', 30000, "mySlideShow1");

function SlideShow(slideList, image, speed, name)          
{
  this.slideList = slideList;
  this.image = image;
  this.speed = speed;
  this.name = name;
  this.current = 0;
  this.timer = 0;
}
SlideShow.prototype.play = SlideShow_play;  
function SlideShow_play()       
{
  with(this)
  {
    oldcurrent = current
	current = randomNumber(slideList.length)
	if (oldcurrent==current) {current = randomNumber(slideList.length);}
    switchImage(image, slideList[current]);
    clearTimeout(timer);
    timer = setTimeout(name+'.play()', speed);
  }
}
function switchImage(imgName, imgSrc) 
{
  if (document.images)
  {
    if (imgSrc != "none")
    {
		fadeimage(imgName, imgSrc)
    }
  }
}

function fadeimage(id, newsrc) {
setopacity2(id, 100, 0, 200)
setTimeout("document.images['" + id + "'].src = '" + newsrc + "';", 200)
setTimeout("setopacity2('" + id + "', 0, 100, 300)", 200)
}

function setopacity2(id, opacstart, opacend, millisec) {
//milliseconds per frame
framerate = 50

//find difference between old and new opacity values
interval = Math.abs(opacend-opacstart)
//the number of steps to take every framerate milliseconds
timer = Math.round(millisec/framerate)
stepspermillisec = interval/timer
for(i=0;i<=(timer-1);i++) {
//check if the new opac is bigger, or smaller than the old one, if it's bigger, the
//script will add to the old opac, if it's smaller, it will subtract
if(opacstart<opacend){
j = Math.round(opacstart+(i+1)*stepspermillisec)
}
if(opacstart>opacend) {
j = Math.round(opacstart-(i+1)*stepspermillisec)
}
//use settimeout function to set the value in increments every tenth of a second.
setTimeout("changeOpac('" + j + "', '" + id + "')",(framerate*i));
}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}