﻿Slideshow = function(targetImage, array, speed) {
	var me = this;
	
	this.slideShowSpeed = speed;
	this.crossFadeDuration = 2;
	this.targetImage = targetImage;
	this.array = array;
	this.currentIndex = 0;
	this.timeout = undefined;
	
	me.runSlideShow();
}

Slideshow.prototype.runSlideShow = function() {
	var me = this;
	
	if (this.array.length>0) {
		var slideshowimg = this.targetImage;
		
		if (document.all){
			slideshowimg.style.filter="blendTrans(duration="+this.crossFadeDuration+")";
			slideshowimg.filters.blendTrans.Apply();     
		}
		var ran = Math.floor(Math.random()*this.array.length)
		slideshowimg.src = this.array[ran].src;
		
		if (document.all){
			slideshowimg.filters.blendTrans.Play();
		}
		
		this.currentIndex = (this.currentIndex + 1) % this.array.length;
		
		this.timeout = setTimeout(function() { me.runSlideShow();}, this.slideShowSpeed);
	}
}
