/**
 * @author christophseydel
 */
var actor = true; //true:auto, false:human
var progress = false;
var id;
var t;
var wait = 5000; // change here the milliseconds for timed slideshow event 1sec == 1000




function autoSlide()
{
	t = window.setInterval('SlideShowLeft(true)', wait);
}

function SlideShowLeft(actor)
{	
	if(!progress)
	{
		if(!actor)
		{
			clearInterval(t);
		}
		progress = true;
		id = Element.readAttribute($$('.current')[0],'id');
		new Ajax.Request('http://berlinbeweger.de/shared/loadNextStageItem/'+id,
		{
			method:'post',
		    onSuccess: function(transport)
			{   
				var response = transport.responseText.evalJSON() || null;
				if(response != null)
				{
					id = response['id'];
					$$('.next')[0].innerHTML = response['content'];
					$$('.next')[0].writeAttribute('id',response['id']);
					move($$('.prev')[0],-1100);
					move($$('.current')[0],-1100);
					move($$('.next')[0],-1100);
					setTimeout('switchClasses(true)',1500);
				}
		    },
		    onFailure: function(e){},
			onLoaded: function(transport){},
			onComplete: function(transport){}
		});
	}
}

function SlideShowRight(actor)
{
	if(!progress)
	{
		if(!actor)
		{
			clearInterval(t);
		}
		progress = true;
		id = Element.readAttribute($$('.current')[0],'id');
		new Ajax.Request('http://berlinbeweger.de/shared/loadPreviousStageItem/'+id,
		{
			method:'post',
		    onSuccess: function(transport)
			{
		    	var response = transport.responseText.evalJSON() || null;
				if(response != null)
				{
					id = response['id'];
					$$('.prev')[0].innerHTML = response['content'];
					$$('.prev')[0].writeAttribute('id',response['id']);
					move($$('.next')[0],1100);
					move($$('.current')[0],1100);
					move($$('.prev')[0],1100);
					setTimeout('switchClasses(false)',1500);
				}
		    },
		    onFailure: function(){}
		});
	}
}

function move(element, width)
{
	new Effect.Move(element, {
		x: width,
		y: 0,
		transition: Effect.Transitions.linear,
		mode: 'relative',
		duration: 1.0
	});
}

function switchClasses(direction)
{
	if(direction)
	{         
		
		Element.writeAttribute($$('.prev')[0],'class','help slides');
		Element.writeAttribute($$('.current')[0],'class', 'prev slides');
		Element.writeAttribute($$('.next')[0],'class', 'current slides');
		Element.writeAttribute($$('.help')[0],'class','next slides');
		Element.setStyle($$('.next')[0], {left:'1100px'});
		Element.setStyle($$('.current')[0], {left:'0'});      
		Element.setStyle($$('.prev')[0],{left:'-1100px'});   	
	}
	else
	{   
		Element.writeAttribute($$('.next')[0],'class','help slides');
		Element.writeAttribute($$('.current')[0],'class', 'next slides');
		Element.writeAttribute($$('.prev')[0],'class', 'current slides');
		Element.writeAttribute($$('.help')[0],'class','prev slides');
		Element.setStyle($$('.next')[0], {left:'1100px'});
		Element.setStyle($$('.current')[0], {left:'0'});
		Element.setStyle($$('.prev')[0], {left:'-1100px'});
	}
	progress = false;
}



/*function old_SlideShowLeft(e) {
	if (!progress) {
		newSlide();
		progress = true;
		var slides = document.getElementById('slide-list');
		var secondaryList = document.getElementById('secondary-list');
		var activeList;
		var passiveList;
		var width;
		clearInterval(t);
		
		//which list is active
		if (flag) {
			activeList = slides;
			passiveList = secondaryList;
		}
		else {
			activeList = secondaryList;
			passiveList = slides;
		}
		
		//changing activity status
		if ((i % e) == 0) {
			if (flag == true) {
				flag = false;
				activeList = secondaryList;
				passiveList = slides;
			}
			else {
				flag = true;
				activeList = slides;
				passiveList = secondaryList;
			}
		}
		
		//counting left value down for passive list
		if (i > (e)) {
			if ((i % e) == 0) 
				j = 0;
			width = 940 + listWidth - ((j) * 940);
			passiveList.style.left = width + 'px';
			j++;
		}
		
		//reset after passing by both lists
		if (((i % e) == 0) && (i == 2 * e)) {
			i = 0;
			activeList.style.left = '940px';
			passiveList.style.left = '940px';
		}
		
		//moving effect
		new Effect.Move(activeList, {
			x: -940,
			y: 0,
			transition: Effect.Transitions.linear,
			mode: 'relative'
		});
		new Effect.Move(passiveList, {
			x: -940,
			y: 0,
			transition: Effect.Transitions.linear,
			mode: 'relative'
		});
		
		//increment circle count
		i++;
		window.setTimeout('progress = false',1000);
	}
}

function old_SlideShowRight(e) {
	if (!progress) {
		progress = true;
		var slides = document.getElementById('slide-list');
		var secondaryList = document.getElementById('secondary-list');
		clearInterval(t);
		//list position change on start
		if (i == 1) {
			slides.style.left = '-'+listWidth+'px';
			secondaryList.style.left = '-'+listWidth+'px';
		}
		
		//list position change after one circle
		if (i == (-e)+1) {
			i = 1;
			slides.style.left = '-'+listWidth+'px';
			secondaryList.style.left = '-'+listWidth+'px';
		}
		
		//moving effect
		new Effect.Move(slides, {
			x: 940,
			y: 0,
			transition: Effect.Transitions.sinoidal,
			mode: 'relative'
		});
		new Effect.Move(secondaryList, {
			x: 940,
			y: 0,
			transition: Effect.Transitions.sinoidal,
			mode: 'relative'
		});
		
		//decrement circle run
		i--;
		window.setTimeout('progress = false',1000);
	}
}

function autoSlideShowLeft(e) {
	if ((!progress)) {
		newSlide();
		progress = true;
		var slides = document.getElementById('slide-list');
		var secondaryList = document.getElementById('secondary-list');
		var activeList;
		var passiveList;
		var width;
		
		//which list is active
		if (flag) {
			activeList = slides;
			passiveList = secondaryList;
		}
		else {
			activeList = secondaryList;
			passiveList = slides;
		}
		
		//changing activity status
		if ((i % e) == 0) {
			if (flag == true) {
				flag = false;
				activeList = secondaryList;
				passiveList = slides;
			}
			else {
				flag = true;
				activeList = slides;
				passiveList = secondaryList;
			}
		}
		
		//counting left value down for passive list
		if (i > (e)) {
			if ((i % e) == 0) 
				j = 0;
			width = 940 + listWidth - ((j) * 940);
			passiveList.style.left = width + 'px';
			j++;
		}
		
		//moving effect
		new Effect.Move(activeList, {
			x: -940,
			y: 0,
			transition: Effect.Transitions.sinoidal,
			mode: 'relative'
		});
		new Effect.Move(passiveList, {
			x: -940,
			y: 0,
			transition: Effect.Transitions.sinoidal,
			mode: 'relative'
		});
		
		//reset after passing by both lists
		if (((i % e) == 0) && (i == 2 * e)) {
			i = 0;
			activeList.style.left = '940px';
			passiveList.style.left = '940px';
		}
		
		//increment circle count
		i++;
		window.setTimeout('progress = false',1000);
	}
}*/
function start_slideshow() {  
	/*id = $('slide-list').firstDescendant().readAttribute('id');
	newSlide();
	entrycount = 3;
	i = 1;
	j = 0;
	listWidth = 3 * 940;
	t = window.setInterval('autoSlideShowLeft(entrycount)', wait);*/
}
