var iPage = 0;
var mode = 0; // 0: Diashow 1: vor/zurck
var lPages = pages.length / 2;
var timerID = null;
var timerRunning = false;
var random = false;

function stopclock() {
	if (timerRunning) {
		document.getElementById("Text_startstop").innerHTML = 'start';
		document.getElementById("Text_startstop").style.backgroundColor="green";
		clearInterval(timerID);
		timerRunning = false;
	}
}
function startclock(time) {
	stopclock();
	document.getElementById("Text_startstop").innerHTML = 'stop';
	document.getElementById("Text_startstop").style.backgroundColor="red";
	timerID = setInterval("ShowNext()", time);
	timerRunning = true;
}
function ShowNext() {
	if (random) {
		Index = Math.floor(Math.random() * lPages);
		SetPage(Index);
	}
	else {
		iPage++;
		if (iPage == lPages) iPage = 0;
		SetPage(iPage);
	}
}
function ShowPrevious() {
	if (random) {
		Index = Math.floor(Math.random() * lPages);
		SetPage(Index);
	}
	else {
		iPage--;
		if (iPage == -1) iPage = lPages-1;
		SetPage(iPage);
	}
}
function changemode() {
	stopclock();
	if (random) {
		random = false;
		document.getElementById("Random").innerHTML = 'chrono';
	} else {
		random = true;
		document.getElementById("Random").innerHTML = 'zufall';
	}
}
function SetPage(page) {
	document.getElementById("PageTitle").innerHTML = pages[page * 2];
	frames["Daten"].location.href = pages[page * 2 + 1];
}
function GetPageTitle(page) {
	return pages[page * 2];
}
function initialize() {
	document.getElementById("Navigation").innerHTML = "";
	for (i=0; i<lPages; i++)
	{
		document.getElementById("Navigation").innerHTML +=
			" <a title='"+GetPageTitle(i)+"' href='javascript:top.SetPage(" + i + ")'>" + i + "</a>";
	}
	SetPage(0);
	if (random) {
		document.getElementById("Random").innerHTML = 'chrono';
	}
	else {
		document.getElementById("Random").innerHTML = 'zufall';
	}
}
function startstop() {
	if (document.getElementById("Text_startstop").innerHTML == 'start') {
		document.getElementById("Text_startstop").innerHTML = 'stop';
		initialize();
		startclock(document.console.timeselect.options[document.console.timeselect.selectedIndex].value);
	}
	else {
		stopclock();
	}
}
function changetime(newtime) {
	if (timerRunning) {
		startclock(newtime);
	}
}
function Liste() {
	frames["Daten"].document.open();
	for (i = 0; i < lPages; i++) {
		var s = "<tt>";
		if (i < 10) s = "&nbsp;";
		s += i + "</tt>";
		s += "<span style='font-family:Tahoma'>";
		s += " <a href='javascript:top.SetPage(" + i + ")'>" + pages[2 * i] + "</a>";
		s += "<br/>";
		document.getElementById("Daten").style = "visibility:hidden";
		frames["Daten"].document.write(s);
	}
	frames["Daten"].document.close();
}
function ConfigureDocument() {
	if (WindowAuto) {
        document.getElementById("Daten").width = screen.width - 150;
        document.getElementById("Daten").height = screen.height - 300;
    }
    else {
        document.getElementById("Daten").width = WindowWidth;
        document.getElementById("Daten").height = WindowHeight;
    }
	for (i=0; i<pages.length; i++){
		if (pages[i][0]=='@')
		pages[i] = window.location.href.replace(/Diashow.htm/g, pages[i].substr(1));
	}
	pages[pages.length] = "Liste der Diashow-Seiten";
	pages[pages.length] = window.location.href.replace(/Diashow.htm/g, "DiashowListe.htm");
	lPages = pages.length/2;
    initialize();
	if (Autostart) startstop(); else { timerRunning=true; stopclock() };
}