// Copyright 1999 Dan Steinman
// http://www.dansteinman.com/dynapi/


// DynLayer Functions ------------------------------------------------------------------------------

function DynLayer(id,nestref1,nestref2) {
	if (is.ns4) {
		if (nestref1) {
			if (nestref2) {
				this.elm = document.layers[nestref2].document.layers[nestref1].document.layers[id]
			}
			else {
				this.elm = document.layers[nestref1].document.layers[id]
			}
		}
		else {
			this.elm = document.layers[id]
		}
		this.css = this.event = this.elm
		this.doc = this.elm.document
		this.l = this.css.left
		this.t = this.css.top
		this.w = this.css.clip.width
		this.h = this.css.clip.height
	}
	else {
		if (is.ie4) this.elm = this.event = document.all[id]
		else this.elm = this.event = document.getElementById(id)
		this.css = this.elm.style
		this.doc = document
		this.l = this.elm.offsetLeft
		this.t = this.elm.offsetTop
		this.w = this.elm.offsetWidth
		this.h = this.elm.offsetHeight
		if (this.w == 0) this.w = this.css.pixelWidth
		if (this.h == 0) this.h = this.css.pixelHeight
	}
	this.obj = id + "DynLayer"
	eval(this.obj + "=this")
	this.moveTo = DynLayerMoveTo
	this.moveBy = DynLayerMoveBy
	this.resizeTo = DynLayerResizeTo
	this.show = DynLayerShow
	this.hide = DynLayerHide
}

function DynLayerMoveTo(l,t) {
	if (l!=null) {
		this.l = l
		if (is.ns4) this.css.left = this.l
		else this.css.pixelLeft = this.l
	}
	if (t!=null) {
		this.t = t
		if (is.ns4) this.css.top = this.t
		else this.css.pixelTop = this.t
	}
}

function DynLayerMoveBy(l,t) {
	this.moveTo(this.l+l,this.t+t)
}

// Slide Methods
function DynLayerSlideTo(endx,endy,inc,speed,fn) {
	if (endx==null) endx = this.l
	if (endy==null) endy = this.t
	var distx = endx-this.l
	var disty = endy-this.t
	this.slideStart(endx,endy,distx,disty,inc,speed,fn)
}
function DynLayerSlideBy(distx,disty,inc,speed,fn) {

	var endx = this.l + distx
	var endy = this.t + disty
	this.slideStart(endx,endy,distx,disty,inc,speed,fn)
}
function DynLayerSlideStart(endx,endy,distx,disty,inc,speed,fn) {
	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
	if (!fn) fn = null
	this.slideActive = true
	this.slide(dx,dy,endx,endy,num,1,speed,fn)
}
function DynLayerSlide(dx,dy,endx,endy,num,i,speed,fn) {
	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+",\""+fn+"\")",speed)
		else this.onSlideEnd()
	}
	else {
		this.slideActive = false
		this.moveTo(endx,endy)
		this.onSlide()
		this.onSlideEnd()
		eval(fn)
	}
}
function DynLayerSlideInit() {}
DynLayer.prototype.slideInit = DynLayerSlideInit
DynLayer.prototype.slideTo = DynLayerSlideTo
DynLayer.prototype.slideBy = DynLayerSlideBy
DynLayer.prototype.slideStart = DynLayerSlideStart
DynLayer.prototype.slide = DynLayerSlide
DynLayer.prototype.onSlide = new Function()
DynLayer.prototype.onSlideEnd = new Function()
// Slide Methods - end

function DynLayerResizeTo(w,h) {
	if (w!=null) {
		this.w = w
		if (is.ns4) this.css.clip.width = this.w
		else this.css.width = this.w
	}
	if (h!=null) {
		this.h = h
		if (is.ns4) this.css.clip.height = this.h
		else this.css.height = this.h
	}
}

function DynLayerShow() {
	this.css.visibility = (is.ns4) ? "show" : "visible"
}

function DynLayerHide() {
	this.css.visibility = (is.ns4) ? "hide" : "hidden"
}

function createLayer(id,l,t,w,h,content,z,visibility,bgColor,events,nestref) {
	if (is.ns4) {
		if (nestref) var lyr = document.layers[nestref].document.layers[id] = new Layer(w, document.layers[nestref])
		else var lyr = document.layers[id] = new Layer(w)
		lyr.name = id
		lyr.left = l
		lyr.top = t
		if (h) lyr.clip.height = h
		if (content) {
			lyr.document.open()
			lyr.document.write(content)
			lyr.document.close()
		}
		if (z) lyr.zIndex = z
		lyr.visibility = (visibility == 'hidden') ? 'hide' : 'show'
		if (bgColor) lyr.bgColor = bgColor
	}
	else {
		if (nestref) {
			index = nestref.lastIndexOf(".")
			var nestlyr = (index != -1) ? nestref.substr(index+1) : nestref
		}
		if (is.dom) {
			lyr=document.createElement("DIV")
			lyr.style.position = "absolute"
			lyr.style.left = l+"px"
			lyr.style.top = t+"px"
			if (w) lyr.style.width = w+"px"
			if (h) lyr.style.height = h+"px"
			if (z) lyr.style.zIndex = z
			if (visibility) lyr.style.visibility = visibility
			if (bgColor) lyr.style.backgroundColor = bgColor
			if (events) {
				if (events.indexOf('border:') != -1) lyr.style.border = '1px black solid'
			}
			lyr.innerHTML = '<span '+((events) ? events : '')+'>'+content+'</span>'
			lyr.id = id
			if (nestref) document.all[nestlyr].appendChild(lyr)
			else document.body.appendChild(lyr)
		}
		else { 
			var str = '\n<DIV id='+id+' style="position:absolute; left:'+l+'; top:'+t
			if (w) str += '; width:'+w
			else str += '; width: 1'
			if (h != null) str += '; height:'+h
			if (z != null) str += '; z-index:'+z
			if (visibility) str += '; visibility:'+visibility
			if (bgColor != null) str += '; background:'+bgColor
			str += '" '+events+'>'+((content)?content:'')+'</DIV>'
			if (nestref) document.all[nestlyr].insertAdjacentHTML("BeforeEnd",str)
			else document.body.insertAdjacentHTML("BeforeEnd",str)
		}
	}
}

function preload(imgSrc) {
	if (document.images) {
		imgObj = imgSrc.substring(imgSrc.lastIndexOf('/')+1,imgSrc.lastIndexOf('.'))
		eval(imgObj+' = new Image()')
		eval(imgObj+'.src = "'+imgSrc+'"')
	}
}

function changeImage(imgName,imgObj,layer) {
	if (document.images && start) {
		if (document.layers && layer) document.layers[layer].document.images[imgName].src = eval(imgObj+'.src')
		else document.images[imgName].src = eval(imgObj+'.src')
	}
}

function DynLayerWrite(html) {
	if (is.ns) {
		this.doc.open()
		this.doc.write(html)
		this.doc.close()
	}
	else if (is.ie) {
		this.event.innerHTML = html
	}
}

DynLayer.prototype.writeLayer = DynLayerWrite

function checkBrowser() {
	var b = navigator.appName
	if (b == 'Netscape') this.b = 'ns'
	else if (b == 'Microsoft Internet Explorer') this.b = 'ie'
	else this.b = b
	this.v = parseInt(navigator.appVersion)
	this.ns = (this.b == 'ns' && this.v >= 4)
	this.ns4 = (this.b == 'ns' && this.v == 4)
	this.ns5 = (this.b == 'ns' && this.v == 5)
	this.ns6 = (this.b == 'ns' && this.v == 5)
	this.ie = (this.b == 'ie' && this.v >= 4)
	this.ie4 = (navigator.userAgent.indexOf('MSIE 4') > 0)
	this.ie5 = (navigator.userAgent.indexOf('MSIE 5.0') > 0)
	this.ie55 = (navigator.userAgent.indexOf('MSIE 5.5') > 0)
	this.ie6 = (navigator.userAgent.indexOf('MSIE 6.0') > 0)
	this.win = (navigator.userAgent.indexOf('Win') > 0)
	this.mac = (navigator.userAgent.indexOf('Mac') > 0)
	if (this.ie5) this.v = 5
	if (this.ie55) this.v = 5.5
	if (this.ie6) this.v = 6
	this.min = (this.ns || this.ie)
	this.dom = (this.v >= 5)
}

is = new checkBrowser()

function documentWidth() { return (is.ie?(document.body.scrollWidth):(document.width)) }
function documentHeight() { return (is.ie?(document.body.scrollHeight):(document.height)) }
function windowWidth() { return (is.ie?(document.body.clientWidth):(window.innerWidth)) }
function windowHeight() { return (is.ie?(document.body.clientHeight):(window.innerHeight)) }
function bodyBottom() { return ((documentHeight()>=bodyHeight())?documentHeight():bodyHeight()) }

function windowScrollH() { return (document.body.scrollLeft) }
function windowScrollV() { return (document.body.scrollTop) }

