// vars
var imageDir;
var currentIndex = 0;
var imageCount = 5;
var interval = 3000;
var step = 0;
var fromImage;
var toImage;
var trans;
var transStepDur = 100;

function initTransitions(img1Id, img2Id, imgDir, imgCnt, intervalDuration, transStepDuration)
{

imageCount = imgCnt;

// get random start index
currentIndex = rand(imageCount);

imageDir = imgDir;
fromImage = document.getElementById(img1Id);
toImage = document.getElementById(img2Id);
fromImage.src = imageDir + getNextIndex() + '.jpg';
// assume previous load
//toImage.src = imageDir + currentIndex + '.jpg';
toImage.className = 'Fade10';
interval = intervalDuration * 1000;
transStepDur = transStepDuration * 1000;

// setup the first transition
window.setTimeout('doNextTransition()', interval);

}
function doTransition()
{

// set img
//toImage.src = imageDir + currentIndex + '.jpg';

// reset step
step = 0;

// do transition steps
trans = window.setInterval('doTransitionStep()', transStepDur);

}
function doTransitionStep()
{
// bump step
step++;

if(step <= 10)
{
fromImage.className = 'Fade' + (10 - step);
toImage.className = 'Fade' + step;
}
else
{

// clear this interval
window.clearInterval(trans);

// pre-load next image.
fromImage.src = imageDir + getNextIndex() + '.jpg';

// setup the next transition
window.setTimeout('doNextTransition()', interval);
}
}
function doNextTransition()
{
// swap
var temp = toImage;
toImage = fromImage;
fromImage = temp;

// update index
currentIndex = getNextIndex();

// do next transition
doTransition();
}
function getNextIndex()
{
if(currentIndex >= imageCount - 1)
{
return 0;
}
else
{
return currentIndex + 1;
}
}

rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd() {
rnd.seed = (rnd.seed*9301+49297) % 233280;
return rnd.seed/(233280.0);
};

function rand(number) {
return Math.ceil(rnd()*number);
};