﻿
//------------------------------------------------------------------------------------------------------------------
// Wp.Slideshow
//------------------------------------------------------------------------------------------------------------------

Wp.Slideshow = function(targetImage, array) {
	var me = this;
	
	this.slideShowSpeed = 6000;
	this.crossFadeDuration = 2;
	this.targetImage = targetImage;
	this.array = array;
	this.currentIndex = 0;
	this.timeout = undefined;
	
	Wp.General.RegisterEvent(window, "load", function() {me.runSlideShow();} );
}

Wp.Slideshow.prototype.runSlideShow = function() {
	var me = this;
	if (this.array.length > 0) {
		var slideshowimg = $(this.targetImage).getElementsByTagName('img')[0];
		if (slideshowimg) {
			if (document.all) {
				slideshowimg.style.filter = "blendTrans(duration=" + this.crossFadeDuration + ")";
				slideshowimg.filters.blendTrans.Apply();
			}
			
			//var ran = Math.floor(Math.random() * this.array.length-1);
			//if(ran<=0){ran=0}
			slideshowimg.src = this.array[this.currentIndex];
			
			if (document.all) {
				slideshowimg.filters.blendTrans.Play();
			}

			this.currentIndex = (this.currentIndex + 1) % this.array.length;

			this.timeout = setTimeout(function() { me.runSlideShow(); }, this.slideShowSpeed);
		}
	}
}