var x= 16384;
var y= 16384;
var z= 16384;
var tt= 0;
var pressed= 0;
/*
var Simple = [];
Simple["br"] = Simple["hr"] = Simple["link"] = Simple["meta"] = Simple["input"] = Simple["img"] = true;
var Ignore = [];
Ignore["N"] = [];
Ignore["N"]["contentEditable"] = Ignore["N"]["start"] = Ignore["N"]["loop"] = Ignore["N"]["tabIndex"] = true;
Ignore["V"] = [];
Ignore["V"][""] =  Ignore["V"]["false"] =  Ignore["V"][null] =  true;

function MyInnerHtml(node, omit_outer_node)
{
 var N = "";
 if (Simple[node.tagName.toLowerCase()]) {
  if (!omit_outer_node) {
   N += '<' + node.tagName.toLowerCase()  + MyAttributes(node) + ' />';
  }
 } else {
  if (!omit_outer_node) {
   N += '<' + node.tagName.toLowerCase()  + MyAttributes(node) + '>';
  }
  for (var i = 0; i < node.childNodes.length; i++) {
   if (node.childNodes[i].nodeName != "#text") {
    N += MyInnerHtml(node.childNodes[i]);
   }			
   if (node.childNodes[i].nodeName == "#text") {
    N += node.childNodes[i].nodeValue;
   }
  }
  if (!omit_outer_node) {
   N += "</" + node.tagName.toLowerCase() + ">";
  }
 }
 return N;
}

function MyAttributes(node)
{
 var node_attributes = "";
 var ar = new Array();
 var j = 0;
 for (var i = 0; i < node.attributes.length; i++) {
  if (!Ignore["N"][node.attributes[i].nodeName] && !Ignore["V"][node.attributes[i].nodeValue]){
   if (node.attributes[i].nodeName == "style"){
    var a = node.attributes[i].nodeValue.toLowerCase().split(";");
    for (var k =0; k < a.length; k++) {
	 if (a[k][0] == ' ') a[k] = a[k].substring(1);
	 a[k] = a[k].replace(/: /g, ":");
	}
	a.sort();
    ar[j] =  a.join(";");
	if (ar[j][0] == ';') ar[j] = ar[j].substring(1);
    ar[j] =  ' ' + node.attributes[i].nodeName + '="' + ar[j] + '"';
   }
   else ar[j] =  ' ' + node.attributes[i].nodeName + '="' + node.attributes[i].nodeValue + '"';
   j++;
  }
 }
 ar.sort();
 return ar.join("");
}
*/

function SetZIndex(sN, z)
{
 if (z < 0){
  document.getElementById(sN).style.visibility = 'hidden';
  document.getElementById(sN).style.zIndex= -1;
 } else{
  document.getElementById(sN).style.visibility = 'visible';
  document.getElementById(sN).style.zIndex= z;
 }
}


function Szene(Name, Im, A, te, Fe)
{
 this.n= "";
// this.aHtml= [];
 this.t= 0;
 this.dt= 57;
 this.t8= 0;
 this.div0;
 this.dd= 0;
 this.DP;

 this.Init = function(sN, xx, yy, zz)
 {
  var i, j, k;
  var u= 0;
  x = xx; y = yy; z = zz;
  this.n = sN;
  this.div0 = document.getElementById(this.n+0);
  
  document.onselectstart = function () { return false; } //TODO: nötig?
  document.ondrag = function () { return false; } // TODO: nötig?
/*
 // Lese alle Fi Divs in ein zweidumensionales Array von Strings ein
  var s = MyInnerHtml(document.getElementById(this.n+'0'), true);//document.getElementById(this.n).innerHTML;
//alert( s );
  var sa = new Array();
  var i;
  var j;
  var k;
  sa = s.split('<div class="F" ');
  for (i = 1; i < sa.length; i++){
   var F = new Array();
   // Mache ein Subarray F für diese Div  mit abwechselnd bedeutungslosem und bedeutungsvollem Text
   if (i == 1)
    F[0] = sa[0] + '<div class="F" ' + sa[i].substring(0, sa[i].search(/ style="/)+8);
   else
    F[0] = '<div class="F" ' + sa[i].substring(0, sa[i].search(/ style="/)+8);
   var St = sa[i].substring(sa[i].search(/ style="/)+8);
   var S = St.substring(0, St.search(/"/)).split(":");
   F[0] += S[0];
   k=1;
   for (j = 1; j < S.length; j++){
    F[k-1] += ":";
    F[k] = S[j].match(/[0-9\-]+/);
    k++;
    F[k] = S[j].match(/[0-9\-]+([^0-9]*)/); F[k] = RegExp.$1;
    k++;
   }
   St = St.substring(St.search(/"/));
   F[k-1] += St.substring(0, St.search(/ src="/)+6);
   St = St.substring(St.search(/ src="/)+6);
   F[k] = St.substring(0, St.search(/"/));
   k++;
   St = St.substring(St.search(/"/));
   var p = St.search(/ style="/);
   if (p >= 0 && p < St.search(/<div /)){
    F[k] = St.substring(0, p+8);
    St = St.substring(p+8);
    S = St.substring(0, St.search(/"/)).split(":");
    F[k] += S[0];
    k++;
    for (j = 1; j < S.length; j++){
     F[k-1] += ":";
     F[k] = S[j].match(/[0-9\-]+/);
     k++;
     F[k] = S[j].match(/[0-9\-]+([^0-9]*)/); F[k] = RegExp.$1;
     k++;
    }
    St = St.substring(St.search(/"/));
   } else {
    F[k] = '" style="height:'; k++;
    F[k] = '100'; k++;
    F[k] = '%;left:'; k++;
    F[k] = '0'; k++;
    F[k] = '%;top:'; k++;
    F[k] = '0'; k++;
    F[k] = '%;width:'; k++;
    F[k] = '100'; k++;
    F[k] = '%'; k++;
   }
   F[k-1] += St;
   this.aHtml[i-1] = F;
//if ( i == 1 ) alert( this.aHtml[i-1].join('') );
  }
// Erzeuge ein zweites Array durch Kopieren
*/
// vorhandene Bilder in das Image-Array stellen:
  for (k= 0; k < 5; k++){
   var l= (A[1][k]).length;
   for (i= 0; i < l; i++){
    u++;
    var kk = k*16+i;
    var No= true;
    var s=document.getElementById('I'+kk).src;
	s= s.substr(s.indexOf('Web'), s.length);
	s= s.substring(0, (s.indexOf('.gif') > 0 ? s.indexOf('.gif')+4 : (s.indexOf('.jpg') > 0 ? s.indexOf('.jpg')+4 : (s.indexOf('.jpeg') > 0 ? s.indexOf('.jpeg')+5 : s.length))))
    if (Im.length == 0){
     Im[0]= new Object();
     Im[0].F =1;
     Im[0].P= new Image(); Im[0].P.src= s;
    } else {
     for (j=0; j < Im.length; j++){
      if (Im[j].P.src.search(RegExp(s,'i')) >= 0 || s.search(RegExp(Im[j].P.src,'i')) >= 0) break;
     }
     if (j == Im.length){
      Im[j]= new Object();
      Im[j].F= 1;
      Im[j].P= new Image(); Im[j].P.src= s;
     }
    }
   }
  }  
 /*
  for (i= 0; i < this.aHtml.length; i++){
   var No= true;
   for (j=0; j < Im.length; j++){
    if (Im[j].P.src.search(RegExp(this.aHtml[i][13],'i')) >= 0){ No = false; break;}
   }
   if (No){
    j= Im.length;
    Im[j]= new Object();
	Im[j].F =1;
    Im[j].P= new Image(); Im[j].P.src= this.aHtml[i][13];
//alert(j + '  '+Im[j].P.src);
   }
  }
  */

// DOM-Elemente referenzieren
  this.DP= document.getElementById('F'+0).parentNode;
  this.dd= this.DP.childNodes.length-1;
  u--;
  while (this.DP.childNodes[this.dd].id != 'F'+u && this.dd > 0) this.dd--;
  this.t8= new Date().getTime();
 }

 this.Laden = function()
 {
   var tn= new Date().getTime();
   this.dt= Math.floor(57 - (tn - this.t8 - 480)/16);
   this.t8= tn;
 //Korrigiere Geschwindigkeit
  ;//TODO: Lade Bilder
 }

 this.Phase = function(ar, n)
 {
 // Ändere verstecktes zweidimensionales Array, also Array d, aufgrund der Array-Daten zum Array ar unter Berücksichtigung  der Phasendauer n
 // if (tt < 9) alert(tt + " " + ar + " " + n);
 // Aktualisiere verstecktes zweidimensionales Array mit den aktuellen Werten
//if (ar !=0) return;
  switch (pressed){
  case 1: z-=1; break;
  case 2: x+=1; z-=1; break;
  case 3: x+=1; break;
  case 4: x+=1; z+=1; break;
  case 5: z+=1; break;
  case 6: x-=1; z+=1; break;
  case 7: x-=1; break;
  case 8: x-=1; z-=1; break;
  }
  var l= (A[1][ar]).length;
  var ddd= this.dd;
//  if (tt < 4) alert(l);
  while (--l>=0){
   var AT= A[1][ar][l];
//alert('l='+l);
//with (AT){alert("(function(t)"+T+")("+(tt - t)+")")};
   with (AT){
    if (T != '{;}')eval("(function(t)"+T+")("+(tt - t)+")");
    var IT= Im[I[i]];
    var F= (Z < z ? 500/(z - Z) : 500/(2*z + Z - 16384));
    var xf= (X >= 0 ? F*(X - x) : F*(16384 - X - 2*x));
    var wp= Math.round(F*W);
    var a= (xf+wp/2)/500;
    var xp= Math.round(xf) +368 + (s<0 || (a >-0.082 && a<=0.082) ? 0 : (a > 0 ? s : -s));
    wp= (s==-2 ? wp : ((s==-1 && xf>=0) || (s==-3 && xf<=0) ? 0 : (s==-1 ? Math.round(wp*(Math.atan(xf/-500)-Math.atan(xf/-1000))/0.322) : Math.round(wp*(Math.atan(xf/500)-Math.atan(xf/1000))/0.322))));
    var k = ar*16+l;
    while (this.DP.childNodes[ddd].id != 'F'+k && ddd > 0) ddd--;
	if (c%2==1 || pressed>0)
     with (this.DP.childNodes[ddd].style){
      height= Math.round(F*H) + 'px';
      top= (Math.round(Y >= 0 ? F*(y - Y) : F*(2*y+Y - 16384))-184) + 'px';
      width= wp + 'px';
      left= (s==-3 ? xp - wp : xp) + 'px';
      fontSize= Math.round(F*S/10) + 'px';
      var ZZ= (Z >= 0 ? Z : 16384 - z - Z);
//  if (tt == 0 && k > 12) alert('h'+height+' t'+top+' w'+width+' l'+left+' z'+ZZ);
      if (z - ZZ > 0) {visibility = 'visible'; zIndex= ZZ;} else {visibility = 'hidden'; zIndex= 0;}
     }
    if ((c>>1)%2==1) document.getElementById('I'+k).src = IT.P.src;
    if ((c>>2)%2==1)
	 with (document.getElementById('I'+k).style){
      left= (w == 100 ? 0 : 50 - w/2 - 100 *(a>0.082 ? Math.round(Math.log(a)) : (a>-0.082 ? 0 : -Math.round(Math.log(-a))))) +'%';
      top= (-j) + '%';
      height= h + '%';
      width= w + '%';
     }
   }
  }
 }
 
 this.Schritt = function()
 {
  if (tt==0) this.t = new Date().getTime();
  var t1 = new Date().getTime();
  this.Phase(0, 1);
  if (tt % 2 == 0) this.Phase(1, 2);
  else {
   if (tt % 4 == 1) this.Phase(2, 4);
   else {
    if (tt % 8 == 3) this.Phase(3, 8);
    else {this.Phase(4, 8); this.Laden();}
   }
  }
  tt++;
//  if (tt < 2) alert("oh "+tt);
  if ((Fe != '{;}' && tt >= te) || (tt == 5 && new Date().getTime() - this.t > 1000))
   eval("(function(t)"+Fe+")("+(tt)+")");
  else {
   var t = this.dt + t1 - new Date().getTime();
   window.setTimeout(Name+".Schritt()", (t > 0 ? t : 0));
  }
 }

};

