var currentRepeatingEvent = 0;
var slideshowTotalImages = 0;
var slideshowLoadedImages = 0;
var showStarted = false;
var show = {};
var myTimeout = -1;

function startSlideshow() {
	if (show.started == false) {
		if (myTimeout != -1) {
				clearTimeout(myTimeout);
		} // eof if()
		var myEffect = new Fx.Style('slideshowLoader', 'opacity', { 
			duration: 500,
			onComplete: function() { 
				$('slideshowContainer').style.display = 'block';
				showStarted = true;
				show.play(); 
			} 
		});
		myEffect.start(1, 0).chain(function() {
			$('slideshowLoader').style.display = 'none';
		});
	} // eof if()
} // eof startSlideshow()

function slideshowImgOnLoad() {
	if (showStarted == false) {
		if (slideshowTotalImages != 0) {
			slideshowLoadedImages = slideshowLoadedImages + 1;
		} // eof if()
		
		if (slideshowLoadedImages == slideshowTotalImages) {
			startSlideshow();
		} // eof if()
	} // eof if()
} // eof slideshowImgOnLoad()

window.addEvent('domready',function(){
	// 1. Slideshow.
	var obj = {
		wait: 3000, 
		effect: 'wipe',
		duration: 1000, 
		loop: true, 
		thumbnails: false,
		backgroundSlider: false,
		transition: Fx.Transitions.Back.easeInOut
	};
	show = new SlideShow('slideshowContainer','slideshowImg',obj);
	// show.play();
	
	// 3. Preload obrazkow do slideshow'a :).
	slideshowTotalImages = $ES('img', 'slideshowContainer').length;
	if (slideshowTotalImages != 0) {
		timeout = slideshowTotalImages * 4 * 1000; // Timeout w ms, po ktorym slideshow i tak sie odpali, nawet jesli sie grafika nie zaladuje...
		myTimeout = setTimeout("startSlideshow()", timeout);
		//if ($defined(window.opera) == false) {
			//timeout = slideshowTotalImages * 4 * 1000; // Timeout w ms, po ktorym slideshow i tak sie odpali, nawet jesli sie grafika nie zaladuje...
			//myTimeout = setTimeout("startSlideshow()", timeout);
		//} else {
			//$$('#slideshowLoader .texts')[0].style.visibility = 'hidden';
		//} // eof if()
	} // eof if()
});

