var featuredImages = [];
var featuredImageCount = -1;

function rotateimage(featuredImages, i) {
	featuredImages[i].rotateImage();
}

function FlippinImage(randomImages) {
	this.delay = 5000;
	this.curIndex = 0;
	this.randomImages = randomImages;
	this.preload = new Array();
	this.imageName = "featured_image_" + featuredImageCount;
	
	for (this.n=0; this.n < this.randomImages.length; this.n++) {
		this.preload[this.n] = new Image();
		this.preload[this.n].src = this.randomImages[this.n];
	}
	document.write('<script type="text/javascript"> setInterval("rotateimage(featuredImages, ' + featuredImageCount + ')",' + this.delay + '); </script>');
	document.write('<img name="' + this.imageName + '" src="'+this.randomImages[Math.floor(Math.random()*(this.randomImages.length))]+'" border="1">');
}

FlippinImage.prototype.rotateImage = function() {
	if (this.curIndex == (this.tempIndex = Math.floor(Math.random() * (this.randomImages.length)))) {
		this.curIndex = (this.curIndex == 0) ? 1 : this.curIndex - 1;
	}
	else {
		this.curIndex = this.tempIndex;
	}
	
	eval('document.images.' + this.imageName + '.src="' + this.randomImages[this.curIndex] + '"');
}
