var curNr = 0;
backLink = 0;
nextLink = 0;

function blaetternWeiter() {
	curNr++; // todo, check max
	//if (curNr < 0) curNr = 0;
	setActivePage();
}

function blaetternZurueck() {
	curNr--;
	//if (curNr < 0) curNr = 0;
	setActivePage();
}

function setActivePage() {
	links = document.getElementById("text_1");	
	rechts = document.getElementById("text_2");	
	mmainpic = document.getElementById("mainpic");

	tl = links.childNodes;
	tr = rechts.childNodes;
	img = mmainpic.childNodes;

	tlc = 0; tll = -1;
	trc = 0; trl = -1;
	imgc = 0; imgl = -1;
	for (i = 0; i < tl.length; i++) {
		if (tl[i].tagName != "DIV") continue;
		if (tl[i].getAttribute("name") == "textblock") {
			tll = i;
			tl[i].style.display = "none";
			if (curNr == tlc)
				tl[i].style.display = "block";
			tlc++;
		}
	}
	if (tl.length > 0 && curNr >= tlc && tll >= 0)
		tl[tll].style.display = "block";

	for (i = 0; i < tr.length; i++) {
		if (tr[i].tagName != "DIV") continue;
		if (tr[i].getAttribute("name") == "textblock") {
			trl = i;
			tr[i].style.display = "none";
			if (curNr == trc)
				tr[i].style.display = "block";
			trc++;
		}
	}
	if (tr.length > 0 && curNr >= trc && trl >= 0)
		tr[trl].style.display = "block";


	for (i = 0; i < img.length; i++) {
		if (img[i].tagName != "DIV") continue;
		if (img[i].getAttribute("name")== "mainpic") {
			imgl = i;
			img[i].style.display = "none";
			if (curNr == imgc)
				img[i].style.display = "block";
			imgc++;
		}
	}
	if (img.length > 0 && curNr >= imgc && imgl >= 0)
		img[imgl].style.display = "block";

	max = tlc;
	if (trc > max) max = trc;
	if (imgc > max) max = imgc;
	
	//if (curNr >= max) curNr = max-1;


	back = document.getElementById("pageBack");
	next = document.getElementById("pageNext");
	slash = document.getElementById("paging_slash");
	
	if ( backLink != 0 && nextLink != 0 )
		slash.style.visibility="visible";

	if ( (curNr == 0 || max == 0) && backLink == 0 ) {
        back.style.visibility="hidden";
     }
	else if ( curNr < 0 && backLink != 0 )
		window.location.href = backLink;
	else {
		back.style.visibility="visible";
        }

	if ( (curNr >= max-1 || max == 0) && nextLink == 0 ) {
		next.style.visibility="hidden";
	}
		
	else if ( curNr >= max && nextLink != 0 )
		window.location.href = nextLink;
	else
		next.style.visibility="visible";

}


