// Slideshow Teaserboxen
function elySlideshow(config)
{
	if(!jQuery)return this;
	this.config.frequency = config.frequency || 0;
	this.config.target = config.target || '#elySlideshow';
	this.init();
}

elySlideshow.prototype = {
	config: {},
	init: function()
	{
		if($(this.config.target).css('position')!='absolute')$(this.config.target).css({'position':'relative'});

		this.listItems = $(this.config.target).children('img');

		this.listItems.css({'position':'absolute','left':0,'top':0, 'z-index':20});

		this.listItems = this.listItems.get();

		if(!this.listItems.length) return this;

		this.backFace = new Image();
		this.backFace.className = 'backFace';
		$(this.config.target).append(this.backFace);
		this.backFace = $(this.config.target).children('.backFace');
		this.backFace.attr('src',$(this.listItems[0]).attr('src'));
		this.backFace.css({'position':'absolute','left':0,'top':0, 'z-index':10});

		this.slide();

		var _this = this;
		if(this.config.frequency)this.moveInterval = setInterval(function(){_this.slide();},this.config.frequency*1000);
	},
	activeImage: 0,
	slide: function()
	{
		var last = this.activeImage;
		this.backFace.attr('src',$(this.listItems[last]).attr('src'));
		var step = 1;
		this.activeImage = (this.activeImage+step > this.listItems.length-1)?0:((this.activeImage+step < 0)?this.listItems.length-1:this.activeImage+step);
		$(this.listItems[last]).hide();
		$(this.listItems[this.activeImage]).fadeIn((this.config.frequency&&this.config.frequency*1000 < 500)?this.config.frequency*1000-50:500);
	}
};
