// Stage functions



/* Loop Ressource*/

var loop = 0;



/* Starting at listpoint with number: */

var startIndex = Math.round(Math.random() * 3);



/* Time to wait for the next image*/

var looptime = 2000;



/* Speed for the image to fadeIn*/

var transition = 1200; //(fast, normal, slow)







function init() {

		

	

	showNextImg(startIndex);

	//Start the Loop on start

	startLoop();

	

}



function startLoop() {

	

	//Start loop if not started yet

	if(loop == 0){

		loop = setInterval("showNextInLoop()", looptime);

	}

}



function stopLoop() {

	

	if(loop > 0){

		clearInterval(loop);

		loop = 0;

	}

	

}



function showNextImg(index) {

	

	$('#teaser ul li, #teaser #teaserText div').fadeOut(transition);

	

	//Get Divcontainer by index

	$('#teaser ul li:eq('+ index +'), #teaser #teaserText div:eq('+ index +')').fadeIn(transition);

		

	

	

	

	

}



function showNextInLoop(index){

	

	var nextIndex = startIndex+1;

	

	if(nextIndex >= $("#teaser ul li").length){

		nextIndex = 0;

	}

	

	startIndex = nextIndex;

	

	showNextImg(nextIndex);

	

	

};



function initStage(startIndexUser, looptimeUser) {

	//Start everything when the page is loaded

	$(document).ready(function() {

		looptime = looptimeUser;

		init();

		

	}); 

}
