// @date 08.06.2006 
var Gallery = Class.create();
Gallery.prototype = 
{
	initialize: function(image, thumbsrule)
	{
		this.element	= $(image);
		this.thumbs		= $$(thumbsrule);
		
		// add on click events
		this.thumbs.each(function(i, k)
		{
			i.observe('click', this.showImage.bind(this, i, k));
		}.bind(this));
		
		this.current 	= 0;
		this._gotoNext	= this.gotoNext.bind(this, 1);
		this.setTimer(4000);
	},
	setTimer: function(time)
	{
					 window.clearTimeout(this.timer);
		this.timer = window.setTimeout(this._gotoNext, time || 8000);
	},
	showImage: function(a, num, time)
	{
		this.current = num;
		
		var src	= a.getAttribute('title');	
		
		new Effect.Fade(this.element,
		{
			duration: .1,
			afterFinish: function(ef)
			{
				ef.element.src=src;
				new Effect.Appear(ef.element);
			}
		});
		this.setTimer(parseInt(time));
	},
	gotoNext: function(to)
	{
		to = this.current + ( to ? to : 1 );
		
		if (!this.thumbs[to])
		{
			to = 0;
		}
	
		this.showImage(this.thumbs[to], to, 4000);
	}
}
