var afoto=0;
var aplauf=0;
var apvar;

if (!ziffern) {
  var ziffern=2;
}

//Umwandlung der Zahlen in Strings mit evtl führender 0 (Umweg über a und zahl für korrekte umwandlung
function zn(zahl) {
 var n = ""
 n="a"+zahl;
 var nullen=0;
 nullen=ziffern-(n.length-1);
 n=""+zahl;
 //if (n.length==3) {n=zahl+""}
 //else if(n.length==2) {n="0"+zahl;}
 for(var i=1; i<=nullen; i++) {
  n="0"+n;
 }
return n;
}

//Definition der Bilder
images = new Array(gfoto);
for(var i = 1; i <= gfoto; i++)
{
 images[i] = new Image();
 images[i].scr = praefix+zn(i)+".jpg";
}

function chance(fnummer)
{
 if (aplauf==1) {return}
 if (afoto==fnummer) {return}
 reallyChance(fnummer);
return
}
function reallyChance(fnummer) {
 document.getElementById("bild").src = images[fnummer].scr;
 document.getElementById("bild").alt = fnummer;
 document.getElementById("bildunterschrift").firstChild.nodeValue = fnummer;
 if (afoto > 0) document.getElementById("UB" + afoto).style.borderColor = "#0000FF";
 document.getElementById("UB" + fnummer).style.borderColor = "#FF0000";
 afoto=fnummer;
return
}
function add()
{
 if (aplauf==1) {return}
 x = afoto + 1;
 if(x > gfoto) {x = 1};
 reallyChance(x);
return
}
function sub()
{
 if (aplauf==1) {return}
 var x;
 x = afoto - 1;
 if(x < 1) {x = gfoto};
 reallyChance(x);
return
}
function subx()
{
 if (aplauf==1) {return}
 reallyChance(1);
return
}
function addx()
{
 if (aplauf==1) {return}
 reallyChance(gfoto);
return
}
function ap()
{
 if (aplauf==0) {return}
 var x;
 x = afoto + 1;
 if(x > gfoto) {x = 1};
 reallyChance(x);
return
}
function apstart()
{
 if (aplauf!=0) {return}
 aplauf=1;
 apvar = window.setInterval("ap();",wzeit*1000);
 document.getElementById("playbtn").style.display = "none";
 document.getElementById("stopbtn").style.display = "inline";
 for (i=1; i<=4 ; i++ )
  document.getElementById("m" + i + "btn").style.display = "none";
return
}
function apstop()
{
 if (aplauf!=1) {return}
 aplauf=0;
 window.clearInterval(apvar);
 document.getElementById("playbtn").style.display = "inline";
 document.getElementById("stopbtn").style.display = "none";
 for (i=1; i<=4 ; i++ )
  document.getElementById("m" + i + "btn").style.display = "inline";
return
}
function init()
{
 var NeuUB;
 var NeuUL;
 document.getElementById("stopbtn").style.display = "none";
 for(var i = 1; i <= gfoto; i++) {
  NeuUL = document.createElement("a");
  NeuUL.href = "JavaScript:chance(" + i + ");";
  NeuUB = document.createElement("img");
  NeuUB.src = praefix + zn(i) + "k.jpg";
  NeuUB.alt = i;
  NeuUB.style.margin = "0px 2px 0px 2px";
  NeuUB.style.border = "solid 2px #0000FF";
  NeuUB.id = "UB" + i;
  NeuUL.appendChild(NeuUB);
  document.getElementById("uesicht").appendChild(NeuUL);
 }
return
}
