//  All code by Gunni Rode | © netbureauet ARANEUM 2000 | http://www.na.dk

NA_Layer.id      = 'NALayer';
NA_Layer.css_id  = 'NALayerCSS';
NA_Layer.layers  = [];
NA_Layer.minZ    = 0;
NA_Layer.maxZ    = 0;

function NA_Layer(pID, pRef, pX, pY, pZ, pVisibility, pWidth, pHeight, pDontClip) {
	this.id          = NA_Layer.css_id + pID;
	this.name        = NA_Layer.id     + pID;
	if (NABrowser.ns) {
	  if (NABrowser.ns4) {
  		this.reference   = (pRef)      ? 'document.' + pRef + '.' : '';
      this.css         = eval(this.reference + 'document.' + this.id);
    	!this.css && alert('UNDEF: ' + this.id + ' ' + this.name);
  	  this.document    = this.css.document;
  	  this.element     = this.css;
    	this.events      = this.css;
		} else {
			this.element  = document.getElementById(this.id);
			this.css      = this.element.style;
    	!this.css && alert('UNDEF: ' + this.id + ' ' + this.name);
			this.document = document;
      this.events   = this.element;    
    }
	} else {
  	this.css         = eval('document.all.' + this.id + '.style');
  	!this.css && alert('UNDEF: ' + this.id + ' ' + this.name);
  	this.document    = document;
	  this.element     = this.document.all[this.id];
  	this.events      = this.element;
  }
	
	this.x           = pX      || ((NABrowser.ns4) ? this.css.left        : this.element.offsetLeft);
	this.y           = pY      || ((NABrowser.ns4) ? this.css.top         : this.element.offsetTop);
	this.z           = pZ      || this.css.zIndex || 0;
	this.width       = pWidth  || ((NABrowser.ns4) ? this.css.clip.width  : (this.element.offsetWidth)  ? this.element.offsetWidth  : this.css.pixelWidth);
	this.height      = pHeight || ((NABrowser.ns4) ? this.css.clip.height : (this.element.offsetHeight) ? this.element.offsetHeight : this.css.pixelHeight);
  this.depth       = 0;
	this.frozen      = false;
  
	this.show(pVisibility);
	this.position(this.x, this.y, this.z);
//  !pDontClip && this.clip(0, this.width, this.height, 0);
	
	this.index = NA_Layer.layers.length;
	NA_Layer.layers[this.index] = this;
  eval(this.name + ' = this');
}

NA_Layer.prototype.show =
  function () {
    if (arguments.length) {
  		switch (arguments[0]) {
    	  case 1:
  	    case true:
				case 'show':
  		  	this.css.visibility = (NABrowser.ns4) ? "show" : "visible";
          break;
        case 'inherit':
  	  		this.css.visibility = "inherit";
			  	break;
      	case 0:
      	case false:
				case 'hide':
      	default:
			  	this.css.visibility = (NABrowser.ns4) ? "hide" : "hidden";
  		}
    } else {
  		return this.css.visibility;
    }
	}

NA_Layer.prototype.position =
  function (pX, pY, pZ) {
    if (arguments.length) {
      this.x = (pX != null) ? pX : this.x;
	    this.y = (pY != null) ? pY : this.y;
  	  this.z = (pZ != null) ? pZ : this.z;

  		if (NABrowser.ns4) {
    	  this.css.left      = this.x;
        this.css.top       = this.y;
			} else if (NABrowser.ns) {
			  this.css.left      = this.x + 'px';
			  this.css.top       = this.y + 'px';
			}	else {   
				this.css.pixelLeft = this.x;
        this.css.pixelTop  = this.y;
    	}
      this.css.zIndex = this.z;

      if (this.z > NA_Layer.maxZ) {
        NA_Layer.maxZ = this.z;
      } else if (this.z < NA_Layer.minZ) {
        NA_Layer.minZ = this.z;
      }
    } else { 
      return [this.x, this.y, this.z];
    }
	}
