/**
 * User: Саша
 * Date: 12.04.11
 * Time: 15:06
 */

var stwImageToggle = function(container, images, options) {
	this.container = $(container);
	this.images = images;
	this.num = 0;

	if (options) {
		for (var k in options) this[k] = options[k];
	}

	this.sceneTop = new Element('dt');
	var img = this.container.down('img');
	if (img) {
		this.sceneTop.insert(img);
		this.images.push(img.readAttribute('src'));
	}
	this.sceneBottom = new Element('dd');

	this.container.insert({
		top: new Element('dl')
				.addClassName('image-toggle-block')
				.insert({top: this.sceneTop})
				.insert({bottom: this.sceneBottom})
	});

};

stwImageToggle.prototype = {
	container: null,
	images: [],
	sceneTop: null,
	sceneBottom: null,
	num: 0,
	speed: 4000,

	next: function(){
		var img = this.sceneTop.down('img');

		var img2 = new Element('IMG', {'src': this.images[this.num]});
		this.sceneBottom.update(img2);

		Effect.Fade( img, {'duration': this.speed / 1000} );

		var t = this;
		setTimeout( function() {
			t.sceneTop.update(img2);
		}, this.speed );

		if (++this.num == this.images.length){
			this.num = 0;
		}

	}
};

