ImageRotater = function() {
// Add you image paths to this array
var images = new Array('image01.jpg', 'image02.jpg', 'image03.jpg');
var v = {
id: 'theImg', // the id attribute of the image
wait: 5000, // time in between rotate in milliseconds
// don't change below
img: null,
spot: 0,
len: images.length-1
};
Init = function() {
v['img'] = document.getElementById(v['id']);
// preload images
for (var x=0, y=images.length; x<y; x++) {
var i = new Image();
i.src = images[x];
}
setTimeout(function(){Rotate()}, v['wait']);
};
Rotate = function() {
v['spot'] = (v['spot'] >= v['len']) ? 0 : ++v['spot'];
v['img'].src = images[v['spot']];
setTimeout(function(){Rotate()}, v['wait']);
};
function appendOnLoad(fx)
{
var old = window.onload;
if (typeof old != 'function') { window.onload = fx; }
else { window.onload = function() { old(); fx(); } }
}
appendOnLoad(Init);
}();