/* ========================================================================
|	Layer.js - JavaScript Klasse zur browserunabhaengigen Manipulation     |
|			   von Ebenen.                                                 |
|																		   |
|	(C) 11/1999 by Oliver Kutter (o.kutter@e-7.com)	                       |
|	some code added by norman timmler @ neteye°° GmbH (norman@net-eye.de)  |
|																		   |	
|   Class: Layer                     									   |
|   Konstruktor   : Layer(name, vis) 									   |
|   Eigenschaften : x, y, z, breite, hoehe, sichtbar					   |
|                   style - Verweis auf style Eigenschaft (private)		   |
|   Unterobjekt: clip. - oben, unten, links, rechts (nur nach setClip)     |
|   Methoden : moveTo, moveBy, setSize, setClip, modClip, setVis,	  	   |
|              writeIn                                                     |
 =========================================================================*/

// Browsercheck		
ns  = (document.all) ? false : true;
ns6 = (!document.all && document.getElementById) ? true : false;
ie  = (document.all) ? true : false;
mac = (navigator.appVersion.indexOf("Mac") != -1) ? true : false; 

lpre = (ns) ? "document.layers." : "document.all.";
lpost = (ns) ? "" : ".style";

// ===> END
 // ==> BEGIN KONSTRUKTOR Layer
 function Layer(name, vis, frame) {
   // Ebenenobjekt aus DOM ermitteln + style Eigenschaft
   if ((frame != "") && (typeof frame != "undefined")) {
        prePath = "top.frames." + frame + ".";
   } else {
        prePath = "";
   }
   
   if (ns && !ns6) {
   		this.obj = eval(prePath + "document.layers[\"" + name + "\"]");
   		this.style = eval(prePath + "document.layers[\"" + name + "\"]");

   } else if (ns6) { 
   		this.obj = eval(prePath + "document.getElementById(\"" + name + "\")");
   		this.style = eval(prePath + "document.getElementById(\"" + name + "\").style");
		
   } else {
   		this.obj = eval(prePath + "document.all." + name);
   		this.style = eval(prePath + "document.all." + name + ".style");
   }
   
   // Startwerte aus Ebene lesen
   this.x = (ns || ns6) ? parseInt(this.style.left) : parseInt(this.style.pixelLeft);
   this.y = (ns || ns6) ? parseInt(this.style.top) : parseInt(this.style.pixelTop);
   this.z = parseInt(this.style.zIndex);
   this.breite = (ns || ns6) ? parseInt(this.style.clip.width) : parseInt(this.style.width);
   this.hoehe = (ns || ns6) ? parseInt(this.style.clip.height) : parseInt(this.style.height);

   // Sichtbarkeit aus Parameter
   this.sichtbar = vis;
      
   // Weitere Definitionen
   this.clip = new Clip(0,0,0,0);
  
   // ===> BEGIN Methoden Deklaration
   Layer.prototype.moveTo = layer_moveTo;
   Layer.prototype.setSize = layer_setSize;
   Layer.prototype.moveBy = layer_moveBy;
   Layer.prototype.setVis = layer_setVis;
   Layer.prototype.setClip = layer_setClip;
   Layer.prototype.modClip = layer_modClip;
   Layer.prototype.writeIn = layer_writeIn;
   Layer.prototype.bgColor = layer_bgColor;
   Layer.prototype.setEvent = layer_setEvent;
   // ===> END Methoden Deklaration

   return this;
 }
 // ===> END KONSTRUKTOR Layer
 
 // ===> BEGIN Methoden Implementierung
 
 // layer_moveTo(x, y) - Positioniert die Ebene bei x, y
 function layer_moveTo(x, y) {
   this.x = x;
   this.y = y;
   this.style.left = x;
   this.style.top = y;
 }
 
 // layer_setSize(name, x, y) - Aendert die Ausdehnung der Ebene auf x * y
 function layer_setSize(breite, hoehe) {
   this.breite = breite;
   this.hoehe = hoehe;
   this.style.width = breite;
   this.style.height = hoehe;
 }
 
 // layer_setVis - Setzt die Sichtbarkeit der Ebene auf sichtbar (true), bzw. unsichtbar (false)
 function layer_setVis(vis) {
   this.sichtbar = vis;

   if(vis) {
     this.style.visibility = "visible";
   } else {
     this.style.visibility = "hidden";
   }
 }
 
// layer_moveBy(x, y) - Verschiebt die Ebene um x, y
function layer_moveBy(x, y) {
  this.x = this.x + x;
  this.y = this.y + y;
  this.style.left = this.x;
  this.style.top = this.y;
}

// layer_setClip(oben, rechts, unten, links) - Setzt die Clip Eigenschaft
function layer_setClip(oben, rechts, unten, links) {
     this.clip.oben = oben;
	 this.clip.rechts = rechts;
	 this.clip.unten = unten;
	 this.clip.links = links;
   if(ns) {
     this.style.clip.top = oben;
	 this.style.clip.right = rechts;
	 this.style.clip.bottom = unten;
	 this.style.clip.left = links;   
   } else {
     this.style.clip = "rect(" + oben + " " + rechts + " " + unten + " " + links + ")";
   }
}

// layer_modClip(oben, rechts, unten, links) - Modifiziert die Clip Eigenschaft
function layer_modClip(oben, rechts, unten, links) {
  this.setClip(this.clip.oben + oben, this.clip.rechts + rechts, this.clip.unten + unten, this.clip.links + links);
}

// layer_writeIn(html) - Schreibt in das Layer
function layer_writeIn(html) {
  if (ns) {
	this.obj.document.open("text/html");
	this.obj.document.write(html);
	this.obj.document.close();
  }	else {
    this.obj.innerHTML = html;
  }
}

// layer_bgColor(color) - Setzt Hintergrundfarbe des Layers
function layer_bgColor(color) {
	if (ns) {
		this.style.bgColor = color;
	} else {
		this.style.backgroundColor = color;
	}
}

// layer_setEvent(which, functionCall) - aktiviert Event
function layer_setEvent(which, functionCall) {
	if (typeof eval(functionCall) == "function") {
		eval("this.obj." + which.toLowerCase() + " = " + functionCall + ";");
	}
}

// ===> END Methoden Implementierung

// ===> BEGIN Hilfsklasse Clip
function Clip(oben, rechts, unten, links) {
  this.oben = parseInt(oben);
  this.rechts = parseInt(rechts);
  this.unten = parseInt(unten);
  this.links = parseInt(links);
  return this;
}
// ===> END Hilfsklasse Clip
