// Copyright (C) 1999 Dan Steinman
// Distributed under the terms of the GNU Library General Public License
// Available at http://www.dansteinman.com/dynapi/
// Modified by Ronnie Ericsson - ronnie@waycap.se

if(is.ns4) {			DynLayerElm	= "this.frame.document.layers[this.id]";		DynLayerCss = "this.elm";	DynLayerDoc	= "this.elm.document";	DynLayerX = "this.css().left";		DynLayerY	= "this.css().top";	DynLayerW = "this.css().clip.width";	DynLayerH = "this.css().clip.height";	DynLayerWTot = "this.css().document.width";	DynLayerHTot = "this.css().document.height" }
else if(is.ie4 || is.ie5) {	DynLayerElm	= "this.frame.document.all[this.id]";			DynLayerCss = "this.elm.style";	DynLayerDoc	= "this.frame.document";DynLayerX = "this.css().pixelLeft";	DynLayerY	= "this.css().pixelTop";DynLayerW = "this.elm.offsetWidth";	DynLayerH = "this.elm.offsetHeight";	DynLayerWTot = "this.elm.offsetWidth";		DynLayerHTot = "this.elm.offsetHeight" }
else{				DynLayerElm	= "this.frame.document.getElementById(this.id)";	DynLayerCss = "this.elm.style";	DynLayerDoc	= "this.frame.document";DynLayerX = "this.css().left";		DynLayerY	= "this.css().top";	DynLayerW = "this.elm.offsetWidth";	DynLayerH = "this.elm.offsetHeight";	DynLayerWTot = "this.elm.offsetWidth";		DynLayerHTot = "this.elm.offsetHeight" }
//else {		DynLayerElm	= "this.frame.document.all[this.id]";			DynLayerCss = "this.elm.style";	DynLayerDoc	= "this.frame.document";DynLayerX = "this.elm.offsetLeft";	DynLayerY	= "this.elm.offsetTop";	DynLayerW = "this.elm.offsetWidth";	DynLayerH = "this.elm.offsetHeight";	DynLayerWTot = "this.elm.offsetWidth";	DynLayerHTot = "this.elm.offsetHeight" }


DynLayer.prototype.css		= new Function("return eval(DynLayerCss)")
DynLayer.prototype.doc		= new Function("return eval(DynLayerDoc)")
DynLayer.prototype.x		= new Function("return parseInt(eval(DynLayerX))")
DynLayer.prototype.y		= new Function("return parseInt(eval(DynLayerY))")
DynLayer.prototype.w		= new Function("return parseInt(eval(DynLayerW))")
DynLayer.prototype.h		= new Function("return parseInt(eval(DynLayerH))")
DynLayer.prototype.wTot		= new Function("return parseInt(eval(DynLayerWTot))")
DynLayer.prototype.hTot		= new Function("return parseInt(eval(DynLayerHTot))")

function DynLayer(id,nestref,frame) {
	this.frame	= window
	this.id		= id
	this.elm	= eval(DynLayerElm)
	this.obj	= id + "DynLayer"
	eval(this.obj + "=this")
	DynLayer.array[DynLayer.array.length] = this
}

// DynLayerInit Function
function DynLayerInit() {
	DynLayer.array = new Array()
	//for(a=0; a<frames.length; a++) {
		a = 0
		DynLayerInit2() 
	//}
}
function DynLayerInit2(nestref) {
	if (is.ns4) {
		if (nestref) ref = eval('document.'+nestref+'.document')
		else {nestref = ''; ref = document}
		for (var i=0; i<ref.layers.length; i++) {
			divname	= ref.layers[i].name
			DynLayer.nestRefArray[divname] = nestref
			index = divname.indexOf("Div")
			if (index > 0)	eval(divname.substr(0,index)+" = new DynLayer('"+divname+"','"+nestref+"','')")
			if (ref.layers[i].document.layers.length > 0) DynLayer.refArray[DynLayer.refArray.length] = (nestref=='')? ref.layers[i].name : nestref+'.document.'+ref.layers[i].name
		}
		if (DynLayer.refArray.i < DynLayer.refArray.length) DynLayerInit2(DynLayer.refArray[DynLayer.refArray.i++])
	}
	else {
		nestrefTmp = ""
		nrOfNested = 0
		ref = (is.ns)? document.getElementsByTagName("Div") : document.all.tags("DIV")
		for (var i=0; i<ref.length; i++) {
			divname	= ref[i].id
			index	= divname.indexOf("Div")
			if (index > 0) {
				if(nrOfNested > 0) { nrOfNested--; nestref = nestrefTmp }
				else nestref = ""
				lyrCont = (is.ns || is.ie6)? document.getElementById(divname).innerHTML : document.all[divname].innerHTML
				pos = lyrCont.indexOf("DIV id=")
				for(j=0; j<pos; j++) {
					if(pos < lyrCont.length-1) {
						nestrefTmp = divname
						nrOfNested++
						pos = lyrCont.substring(pos+1,lyrCont.length-1).indexOf("DIV id=")
					}
				}
				eval(divname.substr(0,index)+" = new DynLayer('"+divname+"','"+nestref+"','')")
			}
		}
	}
	return true
}

DynLayer.refArray		= new Array()
DynLayer.refArray.i		= 0
DynLayer.nestRefArray		= new Array()
DynLayer.prototype.show		= DynLayerShow
DynLayer.prototype.hide		= DynLayerHide
DynLayer.prototype.moveTo	= DynLayerMoveTo
DynLayer.prototype.moveBy	= DynLayerMoveBy
DynLayer.prototype.clipInit	= DynLayerClipInit
DynLayer.prototype.clipTo	= DynLayerClipTo
DynLayer.prototype.clipBy	= DynLayerClipBy
DynLayer.prototype.clipValues	= DynLayerClipValues
DynLayer.prototype.write 	= DynLayerWrite

// Show/Hide Methods
function DynLayerShow() { 
	if(is.ns4) 	this.css().visibility	= "show"
	else 		this.css().visibility	= "visible" 
}
function DynLayerHide() {
	if(is.ns4) 	this.css().visibility	= "hide"
	else 		this.css().visibility	= "hidden" 
}

// Move Methods
function DynLayerMoveTo(x,y) {
	if(!x == null) x = parseInt(x)
	if(!y == null) y = parseInt(y)
	if (x!=null) {
		if (is.ns)	this.css().left		= x
		else		this.css().pixelLeft	= x
	}
	if (y!=null) {
		if (is.ns) 	this.css().top		= y
		else 		this.css().pixelTop	= y
	}
}
function DynLayerMoveBy(x,y) { this.moveTo(this.x()+x,this.y()+y) }

// Clip Methods
function DynLayerClipInit(clipTop,clipRight,clipBottom,clipLeft) {
	if (is.ie) {
		if (arguments.length==4) this.clipTo(clipTop,clipRight,clipBottom,clipLeft)
		else if (is.ie4) this.clipTo(0,this.css().pixelWidth,this.css().pixelHeight,0)
	}
}
function DynLayerClipTo(t,r,b,l) {
	if (t==null) t = this.clipValues('t')
	if (r==null) r = this.clipValues('r')
	if (b==null) b = this.clipValues('b')
	if (l==null) l = this.clipValues('l')
	if (is.ns4) {
		this.css().clip.top	= t
		this.css().clip.right	= r
		this.css().clip.bottom	= b
		this.css().clip.left	= l
	}
	else this.css().clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)"
	this.h = eval("new Function('return " + (b-t) + "')")
	this.w = eval("new Function('return " + (r-l) + "')")
}
function DynLayerClipBy(t,r,b,l) {
	this.clipTo(this.clipValues('t')+t,this.clipValues('r')+r,this.clipValues('b')+b,this.clipValues('l')+l)
}
function DynLayerClipValues(which) {
	if (is.ie || is.ns5) var clipv = this.css().clip.split("rect(")[1].split(")")[0].split("px")
	if (which=="t") return (is.ns4)? this.css().clip.top	: Number(clipv[0])
	if (which=="r") return (is.ns4)? this.css().clip.right	: Number(clipv[1])
	if (which=="b") return (is.ns4)? this.css().clip.bottom	: Number(clipv[2])
	if (which=="l") return (is.ns4)? this.css().clip.left	: Number(clipv[3])
}

// Write Method
function DynLayerWrite(html) {
	if (is.ns) {
		this.doc().open()
		this.doc().write(html)		
		this.doc().close()	
	}
	else this.elm.innerHTML = html
}
