var lastbild = bilder.length-1;
var x,y,w,h,fs,startx,starty,startw,starth,startfs,endx,endy,endw,endh,endfs,stepx,stepy,stepw,steph,stepfs;
var offsetx=0, offsety=0;
var bildnr = -1;
var oldtitle;
var aktiv = 0;
var count = 0;
var done = 1;
var dummy;
var areax=parseFloat(document.getElementById("rahmen").style.left);
var areay=parseFloat(document.getElementById("rahmen").style.top);
var areaw=parseFloat(document.getElementById("rahmen").style.width);
var areah=parseFloat(document.getElementById("rahmen").style.height);

if (adjust_pos == 1 || adjust_pos == 3)
   {
   if(document.all)
     {offsetx=(document.body.offsetWidth/2-areaw/2-areax);}
   else
     {offsetx=(screen.width/2-areaw/2-areax);}
   }
if (adjust_pos == 2 || adjust_pos == 3)
   {
   if(document.all)
     {offsety=(document.body.offsetHeight/2-areah/2-areay);}
   else
     {offsety=(screen.height/2-areah/2-areay);}
   }
move_center('mi_start');
move_center('skip');
move_center('meldung');

dummy=BildCheck();
watch = window.setInterval("manager()",zeit);

function manager()
{
dummy = BildCheck();  //prüfen, on alle Bilder geladen sind
if (dummy == 0)
    {
    //document.getElementById("meldung").firstChild.data = "moment bitte!";
    return;
    };
count =count + 1; // nur zur kontrolle
//document.all.meldung.innerText=" bildnr: "+bildnr + " count:" +count +" offset: " + offsetx +"/" +offsety; // zur kontrolle
if (bildnr == lastbild && done == 1)
 {
 // wenn letztes bild gezeigt, abbrechen
 window.clearInterval(watch);
 melde(last_message);
 done = 999;
 if (neue_url !="")
    {
    window.setTimeout("next_page()",3000);
    }
 }

if (done == 1)
 {
 if (bildnr < lastbild)
  {
  // nächstes bild einleiten
  bildnr = bildnr + 1;
  init_img(bilder[bildnr]);
  done = 0;
  }
 }
if (done == 0)
 {
  // aktuelles bild bewegen
  moveimg(bilder[bildnr]);
 }
}

function next_page()
{
  top.location.href=neue_url;
}

function BildCheck()
{
 var Status = "";
 for(i = 0; i < document.images.length; ++i)
 {
  if(document.images[i].complete == true)
   {Status = Status + "" + (i+1) ;}
  else
   {Status = Status + "" + "x";}
 }
 var warten = Status.indexOf("x");
 if (warten == -1)
  {
  melde("");
  return 1;
  }
 else
  {
  melde("loading..."+Status);
  return  0;
  }
}

function melde(text)
{
  if(document.all)
  {document.getElementById("meldung").innerHTML = text;}
  else
  {
  document.getElementById("meldung").firstChild.data = text;
  }
}

function init_img(bildid)
{
if (document.getElementById(bildid).style.fontSize)
{}
else
{document.getElementById(bildid).style.fontSize=basefontsize+"pt";}
endx = parseFloat(document.getElementById(bildid).style.left);
endy = parseFloat(document.getElementById(bildid).style.top);
endh = parseFloat(document.getElementById(bildid).style.height);
endw = parseFloat(document.getElementById(bildid).style.width);
endfs = parseFloat(document.getElementById(bildid).style.fontSize);
endx = endx+offsetx;
endy = endy+offsety;
startx=parseFloat(document.getElementById("mi_start").style.left);
starty=parseFloat(document.getElementById("mi_start").style.top);
startw=parseFloat(document.getElementById("mi_start").style.width);
starth=parseFloat(document.getElementById("mi_start").style.height);
startfs=parseFloat(document.getElementById("mi_start").style.fontSize);
//startfs=1;
x=startx;
y=starty;
w=startw;
h=starth;
fs=startfs;
stepx = (endx-startx)/steps;
stepy = (endy-starty)/steps;
stepw = (endw-startw)/steps;
steph = (endh-starth)/steps;
stepfs = (endfs-startfs)/steps;
//stepx=5;stepy=5;stepw=1;steph=1;
xstatus = 0;
ystatus = 0;
}

function move_center(id)
{
 dummy = parseFloat(document.getElementById(id).style.left) + offsetx;
 document.getElementById(id).style.left = dummy;

 dummy = parseFloat(document.getElementById(id).style.top) + offsety;
 document.getElementById(id).style.top = dummy;
}


function moveimg(bildid)
{
   //done = 0;
   document.getElementById(bildid).style.display = "block";
   x=x+stepx;
   document.getElementById(bildid).style.left = x;
   y=y+stepy;
   document.getElementById(bildid).style.top = y;
   w=w+stepw;
   document.getElementById(bildid).style.width = w;
   h=h+steph;
   document.getElementById(bildid).style.height = h;
   fs=(fs+stepfs);
   document.getElementById(bildid).style.fontSize = fs+"pt";

   if(document.getElementById(bildid).title)
      {
      melde(document.getElementById(bildid).title);
      oldtitle =document.getElementById(bildid).title;
      }
   else
     {
     melde(oldtitle)
     }

  if (x >= endx && startx < endx){xstatus=1}
  if (y >= endy && starty < endy){ystatus=1}
  if (x <= endx && startx > endx){xstatus=1}
  if (y <= endy && starty > endy){ystatus=1}

  if ((xstatus == 1) && (ystatus ==1))
  {
   document.getElementById(bildid).style.left = endx;
   document.getElementById(bildid).style.top = endy;
   document.getElementById(bildid).style.width = endw;
   document.getElementById(bildid).style.height = endh;
   document.getElementById(bildid).style.fontSize = endfs+"pt";
   //bildnr = bildnr +1 ;
   //window.clearInterval(aktiv);
   done = 1;
  }
}
