//******************************************************************************************
//
//   Object Ebene fuer Dynamisches HTML
//   Version vom 10. Maerz 1999
//   Copyright 1999 Thomas Hieck
//   Verfuegbar auf   http://www.hieck.de/   und   http://www.aquilon.de/
//
//   Diese Klasse darf frei genutz werden, allerdings muss dieser Vermerk bestehen bleiben.
//   Ergaenzungen sollten gekennzeichnet und mir mitgeteilt werden
//
//******************************************************************************************

function Ebene(id,obj) {

    if(ns) this.e = document.layers[id];
    else this.e = document.all[id].style;
    if(ie) this.ee = document.all[id];         // benoetigt fuer this.inhalt

    this.id = id;
    this.obj = obj;
    this.sichtbar = this.e.visibility;
    this.x = (ns) ?  this.e.left : this.e.pixelLeft;
    this.y = (ns) ? this.e.top : this.e.pixelTop;
    this.z = this.e.zIndex;
    this.breite = (ns) ? this.e.clip.width : this.ee.offsetWidth;
    this.hoehe = (ns) ? this.e.clip.height : this.ee.offsetHeight;

    this.zeige = EZeige;
    this.verstecke = EVerstecke;
    this.inhalt = EInhalt;

    this.position = EPosition;
    this.posUm = EPosUm;

    this.bewNach = EBewNach;
    this.bewUm = EBewUm;
    this.bewInit = EBewInit;       // eigentlich als private function
    this.bewege = EBewege;         // eigentlich als private fucntion
    this.bewAktiv = 0;

    this.clipWert = EClipWert;
    this.clipNach = EClipNach;
    this.clipUm = EClipUm;

}

function EZeige() {
    this.sichtbar = "visible";
    this.e.visibility = this.sichtbar;
}

function EVerstecke() {
    this.sichtbar = "hidden";
    this.e.visibility = this.sichtbar;
}

function EInhalt(txt) {
    if(ns){
      this.e.document.open();
      this.e.document.write(txt);
      this.e.document.close();
    }
    else {
      this.ee.innerHTML = txt;
    }
}

function EPosition(x,y) {
    if(x != null) {
      this.x = x;
      this.e.left = this.x;
    }
    if(y != null) {
      this.y = y;
      this.e.top = this.y;
    }
//    eval(this.obj+".inhalt('<table width=\"100\" height=\"100\" border=\"1\" bgcolor=\"#333300\" cellspacing=\"0\"><tr><td align=\"center\" valign=\"middle\">('+parseInt(this.x)+','+parseInt(this.y)+')</td></tr></table>')");
}

function EPosUm(x,y) {
    this.position(this.x+x,this.y+y);
}

function EBewNach(x,y,v) {
    var dx = x-this.x;
    var dy = y-this.y;
    this.bewInit(x,y,dx,dy,v);
}

function EBewUm(dx,dy,v) {
    var x = this.x + dx;
    var y = this.y + dy;
    this.bewInit(x,y,dx,dy,v);
}

function EBewInit(x,y,dx,dy,v) {
    if(this.bewAktiv) return;
    var teiler = Math.sqrt(Math.pow(dx,2) + Math.pow(dy,2)) / v;
    if(teiler == 0) return;
    sx = dx/teiler;
    sy = dy/teiler;
    this.bewAktiv = 1;
    this.bewege(x,y,sx,sy,teiler,1)
}

function EBewege(x,y,sx,sy,teiler,i) {
    if(!this.bewAktiv) return;
    if(i++ < teiler) {
      this.posUm(sx,sy);
      if(this.bewAktiv) setTimeout(this.obj+".bewege("+x+","+y+","+sx+","+sy+","+teiler+","+i+")",30);
      else return;
    }
    else {
      this.bewAktiv = 0;
      this.position(x,y);
      return;
   }
}

function EClipNach(oben,rechts,unten,links) {
    if(ns) {
      this.e.clip.top = oben;
      this.e.clip.right = rechts;
      this.e.clip.bottom = unten;
      this.e.clip.left = links;
    }
    else this.e.clip = "rect("+oben+"px "+rechts+"px "+unten+"px "+links+"px)";
}

function EClipUm(oben,rechts,unten,links) {
    this.clipNach(this.clipWert('oben')+oben,this.clipWert('rechts')+rechts,this.clipWert('unten')+unten,this.clipWert('links')+links);
}

function EClipWert(w) {
  if(ie) var clipw = this.e.clip.split("rect(")[1].split(")")[0].split("px");
  if(w=="oben") return (ns) ? this.e.clip.top : Number(clipw[0]);
  if(w=="rechts") return (ns) ? this.e.clip.right : Number(clipw[1]);
  if(w=="unten") return (ns) ? this.e.clip.bottom : Number(clipw[2]);
  if(w=="links") return (ns) ? this.e.clip.left : Number(clipw[3]);
}

