function layerObj() {
	var a = arguments;
	if(!a.length) return null;
	this.getWidth = function(){ return is.ie ? is.ie4 ? this.elm.scrollWidth : this.elm.offsetWidth : is.nn ? is.nn4 ? this.elm.document.width : this.elm.offsetWidth : null }
	this.getHeight = function() { return is.ie ? is.ie4 ? this.elm.scrollHeight : this.elm.offsetHeight : is.nn ? is.nn4 ? this.elm.document.height : this.elm.offsetHeight : null }
	if(a.length == 1) {
		this.elm = getLayer(a[0]);
		if(!this.elm) return null;
		this.css = is.nn4 ? this.elm : this.elm.style;
		this.x = (is.ie || is.nn5) ? parseInt(this.elm.offsetLeft) : is.nn4 ? parseInt(this.css.left) : null;
		this.y = (is.ie || is.nn5) ? parseInt(this.elm.offsetTop) : is.nn4 ? parseInt(this.css.top) : null;
		this.isVisible = is.min ? (this.css.visibility != 'hide' && this.css.visibility != 'hidden') : null;
		this.width = this.getWidth();
		this.height = this.getHeight();
		this.zIndex = this.css.zIndex;
		var c = this.css.clip;
		if(is.nn4) { this.clipX = c.left; this.clipY = c.top; this.clipWidth = c.right - c.left; this.clipHeight = c.bottom - c.top }
		else {
			if(c.indexOf('rect(') > -1) {
				c = c.split('rect(')[1].split(')')[0].split('px');
				for(var i = 0; i < 4; i++) c[i] = parseInt(c[i].removeChar(32).removeChar(44));
				this.clipX = c[3]; this.clipY = c[0]; this.clipWidth = c[1] - c[3]; this.clipHeight = c[2] - c[0];
			} else with(this) { clipX = 0; clipY = 0; clipWidth = width; clipHeight = height }
		}
	} else {
		this.isChild = a[0]&&a[0].isLayer?true:false;
		this.parent = this.isChild?a[0].elm:is.nn4?window:document.body;
		if(this.isChild) a[0].children[a[0].children.length] = this;
		this.x = a[1]||0;
		this.y = a[2]||0;
		this.isVisible = a[3];
		this.zIndex = a[4]||0;
		this.width = a[5]||null;
		this.height = a[6]||null;
		this.clipX = 0;
		this.clipY = 0;
		this.clipWidth = this.width;
		this.clipHeight = this.height;
		this.isClipSet = false;
		this.html = a[7]||'';
		if(is.dom) {
			this.elm = is.ie ? this.parent.document.createElement('DIV') : document.createElement('DIV');
			this.css = this.elm.style;
			with(this.css) {
				position = 'absolute';
				left = new String(this.x+'px');
				top = new String(this.y+'px');
				if(this.width) width = new String(this.width+'px');
				if(this.height) height = new String(this.height+'px');
				visibility = this.isVisible ? 'inherit' : 'hidden';
				zIndex = this.zIndex;
			}
			this.parent.appendChild(this.elm);
			this.elm.innerHTML = this.html;
		}
		if(is.nn4) {
			this.elm = this.css = new Layer(this.width,this.parent);
			this.elm.moveTo(this.x,this.y);
			this.css.zIndex = this.zIndex;
			this.css.visibility = this.isVisible ? 'inherit' : 'hide';
			with(this.elm.document) { open(); write(this.html); close() }
		}
		if(is.ie4) {
			var html = '<div style="position:absolute; left:'+this.x+'px; top:'+this.y+'px; ';
			if(this.width) html += 'width:'+this.width+'px; ';
			if(this.height) html += 'height:'+this.height+'px; ';
			html += 'visibility:'+(this.isVisible ? 'visible' : 'hidden')+'; z-index:'+this.zIndex+'">'+this.html+'</div>';
			this.parent.insertAdjacentHTML('beforeEnd',html);
			this.elm = this.parent.children[this.parent.children.length - 1];
			this.css = this.elm.style;
		}
	}
	this.id = layerObj.objects.length;
	layerObj.objects[this.id] = this;
	this.isLayer = true;
	this.children = [];
	this.opacity = 100;
	if(is.nn4) for(var i = 0; i < this.elm.document.images.length; i++) layerObj.lyrImg[this.elm.document.images[i].name] = this;
	this.moveBy = function(dx,dy) { with(this) { x += dx; y += dy; css.left = x + 'px'; css.top = y + 'px' } }
	this.moveTo = function(xPos,yPos) { with(this) { x = xPos; css.left = x + 'px'; y = yPos; css.top = y + 'px' } }
	this.setVisible = function(b) { this.isVisible = b; this.css.visibility = b ? 'inherit' : (is.nn4 ? 'hide' : 'hidden') }
	this.show = function() { this.setVisible(true) }
	this.hide = function() { this.setVisible(false) }
	this.setZIndex = function(z) { this.zIndex = z; this.css.zIndex = z }
	this.writeHTML = function(html) {
		this.html = html;
		if(is.ie || is.nn5) this.elm.innerHTML = html;
		if(is.nn4) { with(this.elm.document) { open(); if(html != '') write(html); else clear(); close() } }
		this.setVisible(html != '')
		this.width = this.getWidth(); this.height = this.getHeight();
		if(!this.isClipSet) { this.clipWidth = this.width; this.clipHeight = this.height }
		if(is.nn4) for(var i = 0; i < this.elm.document.images.length; i++) layerObj.lyrImg[this.elm.document.images[i].name] = this;
	}
	this.setClip = function(x1,y1,x2,y2) {
		if(is.ie || is.nn5) this.css.clip = 'rect(' + y1 + ',' + x2 + ',' + y2 + ',' + x1 + ')';
		if(is.nn4) { with(this.elm.clip) { top = y1; right = x2; bottom = y2; left = x1 } }
		this.clipX = x1; this.clipY = y1; this.clipWidth = x2 - x1; this.clipHeight = y2 - y1;
		this.isClipSet = true;
	}
	this.scrollBy = function(dx,dy) { with(this) { moveBy(-dx,-dy); setClip(clipX + dx,clipY + dy,clipX + clipWidth + dx,clipY + clipHeight + dy) } } 
	this.setOpacity = function(p) {
		this.opacity = p;
		if(this.elm.filters) this.css.filter = new String('alpha(opacity='+p+')');
		else if(typeof(this.css.MozOpacity) == 'string') this.css.MozOpacity = p/100;
		else this.css.opacity = p/100;
	}
	this.setBgColor = function(color) {
		this.bgColor = color||(is.nn4 ? null : 'transparent');
		if(is.nn4) this.elm.bgColor = this.bgColor;
		else this.css.backgroundColor = this.bgColor;
	}
	this.setBgImage = function(image) {
		this.bgImage = image;
		if(is.nn4) this.elm.background.src = image;
		else this.css.backgroundImage = 'url('+image+')';
	}

	this.deleteLayer = function() {
		if(!this.isLayer) return;
		this.isLayer = false;
		for(var i = 0; i < this.children.length; i++) this.children[i].deleteLayer();
		this.hide();
		if(!is.nn4) { this.elm.innerHTML = ''; this.elm.outerHTML = '' }
		//layerObj.objects.splice(this.id,1);
		var tempObjects = [];
		for(var i = 0; i < layerObj.objects.length; i++) if(this.id!=i) tempObjects[tempObjects.length] = layerObj.objects[i];
		layerObj.objects = tempObjects;
		//--
		for(var i = this.id; i < layerObj.objects.length; i++) layerObj.objects[i].id--;
		this.html = '';
		this.elm = {};
		this.css = {};
	}

	this.refresh = function() { this.writeHTML(this.html) }
	this.isSelected = function(mX,mY) { with(this) { return(isVisible && x + clipX < mX && x + clipX + clipWidth > mX && y + clipY < mY && y + clipY + clipHeight > mY) } }
	return this;
}
layerObj.objects = [];
layerObj.lyrImg = [];
layerObj.getSelectedObject = function(x,y) {
	var selectedObjects = [];
	for(var i = 0; i < this.objects.length; i++) if(!this.objects[i].isChild && this.objects[i].isSelected(x,y)) selectedObjects[selectedObjects.length] = this.objects[i];
	if(!selectedObjects.length) return null;
	for(var i = 0; i < selectedObjects.length; i++) for(var j = 0; j < selectedObjects[i].children.length; j++) if(selectedObjects[i].children[j].isSelected(x-selectedObjects[i].x,y-selectedObjects[i].y)) selectedObjects[selectedObjects.length] = selectedObjects[i].children[j];
	var zIndex;
	var maxZIndex = selectedObjects[0].zIndex;
	var selectedObject = selectedObjects[0];
	for(var i = 1; i < selectedObjects.length; i++) {
		zIndex = selectedObjects[i].zIndex;
		if(zIndex >= maxZIndex) { maxZIndex = zIndex; selectedObject = selectedObjects[i] }
	}
	return selectedObject;
}
function getLayer(id,document) {
	if(!document) document = window.document;
	if(is.nn4) {
		for(var i = 0; i < document.layers.length; i++) if(document.layers[i].id == id) { return document.layers[i]; }
		for(var i = 0; i < document.layers.length; i++) {
			var layer = getLayer(id,document.layers[i].document);
			if(layer) return layer;
		}
		return null;
	}
	if(is.ie4) return document.all[id];
	if(is.dom) return document.getElementById(id);
	return null;
}
String.prototype.removeChar = function(charCode) {
	var rStr = new String();
	for(var i = 0; i < this.length; i++) if(this.charCodeAt(i) != charCode) rStr += this.charAt(i);
	return rStr;
}
