﻿window.addEvent('domready', function(){
			var busy = false, timer, loadedImages = [], gallery = $('gallery'); 
var path = 'bilder/';
var images = [
	path + 'babymasage-03.jpg',
	path + 'rueckb-01.jpg', 
	path + 'babymasage-02.jpg', 
	path + 'rueckb-02.jpg', 
	path + 'babymasage-01.jpg',
	path + 'bauch.jpg'
];
gallery.setStyles({'opacity': 0, 'display': 'none'});


 
//$('start').addEvent('click', function(e) {
	//e = new Event(e).stop();


	if (!busy) {
 
		var galleryImgs = $$('#gallery img');
		if (galleryImgs.length > 0) galleryImgs.each(function(image) {	image.remove();	});
 
		busy = true;
		
		gallery.setStyle('display', 'block');
		new Asset.images(images, {
			onProgress: function(i) {
				this.setStyles({
					'position': 'absolute',
					'opacity': 0,
					'left': (gallery.getCoordinates().width / 2) - (this.width / 2),
					'top': (gallery.getCoordinates().height / 2) - (this.height / 2)
				});
				loadedImages[i] = this;

			},
			onComplete: function() {
				
				var fx = $('gallery').effect('opacity').start(1);
				timer = 0;
				loadedImages.each(function(image, i) {
					timer += 5000;
					image.inject(gallery);
					fx = function() {
						var imgEffect = image.effect('opacity', {duration: 5000});
						imgEffect.start(1).chain(function() {
							if (i < loadedImages.length - 1) {
								
								this.start(0).chain(function() {
									image.remove();
								});
							} else {
								busy = false;
								
								
							}
						});
 
					}.delay(timer * 2);
				});
			}
		});
	}

}); 

//});
			
			
	
