/**
 * @author Dominik Scholz
 */

var products = {
	// vars
	maxImage: 4,
	currentImage: 1,
	timeOut: 4,
	duration: 2,
	path: '/common/gfx/products/products_',
	effect: null,
	img1: null,
	img2: null,
	
	// init search
	init: function(e) {

		this.img1 = $('mainimage1');
		this.img2 = $('mainimage2');

		this.img1.src = this.path + this.nextImage() + '.jpg';
		window.setTimeout(this.fadeOut.bind(this), this.timeOut * 1000);
	},
	
	// fade image out
	fadeIn: function() {
		
		this.effect = new Effect.Appear(this.img2, {
			transition: Effect.Transitions.sinoidal,
			duration: this.duration,
			afterFinish: function() {
				this.img1.src = this.path + this.nextImage() + '.jpg';
				window.setTimeout(this.fadeOut.bind(this), this.timeOut * 1000);
			}.bind(this)
		});
	},
	
	// fade image in
	fadeOut: function() {
		
		this.effect = new Effect.Fade(this.img2, {
			transition: Effect.Transitions.sinoidal,
			duration: this.duration,
			afterFinish: function() {
				this.img2.src = this.path + this.nextImage() + '.jpg';
				window.setTimeout(this.fadeIn.bind(this), this.timeOut * 1000);
			}.bind(this)
		});
	},
	
	
	// get next image
	nextImage: function() {
		
		this.currentImage++;
		if (this.currentImage > this.maxImage) this.currentImage = 1;
		
		return this.currentImage;
	}
	
};

// register search
document.observe("dom:loaded", function() {
	products.init();
});

