var photo_count = 0;
var photo = Math.ceil(Math.random()*(photo_count));
var fadeImages = function(){
	var current = photo
	if (photo == photo_count){var next = 1;photo = 1;}else{var next = photo+1;photo++;}
	myFx1 = new Fx.Tween($('img'+current),{property: 'opacity',duration: 2000});
    myFx1.start(1,0); 
    myFx2 = new Fx.Tween($('img'+next),{property: 'opacity',duration: 2000});
    myFx2.start(0,1);
}
var pause = function(){
	$clear(timer);
	$('button').addEvent('click', play);
	$('button').setStyle('background','url(tl_files/Fahrschule_Silbermann/images/btn_play.png)');
	var slideshowCookie = Cookie.write('slidedshow', 0);
}
var play = function(){
	timer = fadeImages.periodical(5000);
	$('button').addEvent('click', pause);
	$('button').setStyle('background','url(tl_files/Fahrschule_Silbermann/images/btn_pause.png)');
	var slideshowCookie = Cookie.write('slidedshow', 1);
}
var start = function(){
	var slideshowCookie = Cookie.read('slidedshow');
	if (slideshowCookie != 0) {
		timer = fadeImages.periodical(5000);
		$('button').addEvent('click', pause);
		$('button').setStyle('background','url(tl_files/Fahrschule_Silbermann/images/btn_pause.png)');
	}else{
		$('button').addEvent('click', play);
		$('button').setStyle('background','url(tl_files/Fahrschule_Silbermann/images/btn_play.png)');
	}
}
window.addEvent('domready', function() {
	photo_count = $('photo').getChildren('img').length;
	photo = Math.ceil(Math.random()*(photo_count));
	$('img'+photo).setStyle('visibility','visible');
	if(photo_count > 1)
		start();
});


