// copyright www.cg3d.de
function preimages() {
     var strPrefix = "0";
     arrImg = new Array();
     for(var p=1; p<=intImageCount; p++) {
     	if (p > 9) {strPrefix = "";}
      	arrImg[p] = new Image();
     	arrImg[p].src = strPath + strImageName + strPrefix + p + "." + strFileType;
     }
}

function makeDate() {
	var jetzt=new Date(); var Jahr=jetzt.getFullYear();
	document.getElementById("copyright").innerHTML = "&copy; " + Jahr + ", Britta H&uuml;ning";
}

function gPic(strObject){
	// animation anhalten
	stopAnimation();
	
	var Zahl = strObject.innerHTML;
	if ( parseInt(Zahl, 10) >= 1 && parseInt(Zahl, 10) <= intImageCount) { } else { return false; }
	// alert("url(" + strPath + strImageName + strObject.innerHTML + "." + strFileType + ")");
	// hintergrund setzen
	document.getElementById("gPictureFrame").style.backgroundImage = "url(" + strPath + strImageName + strObject.innerHTML + "." + strFileType + ")";
	// bildtext
	document.getElementById("bildtext").innerHTML = arrText[parseInt(Zahl, 10)];
	// externes link einstellen falls vorhanden
	if (arrLink[parseInt(Zahl, 10)].length > 1) {
		document.getElementById("gExternLink").innerHTML = "<a class='exlink' target='blank' rel='nofollow' href='http://" + arrLink[parseInt(Zahl, 10)] + "'>" + arrLink[parseInt(Zahl, 10)] + "</a>";
	} else {
		document.getElementById("gExternLink").innerHTML = "&nbsp;";
	}
	
	// andere links selektion abwählen
	var alle_li = strObject.parentNode.parentNode.childNodes;
	  for (var i=0;i<alle_li.length;i++) {
		// alert("TagName: " + alle_li[i].tagName);
		if (alle_li[i].tagName == "LI") {
			// alert("LI child tagname: " + alle_li[i].firstChild.tagName);
			alle_li[i].firstChild.className = "nlink";
		}
	  }
	// dieses link durch wechseln der klasse selektieren
	strObject.className = "nlinkselected";
}

// klick nach links
function gArrowLeft() {
// finde aktive zahl

// var alles = document.getElementById("NumLinkList").childNodes
var alles = document.getElementById("NumLinkList").getElementsByTagName("li");

// alert(alles.length + " childnodes found in NumLinkList.");
	for (var i=0;i<alles.length;i++) {
		// alert("TagName: " + alles[i].tagName);
//		if (alles[i].tagName == "LI") {
			// alert("(" + i + ")" + " a class name: " + alles[i].firstChild.className);
			if (alles[i].firstChild.className == "nlinkselected") {
					// alert("Zahl = " + alles[i].firstChild.innerHTML);
					Zahl = alles[i].firstChild.innerHTML;
					// nach unten wenn nicht schon unten
					if ( Zahl != "01" ) {
						// den eins davor auswählen
						alles[(i-1)].firstChild.className = "nlinkselected";
						// den aktiven abwählen
						alles[i].firstChild.className = "nlink";
						// bild einstellen
						document.getElementById("gPictureFrame").style.backgroundImage = "url(" + strPath + strImageName + alles[(i-1)].firstChild.innerHTML + "." + strFileType + ")";
						// bild text einstellen
						document.getElementById("bildtext").innerHTML = arrText[(parseInt(Zahl, 10)-1)];
						// externes link einstellen falls vorhanden
						if (arrLink[parseInt(Zahl, 10)-1].length > 1) {
							document.getElementById("gExternLink").innerHTML = "<a class='exlink' target='blank' rel='nofollow' href='http://" + arrLink[parseInt(Zahl, 10)-1] + "'>" + arrLink[parseInt(Zahl, 10)-1] + "</a>";
						} else {
							document.getElementById("gExternLink").innerHTML = "&nbsp;";
						}
					}

					// nach unten geloopt über den ersten
					if ( Zahl == "01" ) {
						alles[(i+intImageCount-1)].firstChild.className = "nlinkselected";
						alles[i].firstChild.className = "nlink";
						document.getElementById("gPictureFrame").style.backgroundImage = "url(" + strPath + strImageName + alles[(i+intImageCount-1)].firstChild.innerHTML + "." + strFileType + ")";
						document.getElementById("bildtext").innerHTML = arrText[(parseInt(Zahl, 10)+intImageCount-1)];
						if (arrLink[parseInt(Zahl, 10)-1].length > 1) {
							document.getElementById("gExternLink").innerHTML = "<a class='exlink' target='blank' rel='nofollow' href='http://" + arrLink[parseInt(Zahl, 10)+intImageCount-1] + "'>" + arrLink[parseInt(Zahl, 10)+intImageCount-1] + "</a>";
						} else {
							document.getElementById("gExternLink").innerHTML = "&nbsp;";
						}
						return;
					}
			}
//		}
	}
}

// klick nach links
function gArrowRight() {
	
// finde aktive zahl
// var alles = document.getElementById("NumLinkList").childNodes
var alles = document.getElementById("NumLinkList").getElementsByTagName("li");
	for (var i=0;i<alles.length;i++) {
		// alert("TagName: " + alle_li[i].tagName);
//		if (alles[i].tagName == "LI") {
			// alert("(" + i + ")" + " a class name: " + alle_li[i].firstChild.className);
			if (alles[i].firstChild.className == "nlinkselected") {
					// alert("Zahl = " + alles[i].firstChild.innerHTML);
					Zahl = alles[i].firstChild.innerHTML;
					// nach oben
					if ( parseInt(Zahl, 10) < intImageCount ) {
						// den aktiven abwählen
						alles[i].firstChild.className = "nlink";
						// den eins danach auswählen
						alles[(i+1)].firstChild.className = "nlinkselected";
						// bild einstellen
						document.getElementById("gPictureFrame").style.backgroundImage = "url(" + strPath + strImageName + alles[(i+1)].firstChild.innerHTML + "." + strFileType + ")";
						// bild text einstellen
						document.getElementById("bildtext").innerHTML = arrText[(parseInt(Zahl, 10)+1)];
						// externes link einstellen falls vorhanden
						if (arrLink[parseInt(Zahl, 10)+1].length > 1) {
							document.getElementById("gExternLink").innerHTML = "<a class='exlink' target='blank' rel='nofollow' href='http://" + arrLink[parseInt(Zahl, 10)+1] + "'>" + arrLink[parseInt(Zahl, 10)+1] + "</a>";
						} else {
							document.getElementById("gExternLink").innerHTML = "&nbsp;";
						}
						return false;
					}
					// zum ersten über den letzten
					if ( parseInt(Zahl, 10) == intImageCount ) {
						alles[i].firstChild.className = "nlink";
						alles[(i-intImageCount+1)].firstChild.className = "nlinkselected";
						document.getElementById("gPictureFrame").style.backgroundImage = "url(" + strPath + strImageName + alles[(i-intImageCount+1)].firstChild.innerHTML + "." + strFileType + ")";
						document.getElementById("bildtext").innerHTML = arrText[(parseInt(Zahl, 10)-intImageCount+1)];
						
						// externes link einstellen falls vorhanden
						if (arrLink[parseInt(Zahl, 10)-intImageCount+1].length > 1) {
							document.getElementById("gExternLink").innerHTML = "<a class='exlink' target='blank' rel='nofollow' href='http://" + arrLink[parseInt(Zahl, 10)-intImageCount+1] + "'>" + arrLink[parseInt(Zahl, 10)-intImageCount+1] + "</a>";
						} else {
							document.getElementById("gExternLink").innerHTML = "&nbsp;";
						}
						
						return;

					}
			}
//		}
	}
}


// animation 
var aktiv = null; 
function toggleAnimation() {
		// status des buttons auslesen
		var status = document.getElementById("gAnim").firstChild.innerHTML
		if (status == "play animation") {
			// ein bild vor
			window.setTimeout('gArrowRight(\'\');', 1000);
			// stop button anzeigen
			document.getElementById("gAnim").firstChild.innerHTML = "stop animation";
			document.getElementById("gAnim").firstChild.title = "Animation anhalten"
			// animation starten
			aktiv = window.setInterval('gArrowRight(\'\');', 4000);
		} else {
			// play button anzeigen
			document.getElementById("gAnim").firstChild.innerHTML = "play animation";
			document.getElementById("gAnim").firstChild.title = "Bilder als Animation wiedergeben";
			// animation anhalten
			window.clearInterval(aktiv);
		}
}

function stopAnimation() {
	document.getElementById("gAnim").firstChild.innerHTML = "play animation";
	document.getElementById("gAnim").firstChild.title = "Bilder als Animation wiedergeben";
	window.clearInterval(aktiv);
}
