
window.addEvent('domready',function() {
	/* settings */
	var showDuration = 8000;
	var container = $$('.slideshow_container');
	var texts = $$('.slideshow_box');
	var currentIndex = 0;
	var interval;
	var toc = $$('.toc');
	var tocWidth = 20;
	var tocActive = 'active';
	
	
	
	/* new: starts the show */
	var start = function() { interval = show.periodical(showDuration); };
	var stop = function() { $clear(interval); };
	/* worker */
	var show = function(to) {
		texts[currentIndex].fade('out');
		toc[currentIndex].removeClass(tocActive);
		texts[currentIndex = ($defined(to) ? to : (currentIndex < texts.length - 1 ? currentIndex+1 : 0))].fade('in');
		toc[currentIndex].addClass(tocActive);
	};
	
	
	/* new: control: start/stop on mouseover/mouseout */
	/*container.addEvents({
		mouseenter: function() { stop(); },
		mouseleave: function() { start(); }
	});*/
	
	$$('.page1').addEvent('click',function(){
		if(currentIndex!=0)
			{
			stop();
			texts[currentIndex].fade('out');
			toc[currentIndex].removeClass(tocActive);
			texts[0].fade('in');
			currentIndex = 0;
			toc[currentIndex].addClass(tocActive);
			start();
			}
	});
	
	$$('.page2').addEvent('click',function(){
		if(currentIndex!=1)
			{
			stop();
			texts[currentIndex].fade('out');
			toc[currentIndex].removeClass(tocActive);
			texts[1].fade('in');
			currentIndex = 1;
			toc[currentIndex].addClass(tocActive);
			start();
			}
	});
	
	$$('.page3').addEvent('click',function(){
		if(currentIndex!=2)
			{
			stop();
			texts[currentIndex].fade('out');
			toc[currentIndex].removeClass(tocActive);
			texts[2].fade('in');
			currentIndex = 2;
			toc[currentIndex].addClass(tocActive);
			start();
			}
	});
	
	
	/* start once the page is finished loading */
	window.addEvent('load',function(){
		start();
	});
	
	
});

