//	E B E N E N
//  browserübergreifende Hilffunktionen zum Ermitteln von Ebenen, Ebenenpositionen, 
//  sowie zum Ein- und Ausblenden von HTML-Elementen
//  (c) Alexander Zauner 2007

//						H I L F S F U N K T I O N E N
//  Kurzform für getElementById
function $(id) {
	return document.getElementById(id);
	}
	
//  Kurzform für innerHTML
function injectHTML(id,text) {
	if($(id)) {
		$(id).innerHTML = text;
		}
	}

//  Koordinaten-Objekt
function Coord(x,y)
	{
	this.x = (!x) ? 0 : x;
	this.y = (!y) ? 0 : y;
	
	this.toString = objToString;
  	this.equals = equalsCoord;
}
 
/**
 * liefert eine Stringrepräsentation des Objektes Coord
 * einschießlich seiner Daten, 
 * ausschließlich seiner Methoden 
 * 
 * @return: String
 */ 
function objToString(){
  var ret = "{";
  for(prp in this ){
    if (typeof this[prp] == "function" || isObject(typeof this[prp])) 
      continue;
    if(ret.length > 1)
      ret += ",";
    ret += prp + ":" + this[prp];
  }
  return ret + "}";
}

/**
 * vergleicht 2 Coord-Objekte. Diese sind genau dann gleich,
 * wenn seine x- und y-Eigenschaften gleiche Werte enthalten.
 * 
 * @param: Coord 
 * @return: boolean (true, false)
 */ 
function equalsCoord(c){
  return (this.x == c.x && this.y == c.y);
}
	
	
//  Ebenen-Objekt 
function Layer(left, top, width, height) {
	this.left = (!left) ? 0 : left;
	this.top = (!top) ? 0 : top;
	
	this.width = (!width) ? 0 : width;
	this.height = (!height) ? 0 : height;
	this.equals = equalsLayer;
	this.toString = objToString;
}

function equalsLayer(l) {
	return (this.left == l.left && this.top == l.top && this.width == l.width && this.height == l.height);
}

			
//						S T Y L E S / L A Y E R S
	
//  Layer öffnen 
 function openLayer(layer) {
	layer.style.visibility = "visible";
	}
 function openLayerById(id) {
	openLayer($(id));
 	}
	
	
//  Layer schliessen
function closeLayer(layer) {
	layer.style.visibility = "hidden";
	}
function closeLayerById(id) {
	closeLayer($(id));
	}
	
 //  Schalter für Layer
 function toggleLayer(id)
 	{
 	var currStyle = $(id).style;
 	currStyle.visibility = (currStyle.visibility == "visible") ? "hidden" : "visible";
 	}
	
 
//  LAYERDATEN 
//  Position eines Layers ermitteln
function getPosition(element) {
	if(!isObject(element)) return false;
	
	var left = getPosX(element);
	var top = getPosY(element);
	
	var width = element.offsetWidth;
	var height = element.offsetHeight;
	
	return new Layer(left,top,width,height);
}

//  linker Rand eines DOM-Elements
function getPosX(e) {
	if(!e) return -1;
	return (e.offsetParent) ? e.offsetLeft + getPosX(e.offsetParent) : e.offsetLeft;
	}
	
//  oberer Rand eines DOM-Elements
function getPosY(e) {
	if(!e) return -1;
	return (e.offsetParent) ? e.offsetTop + getPosY(e.offsetParent) : e.offsetTop;
	}

//  ist Ebene sichtbar 
function isVisible(id){
	if($(id) == null) return false;
	if($(id).style.visibility == "visible") return true;
	return false;
	}

 
 //			H T M L  -  K O M P O N E N T E N   E I N / A U S B L E N D E N

 function toggleElement(id) {
 	var currStyle = $(id).style;
 	currStyle.display = (currStyle.display == "none") ? "block" : "none";
 	}
	
  //  klappt nur bei IE und neuen Firefox-Browsern
 function closeElement(id)
 	{
 	$(id).style.display = "none";
 	}
 	
  //  klappt nur bei IE und neuen Firefox-Browsern
 function openElement(id)
 	{
 	$(id).style.display = "";
 	}
 	

	
//  Mausposition eruieren
function getMouseXY(e) {
        var xPos  =  (e) ? e.pageX : window.event.x;
        var yPos  =  (e) ? e.pageY : window.event.y;
        
       // IE
       if(document.all && document.attachEvent) {
		   if(!e) e = window.event;
		   xPos = e.clientX;
		   yPos = e.clientY;
	   }
 
		return new Coord(xPos,yPos);
	}

