var RandImage = Class.create({
	_cache: undefined,
	changeDur: undefined,
	changeDel: undefined,
	targetImg: undefined,
	nextIndex: undefined,
	nextImage: undefined,
	arrImages: undefined,
	intvImage: undefined,
	
	initialize: function(t,d,k,es) {
		this.changeDur = d;
		this.changeDel = k;
		this.targetImg = t;
		this.arrImages = es;
		this.nextIndex = Math.round(Math.random() * this.arrImages.length-1);
		
		this._rand();
	},
	
	_rand: function() {
	//	if (this.intvImage)
	//		clearTimeout(this.intvImage);
		this.nextIndex = (this.nextIndex == (this.arrImages.length-1)) ? 0 : this.nextIndex + 1;
		this._cache = new Image();
		this._cache.onload = (function() {
			new Effect.Opacity(
				'ri_' + this.targetImg, {
					from: 1,
					to: 0,
					delay: this.changeDur + this.changeDel,
					queue: {
						position: 'front',
						scope: 'q_' + this.targetImg
					},
					duration: .5,
					afterFinish: (function() {
						$('ri_' + this.targetImg).src = 'http://www.wahrekunst.com/' + this.arrImages[this.nextIndex];
						delete this._cache;
						new Effect.Opacity(
							'ri_' + this.targetImg, {
								from: 0,
								to: 1,
								queue: {
									position: 'end',
									scope: 'q_' + this.targetImg
								},
								delay: .3,
								duration: .5,
								afterFinish: this._rand.bind(this)
							}
						);
					}).bind(this)
				}
			);
		}).bind(this);
		this._cache.src = 'http://www.wahrekunst.com/' + this.arrImages[this.nextIndex];
	}
});
