$(window).addEvent('domready', function() {
	
	ce_slideshow($('teaser_images'), 'img');
	
});

function ce_slideshow(container, type) {
	var elements = container.getChildren(type);

	var elementcount = elements.length - 1;
	var visible = 0;
	elements.fade('hide');
	elements.each(function(el) {
		el.position({
			relativeTo: container,
	  		position: 'topRight',
	  		edge: 'topLeft',
	  		offset: {x: 20, y: 0}
		});
	});
	elements[visible].fade('show');
	elements[visible].position({
			relativeTo: container,
	  		position: 'topLeft',
	  		edge: 'topLeft'
		});
	
	var fader = window.setInterval(function(){
		var lastvisible = elements[visible];
		elements[visible].setStyle('z-index', 3);
		(function(){
			lastvisible.move({
				relativeTo: container,
		  		position: 'topRight',
		  		edge: 'topLeft',
		  		offset: {x: 20, y: 0},
		  		duration: 1000
			});
		}).delay(0);
		if(visible == elementcount) {
			visible = 0;
		} else {
			visible = visible + 1;
		}
		elements[visible].fade('show');
		elements[visible].setStyle('z-index', 4);
		elements[visible].move({
			relativeTo: container,
	  		position: 'topLeft',
	  		edge: 'topLeft',
			duration: 1000
		});
	}, 5000);
}
