//#### Wichtig für den Roll-Effekt ############
var nextPicTimeout = 2;		// Timeout in Sekunden für Bilderwechsel
var scrollDelay = 100;		// wird benötigt, damit vor- und zurückblättern nicht ins Stolpern kommt
var count = 11;				// Zähler
var counterTimeout;			// Timeout-Objekt
var currentSlide = 0;
//#############################################

nextPicTimeout = nextPicTimeout * 1000;	// in Millisekunden umrechnen

$(document).ready(function(){
	
	/**
	 * Lade alle Countdown-Bilder in den Browserspeicher
	 */
	MM_preloadImages(
		'/scopeanalysis/img/countdownpics/pause.gif',
		'/scopeanalysis/img/countdownpics/01.gif',
		'/scopeanalysis/img/countdownpics/03.gif',
		'/scopeanalysis/img/countdownpics/04.gif',
		'/scopeanalysis/img/countdownpics/05.gif',
		'/scopeanalysis/img/countdownpics/06.gif',
		'/scopeanalysis/img/countdownpics/07.gif',
		'/scopeanalysis/img/countdownpics/08.gif',
		'/scopeanalysis/img/countdownpics/09.gif'
	);
	
	/**
	 * Mitteilungen Box Startseite Rollierende Meldungen (cycle)
	 */
	if($('#box-last-news').length>0)
	{
		$('#box-last-news').cycle({
			cleartype:  true,
    		cleartypeNoBg:  true,
			fx: 'scrollVert', //fade
			rev: 1,
			prevNextEvent:  'click.cycle',
			next: 'img.next',
			prev: 'img.prev',
			timeout: 0,  // 6000
			speed: 500,
			/*
			before: function (curr, next, opts) {
				window.clearTimeout(counterTimeout);
			},
			prevNextClick: function (isNext, zeroBasedSlideIndex, slideElement) {
				window.clearTimeout(counterTimeout);
			},
			*/
			after: function (curr, next, opts) {
				count = 10;
				currentSlide = opts.currSlide+1;
				window.clearTimeout(counterTimeout);
				setTimeoutCounter();
			}
		});
	}

	// Pause der Rollierenden Meldungen
	$('div.boxstart').mouseenter(function()
		{
			$('#box-last-news').cycle('pause');
			window.clearTimeout(counterTimeout);
			$("#countdownImg"+currentSlide).attr("src","/scopeanalysis/img/countdownpics/pause.gif");
	});
	$('div.boxstart').mouseleave(function()
		{
			$('#box-last-news').cycle('resume');
			if(count<9){
				count++;
			}
			setTimeoutCounter();
	});
	
});

/**
 * Wechselt Bilder im Sekundentackt 
 */
function setTimeoutCounter()
{
	// Timeout löschen
	window.clearTimeout(counterTimeout);
	// ... und neu setzen
	counterTimeout = window.setTimeout("setTimeoutCounter()",nextPicTimeout);
	
	if(count>9){
		count = 9;
	}
	
	if(count<=1){
		count = 1;
		nextSlide();
	}
	if(count>=1 && count<=9){
		$("#countdownImg"+currentSlide).attr("src","/scopeanalysis/img/countdownpics/0"+count+".gif");
	}
	
	//$("#test"+currentSlide).html("["+count+"/"+currentSlide+"]");
	if(count>0){
		count--;
	}
}

/**
 * Blättert vor 
 */
function nextSlide(){
	window.clearTimeout(counterTimeout);
	window.setTimeout("$('#box-last-news').cycle('next');",scrollDelay);
}
/**
 * Blättert zurück 
 */
function prevSlide(){
	window.clearTimeout(counterTimeout);
	window.setTimeout("$('#box-last-news').cycle('prev');",scrollDelay);
}
