// Funktion kann mit JavaScript Bilder schrittweise (animiert) umblättern
// Die Element-ID des auszublendenden Elements wird als Zeichenkette angegeben.
// Der zweite Parameter gibt die Schrittweite in % an, mit der das Bild ein- oder
// ausgeblendet werden soll. Negative Werte blenden aus; Positive blenden ein
// Beim InternetExplorer sind das % von 1, ansonsten % von 100

timeoutNachZeit=0;
timeoutTurn=0;
aktivTurn=null;
var status='aus';

function turnoverOnLoad()
{
 setTimeout(function(){turnoverOnLoadTimeout();},16000);
}

function turnoverOnLoadTimeout()
{
 
 AktuellesBild+=1;
 if ( AktuellesBild >= maxBild ) AktuellesBild=0;
 turnover('Division11', 'TextLeer', bild[AktuellesBild]);
 setTimeout(function(){turnoverOnLoadTimeout();},12000);
}

function turnoverNachZeit(mydivision,myhtml,background)
{
 timeoutNachZeit=setTimeout(function(){turnover(mydivision, myhtml, background);},500);
}

function turnover(mydivision,myhtml,background)
{
 clearTimeout(timeoutNachZeit);
 timeoutNachZeit=0;
 mynewbg='url("'+background+'")';
 if ( status!='aus' )
 {
  //nur das juengste Ereignis bleibt bestehen
  clearTimeout(timeoutNachZeit);
  timeoutNachZeit=0;
  clearTimeout(timeoutTurn);
  timeoutTurn=0;
  timeoutTurn=setTimeout(function(){turnover(mydivision, myhtml, background);},2);
 }
 else
 {
  turnover_start(mydivision, myhtml, mynewbg);
 }
}

function turnover_start(mydivision,myhtml,mynewbg)
{
 document.getElementById (mydivision).innerHTML="";
 turn(mydivision, myhtml, mynewbg, -15);
 status='turnover';
}

function turnback(mydivision,myhtml,mynewbg)
{
 document.getElementById (mydivision).innerHTML="";
 document.getElementById (mydivision).style.backgroundImage=mynewbg;
 turn(mydivision, myhtml, mynewbg, 15);
 status='turnback';
}

function turn(mydivision, myhtml, mynewbg, step) 
{
 // Wenn das Element existiert
 if (document.getElementById (mydivision))
 {
  // Intervall noch nicht gestartet?
  if (!aktivTurn) 
  {
   // Schrittweite muss positiv  sein, da
   // sonst nicht ausgeblendet wird.
   if ( step == 0) 
   {
    // Fehlermeldung und Beenden, wenn Schrittweite >= 0
    alert ('Schrittweite darf nicht 0 sein!');
    return;
   }
   // Ansonsten kann die Animation gestartet werden.
    window.clearInterval (aktivTurn);
   aktivTurn = null;
   aktivTurn = window.setInterval ('turn("' + mydivision + '", "' + myhtml + '", \'' + mynewbg + '\', ' + step + ')', 1);
   if (step<0) status=status+'ausblenden';
   else status=status+'einblenden';
  }
  else 
  {
   // Wir befinden uns bereits in der Ein- Ausblendphase
   var e = document.getElementById (mydivision);
   var mywidth;
   help=e.offsetWidth + step;
   mywidth = help + 'px';  
   if ( (step < 0 && help > 0) || ( step > 0 && help < mydivwidth ) ) 
   {
    e.style.width=mywidth;
   }
   else 
   {
    // Endzustand (vollständig ein-/ausgeblendet) erreicht!
    // Prozess kann nun abgebrochen werden.
    if ( step < 0 ) 
    {
     window.clearInterval (aktivTurn);
     aktivTurn = null;
     turnback(mydivision, myhtml, mynewbg);
    }
    else 
    {
     document.getElementById (mydivision).innerHTML=document.getElementById (myhtml).innerHTML;
     window.clearInterval (aktivTurn);
     aktivTurn = null;
     e.style.width=mydivwidth +'px';
     status='aus';
    }
   }
  }
 }
 else alert("Das Element "+mydivision+" existiert nicht");
}



