var NS = typeof(document.layers) != 'undefined';
var IE = typeof(document.all) != 'undefined';

if ((typeof(document.layers) == 'undefined') && (typeof(document.all) == 'undefined')) {
	NS = true;
}

if (IE) {
	SHOW = "visible";
	HIDE = "hidden";
}
if (NS) {
	SHOW = "show";
	HIDE = "hide";
}

function ie_write(arg) {
	this.textToWrite += arg;
}

function ie_open(doc) {
	this.textToWrite = "";
}

function ie_close(doc) {
	this.innerHTML = this.textToWrite; // flush
	this.textToWrite = null; // freeeeeee
}

  function offsetTop1(el)
  {
y = el.offsetTop
    for (e = el.offsetParent; e; e = e.offsetParent)
      y += e.offsetTop;
    return Math.floor(y)
  } 
  function offsetLeft1(el)
  {
    x = el.offsetLeft
    for (e = el.offsetParent; e; e = e.offsetParent)
      x += e.offsetLeft;
    return Math.floor(x)
  } 
function getLayer(id){
	var layer = (NS) ? document[id] : document.all[id].style;
	layer.doc = (NS) ? document.layers[id].document : document.all[id];
	if (IE) {
		layer.doc.write = ie_write;
		layer.doc.open = ie_open;
		layer.doc.close = ie_close;
		// reparatur fuer IE5 (posTop ist initial immer auf null)
		layer.posInitialTop = offsetTop1(document.all[id]);
		layer.posInitialLeft = offsetLeft1(document.all[id]); //.offsetParent.offsetLeft;
	}
	else {
		layer.posInitialTop = Math.floor(layer.pageY);
		layer.posInitialLeft = Math.floor(layer.pageX);
	}
	layer.clipTo = Layer_clipTo;
	layer.getWidth = Layer_getWidth;
	layer.getHeight = Layer_getHeight;
	layer.getLeft = Layer_getLeft;
	layer.getTop = Layer_getTop;
	layer.getAbsoluteLeft = Layer_getAbsoluteLeft;
	layer.getAbsoluteTop = Layer_getAbsoluteTop;
	layer.resize = Layer_resize;
	layer.write = Layer_write;
	layer.changeImage = Layer_changeImage;
	if (IE) {
		layer.moveTo = Layer_moveTo;
		layer.moveBy = Layer_moveBy;
	}		
	return layer;

}

function Layer_write(text) {
  this.doc.open();
  this.doc.write(text);
  this.doc.close();
}

function Layer_changeImage(name, url) {
  if (typeof(name) != "string") {
	return;
  }	
  if (!(url && url != '')) {
	url = pixt_url;
  }
  if (IE) {
	document.images[name].src = url;
  }
  if (NS) {
	this.doc.images[name].src = url;
  }
}

function _setHeight(layer, h){
	if (NS) {
		layer.clip.height  = Math.floor(h);
	}
	if (IE) {
	  layer.clientHeight = Math.floor(h);
	}
}
function _setWidth(layer, w){
	if (NS) {
		layer.clip.width  = Math.floor(w);
	}
	if (IE) {
	  layer.clientWidth = Math.floor(w);
	}
}
function Layer_getTop() {
	var top = (NS) ? this.top : this.posTop;
	return Math.floor(top);
}
function Layer_getAbsoluteTop() {
	var top = (NS) ? this.pageY : this.posTop;
	return Math.floor(top);
}
function Layer_getAbsoluteLeft() {
	var left = (NS) ? this.pageX : this.posLeft;
	return Math.floor(left);
}
function Layer_getLeft() {
	var left = (NS) ? this.left : this.posLeft;
	return Math.floor(left);
}
function Layer_getHeight() {
	var h = (NS) ? this.document.height : this.doc.scrollHeight;
	return Math.floor(h);
}
function Layer_getWidth() {
	var w = (NS) ? this.document.width : this.doc.scrollWidth;
	return Math.floor(w);
}
function Layer_moveTo(x, y) {

	this.top  = Math.floor(y);   



	this.left  = Math.floor(x);   
}
function Layer_moveBy(x, y) {
	//alert("Layer_moveBy(" + x + "," + y + ")");
	this.top  = this.getTop() + Math.floor(y);   
	this.left  = this.getLeft() + Math.floor(x);   
}
function Layer_clipTo(x, y, w, h) {
	if (NS) {
		this.clip.left  = Math.floor(x);
		this.clip.top  = Math.floor(y);
		this.clip.width  = Math.floor(w);
		this.clip.height  = Math.floor(h);
	}
	if (IE) {
	  	var left = Math.floor(x);
	  	var top = Math.floor(y);
	  	var width = Math.floor(w);
	  	var height = Math.floor(h);
		this.clip = "rect("+top+"px "+(left+width)+"px "+(top+height)+"px "+left+")";
	}
}
function Layer_resize(width, height) {
	this.clipTo(this.getLeft(), this.getTop(), width, height);
}
   function set_layer_z(id,z){
     var layer = get_layer(id);
     if(layer){
        layer.zIndex = Math.floor(z);
     }     
   }
   function get_layer_y(id,y){
     var layer = get_layer(id);
     if(layer){
        return (NS4) ? layer.top : layer.posTop;
     }     
   }
  


