function layerObj(id,nestref) {
	if (is.ns4) {
		this.css = (nestref)? eval("document."+nestref+".document."+id) : document.layers[id]
		this.elm = this.css
		this.doc = (nestref)? eval('document.'+nestref+'.document.'+id+'.document') : document.layers[id].document
		this.x = this.css.left
		this.y = this.css.top
		this.z = this.css.zIndex
		this.w = this.css.clip.width
		this.h = this.css.clip.height
	}
  else if (is.ns5) {
    this.elm = document.getElementById(id)
    this.css = document.getElementById(id).style
    this.doc = document
    this.x = this.css.left
		this.y = this.css.top
		this.z = this.css.zIndex
		this.w = this.css.width
		this.h = this.css.height
	}
  else if (is.ie) {
		this.elm = document.all[id]
		this.css = document.all[id].style
		this.doc = document
		this.x = this.elm.offsetLeft
		this.y = this.elm.offsetTop
		this.z = this.css.zIndex
		this.w = (is.ie4)? this.css.pixelWidth : this.elm.offsetWidth
		this.h = (is.ie4)? this.css.pixelHeight : this.elm.offsetHeight
	}
	
	this.id = id
	this.nestref = nestref
	this.obj = id + "layerObj"
  eval(this.obj + "=this")
	
	this.show = layerObjShow
	this.hide = layerObjHide
	this.moveBy = layerObjMoveBy
	this.moveTo = layerObjMoveTo
	this.slideTo = layerObjSlideTo
	this.slideBy = layerObjSlideBy
	this.slideStart = layerObjSlideStart
	this.slide = layerObjSlide
	this.onSlide = new Function("")
	this.onSlideEnd = new Function("")
	this.slideToCenter = layerObjSlideToCenter
	this.clipTo = layerObjClipTo
	this.clipBy = layerObjClipBy
	this.clipValues = layerObjClipValues
	this.write = layerObjLayerWrite
	this.source = layerObjLayerSource
	this.setBgColor = layerObjSetBgColor
	this.setBgImage = layerObjSetBgImage
	this.getZIndex = layerObjGetZIndex
	this.setZIndex = layerObjSetZIndex
	this.getWidth = layerObjGetObjWidth
	this.setWidth = layerObjSetObjWidth
	this.getHeight = layerObjGetObjHeight
	this.setHeight = layerObjSetObjHeight
	this.center = layerObjCenter
	this.wipeTo = layerObjWipeTo
	this.wipeBy = layerObjWipeBy
	this.wipeStart = layerObjWipeStart
	this.wipe = layerObjWipe
	this.onWipe = new Function("")
	this.onWipeEnd = new Function("")
  if (is.ie) {
    this.fadeIn = layerObjFadeIn
    this.fadeBy = layerObjFadeBy
  }
}
function layerObjShow() {
	if (is.ns4) this.css.visibility = "show"
	else if (is.ie || is.ns5) this.css.visibility = "visible"
}
function layerObjHide() {
	if (is.ns4) this.css.visibility = "hide"
	else if (is.ie || is.ns5) this.css.visibility = "hidden"
}
function layerObjSetBgColor(color) {
	if (is.ns4) this.css.bgColor = color
  else if (is.ie || is.ns5) this.css.backgroundColor = color
}
function layerObjSetBgImage(url) {
	if (is.ns4) this.css.background.src = url;
  else if (is.ie || is.ns5) this.css.backgroundImage = "url("+url+")";
}
function layerObjMoveBy(dx,dy) {
	this.x += dx
	this.css.left = this.x
	this.y += dy
	this.css.top = this.y
}
function layerObjMoveTo(x,y) {
	this.x = x
	this.css.left = this.x
	this.y = y
	this.css.top = this.y
}
function layerObjLayerWrite(text) {
	if (is.ns4) {
		this.doc.open()
		this.doc.write(text)
		this.doc.close()
	}
	else if (is.ie || is.ns5) this.elm.innerHTML = text
}
function layerObjLayerSource(url) {
	if (is.ns4) {
		this.css.load(url,this.w);
	}
	else if (is.ie) {
		parent.bufferFrame.document.location = url;
	}
  else if (is.ns5) {
    alert('not implemented yet')
  }
}
function LoadSourceFinish(id) {
	if (is.ie) document.all[id].innerHTML = parent.bufferFrame.document.body.innerHTML;
  else if (is.ns5) alert('not implemented yet')
}
function layerObjGetZIndex() {
	return(this.z)
}
function layerObjSetZIndex(z) {
	this.z = z
	this.css.zIndex = this.z
}
function layerObjGetObjWidth() {
	if (is.ns) {
    if (is.ns4) return(this.css.clip.width)
    else if (is.ns5) return(0)
  }
	else if (is.ie) {
		if (is.ie4) return(this.css.pixelWidth)
		else return(this.elm.offsetWidth)
	}
}
function layerObjSetObjWidth(newwidth) {
	this.w = newwidth
	if (is.ns) {
    if (is.ns4) this.css.clip.width = this.w
    else if (is.ns5) return(0)
  }
	else if (is.ie) {
		if (is.ie4) this.css.pixelWidth = this.w
		else this.elm.offsetWidth = this.w
	}
}
function layerObjGetObjHeight() {
	if (is.ns) {
    if (is.ns4) return(this.css.clip.height)
    else if (is.ns5) return(0)
  }
	else if (is.ie) {
		return(this.elm.offsetHeight) 
	}
}
function layerObjSetObjHeight(newheight) {
	this.h = newheight
	if (is.ns) {
    if (is.ns4) this.css.clip.height = this.h
    else if (is.ns5) return(0)
  }
	else if (is.ie) {
		if (is.ie4) this.css.pixelHeight = this.h
		else this.elm.offsetHeight = this.h
	}
}
function getInsideWindowWidth() {
	if (is.ns4) return(window.innerWidth)
  else if (is.ns5) return(document.width)
	else if (is.ie) return(document.body.clientWidth)
}
function getInsideWindowHeight() {
	if (is.ns4) return(window.innerHeight)
  else if (is.ns5) return(document.height)
	else if (is.ie) return(document.body.clientHeight)
}
function layerObjClipTo(cliptop, clipright, clipbottom, clipleft) {
	if (is.ns4) {
    this.css.clip.left   = clipleft
    this.css.clip.top    = cliptop
    this.css.clip.right  = clipright
    this.css.clip.bottom = clipbottom
  }
  else if (is.ie || is.ns5) this.css.clip = "rect("+cliptop+"px "+clipright+"px "+clipbottom+"px "+clipleft+"px)"
}
function layerObjClipBy(dtop,dright,dbbottom,dleft) {
	this.clipTo(this.clipValues('top')+dtop,this.clipValues('right')+dright,this.clipValues('bottom')+dbottom,this.clipValues('left')+dleft)
}
function layerObjClipValues(which) {
	if (is.ie || is.ns5) var clipv = this.css.clip.split("rect(")[1].split(")")[0].split("px")
	if (which=="top") return (is.ns4)? this.css.clip.top : Number(clipv[0])
	if (which=="right") return (is.ns4)? this.css.clip.right : Number(clipv[1])
	if (which=="bottom") return (is.ns4)? this.css.clip.bottom : Number(clipv[2])
	if (which=="left") return (is.ns4)? this.css.clip.left : Number(clipv[3])
}
function layerObjCenter() {
	var x = Math.round((getInsideWindowWidth() / 2) - (this.getWidth() / 2))
	var y = Math.round((getInsideWindowHeight() / 2) - (this.getHeight() / 2))
	this.moveTo(x,y)
}
function layerObjSlideBy(distx,disty,inc,speed) {
	var endx = this.x + distx
	var endy = this.y + disty
	this.slideStart(endx,endy,distx,disty,inc,speed)
}
function layerObjSlideTo(endx,endy,inc,speed) {
	if (endx==null) endx = this.x
	if (endy==null) endy = this.y
	var distx = endx-this.x
	var disty = endy-this.y
	this.slideStart(endx,endy,distx,disty,inc,speed)
}
function layerObjSlideStart(endx,endy,distx,disty,inc,speed) {
	if (this.slideActive) return
	if (!inc) inc = 10
	if (!speed) speed = 20
	var num = Math.sqrt(Math.pow(distx,2) + Math.pow(disty,2)) / inc
	if (num==0) return
	var dx = distx / num
	var dy = disty / num
	this.slideActive = true
	this.slide(dx,dy,endx,endy,num,inc,speed)
}
function layerObjSlide(dx,dy,endx,endy,num,i,speed) {
	if (!this.slideActive) return
	if (i++ < num) {
		this.moveBy(dx,dy)
		this.onSlide()
		if (this.slideActive) setTimeout(this.obj+".slide("+dx+","+dy+","+endx+","+endy+","+num+","+i+","+speed+")",speed)
		else this.onSlideEnd()
	} else {
		this.slideActive = false
		this.moveTo(endx,endy)
		this.onSlide()
		this.onSlideEnd()
	}
}
function layerObjSlideToCenter(inc,speed) {
	var x = Math.round((getInsideWindowWidth() / 2) - (this.getWidth() / 2))
	var y = Math.round((getInsideWindowHeight() / 2) - (this.getHeight() / 2))
	this.slideTo(x,y,inc,speed)
}
function layerObjWipeTo(endt,endr,endb,endl,num,speed) {
	var distt = (endt!=null)? endt-this.clipValues('top'):0
	var distr = (endr!=null)? endr-this.clipValues('right'):0
	var distb = (endb!=null)? endb-this.clipValues('bottom'):0
	var distl = (endl!=null)? endl-this.clipValues('left'):0
	this.wipeStart(distt,distr,distb,distl,endt,endr,endb,endl,num,speed)
}
function layerObjWipeBy(distt,distr,distb,distl,num,speed) {
	this.wipeStart(distt,distr,distb,distl,distt+this.clipValues('top'),distr+this.clipValues('right'),distb+this.clipValues('bottom'),distl+this.clipValues('left'),num,speed)
}
function layerObjWipeStart(distt,distr,distb,distl,endt,endr,endb,endl,num,speed) {
	if (this.wipeActive) return
	this.wipeActive = true
	this.wipe(distt/num,distr/num,distb/num,distl/num,endt,endr,endb,endl,this.clipValues('top'),this.clipValues('right'),this.clipValues('bottom'),this.clipValues('left'),num,1,speed)
}
function layerObjWipe(dt,dr,db,dl,endt,endr,endb,endl,st,sr,sb,sl,num,i,speed) {
	if (!this.wipeActive) return
	if (i++ < num) { 
    this.clipTo(st+i*dt,sr+i*dr,sb+i*db,sl+i*dl)
    this.onWipe()
		setTimeout(this.obj+".wipe("+dt+","+dr+","+db+","+dl+","+endt+","+endr+","+endb+","+endl+","+st+","+sr+","+sb+","+sl+","+num+","+i+","+speed+")",speed)
	} else {
		this.wipeActive = false
		this.onWipe()
		this.onWipeEnd()
		this.clipTo(endt,endr,endb,endl)
	}
}
function layerObjFadeIn(i,inc,speed) {
  if (i-- != 0) {
    this.elm.filters.alpha.opacity -= inc
    setTimeout(this.obj+".fadeIn("+i+","+inc+","+speed+")",speed)
  }
}
function layerObjFadeBy(dfade) {
  this.elm.filters.alpha.opacity += dfade
}

