/*
aa.fx.pack.js, effects for aa-electric.com
v 2.0.0
*/

//---------------------------------------------------------------

var simpleSlideShow = new Class({
	initialize: function(foreImg, backImg, imgLink, imgList) {
		this.foreImg = $(foreImg);
		this.backImg = $(backImg);
		this.imgLink = $(imgLink);
		this.currentIdx = 0;
		this.imgList = imgList;
	},

	step: function() {
		this.backImg.src = null; //-- so Safari fires an onload if .src's are identical by chance
		this.backImg.onload = function() {
			this.fwOpacity = new Fx.Style(this.foreImg, 'opacity', { duration: this.imgList[this.currentIdx].duration });
			this.fwOpacity.set(0);
			setTimeout(function() {
				this.foreImg.onload = function() {
					this.fwOpacity.custom(0,1);
				}.bind(this);
				this.foreImg.src = this.imgList[this.currentIdx].image;
				if(this.imgLink==undefined) {
					this.imgLink.href = this.linkList[this.currentIdx].link;
				} // if
				this.currentIdx = (this.currentIdx+1) % this.imgList.length;
				this.timer = setTimeout(this.step.bind(this),this.imgList[this.currentIdx].linger+this.imgList[this.currentIdx].duration+20);
			}.bind(this)
			,20);
		}.bind(this);
		this.backImg.src = this.foreImg.src;
	},

	shuffle: function() {
	  var i = this.imgList.length;
	  if ( i == 0 ) return false;
	  while ( --i ) {
	     var j = Math.floor( Math.random() * ( i + 1 ) );
	     var tempi = this.imgList[i];
	     var tempj = this.imgList[j];
	     this.imgList[i] = tempj;
	     this.imgList[j] = tempi;
	   }
	},

	pause: function() {
		clearTimeout(this.timer);
	},

	resume: function() {
		this.step.bind(this);
	},

	start: function() {
		this.currentIdx = 0;
		this.timer = setTimeout(this.step.bind(this), this.imgList[this.currentIdx].linger);
	}
}); // class..simpleSlideShow

//---------------------------------------------------------------

