/* Copyright (C) 2000 Micah Goulart
   Modified by Shelley Huckins */
   
   function BrowserCheck() {
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.version = navigator.appVersion
	this.v = parseInt(this.version)
	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.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (this.version.indexOf('MSIE 4')>0)
	this.ie5 = (this.version.indexOf('MSIE 5')>0)
	this.min = (this.ns||this.ie)
}
is = new BrowserCheck()

function DynLayer(id, x, y, w, h, color, v) {
	var arg = arguments
	this.parent = document
	this.elm = this.doc = this.css = {}
	this.id = id || "JSDynLayer"+DynLayer.nullCount++
	this.x = x; this.y = y; this.w = w || null; this.h = h || null
	this.bgColor = color ? color : null; this.v = (v != "hidden")
	this.visibility = v
	this.children = []
	this.events = []
	this.created = false
	this.html = null

	return DynLayer.all[DynLayer.all.length] = DynLayer.all[this.id] = this
}
DynLayer.prototype.getDynLayer = function () {return this}
DynLayer.prototype.getClass = function () {return "DynLayer"}

DynLayer.prototype.add = function() {
	for (var i = 0; i < arguments.length; i++) {
		var dlyr = arguments[i]
		if (this.created) dlyr.create(this)
		else {
			dlyr.isChild = true
			dlyr.parent = this
			this.children[this.children.length] = dlyr
		}
	}
}
DynLayer.prototype.remove = function(dlyr) {
	if (!this.created) {
		this.children = RemoveFromArray(this.children, dlyr, 1)
		dlyr.isChild = false
		dlyr.parent = document
	}
	else deleteDynLayer(dlyr)
}
DynLayer.prototype.create = function(r) {
	if (this.isChild && !this.parent.created) return
	this.assignLayer(createLayer(this.id, this.parent))
	this.created = true
	this.setPos(this.x, this.y)
	this.setHTML(this.html)
	if (this.w == null) this.w = this.getW()
	if (this.h == null) this.h = this.getH()
	this.setSize(this.w, this.h)
	this.setBgColor(this.bgColor)
	if (this.bgImage != null) this.setBgImage(this.bgImage)
	if (this.visibility == "inherit") this.css.visibility = "inherit"
	else this.setV(this.v)
	this.createChildren()
	if (this.onCreate) this.onCreate()
	return this
}
DynLayer.prototype.createChildren = function()
{ for (i in this.children) this.children[i].create(this) }

DynLayer.prototype.assignLayer = function(lyr) {
	if (is.ns4) { this.css = lyr; this.doc = lyr.document	}
	else if (is.ie || is.ns5) { this.css = lyr.style; this.doc = document }
	this.elm = lyr
	lyr.obj = this
	if (is.ns4) this.doc.obj = this
}
DynLayer.prototype.toString = function () {return "DynLayer.all['"+this.id+"']"}

DynLayer.prototype.setPos = function(x, y) {
	if (x != null) {
		if (this.created) { if (is.ns) this.css.left = x; else this.css.pixelLeft = x	}
		this.x = x
	} if (y != null) { 
		if (this.created) { if (is.ns) this.css.top = y; else this.css.pixelTop = y }
		this.y = y
	}
	if (this.onMove) this.onMove()
}
DynLayer.prototype.setPosBy = function(x,y) {this.setPos(this.x+x,this.y+y)}

DynLayer.prototype.getPageX = function () 
{return (is.ns4 ? this.css.pageX : (this.isChild?this.parent.getPageX():0)+this.x)}

DynLayer.prototype.getPageY = function () 
{return (is.ns4 ? this.css.pageY : (this.isChild?this.parent.getPageY():0)+this.y)}

DynLayer.prototype.setV = function(v) {
	this.v = v
	if (this.created)
		this.css.visibility=v?(is.ns4?"show":"visible"):(is.ns4?"hide":"hidden")
}
DynLayer.prototype.show = function() {this.setV(1)}
DynLayer.prototype.hide = function() {this.setV(0)}
DynLayer.prototype.toggle = function() { this.v ? this.hide() : this.show() }

DynLayer.prototype.setBgImage = function(path) {
	this.bgImage = path
	if (!this.created) return
	if (is.ns4) this.elm.background.src = path
	else this.css.background = "url("+path+")"
}
DynLayer.prototype.setBgColor = function(color) {
	if (color == null) color = null
	this.bgColor = color
	if (!this.created) return
	if (is.ns4) this.doc.bgColor = color
	else this.css.backgroundColor = color
}
DynLayer.prototype.setHTML = function(html) {
	if (html == null) html = ""
	this.html = html	
	if (!this.created) {		
		for (var i in this.children) this.remove(this.children[i])
		return false
	}
	if (is.ie) this.elm.innerHTML = html
	else if (is.ns4) {
		this.doc.open(); this.doc.write(html); this.doc.close()
		if (this.doc.images.length > 0)
			for (i in this.doc.images) this.doc.images[i].obj = this
	} else if (is.ns5) {
		while (this.elm.hasChildNodes()) this.elm.removeChild(this.elm.firstChild)
		var r = this.elm.ownerDocument.createRange()
		r.selectNodeContents(this)
		r.collapse(true)
		this.elm.appendChild(r.createContextualFragment(str))
	}
}
DynLayer.prototype.setSize = function(w, h)
{	if (w != null) {
		if (this.created) {if (is.ns4) this.css.clip.width = w; else this.css.width = w }
		this.w = w
	}
	if (h != null) {
		if (this.created) {if (is.ns4) this.css.clip.height = h;	else this.css.height = h }
		this.h = h
	}
	this.setClip(0, w, h, 0)
	if (this.onResize) this.onResize()
}
DynLayer.prototype.setSizeBy = function (w,h){this.setSize(this.w+w,this.h+h)}

DynLayer.prototype.getW = function() 
	{return parseInt(is.ns ? this.doc.width : this.elm.offsetWidth)}
DynLayer.prototype.getH = function() 
	{return parseInt(is.ns ? this.doc.height : this.elm.offsetHeight)}

DynLayer.prototype.setClip = function(t,r,b,l) {
	var clip = this.css.clip
	if (t==null) t = this.getClip("t"); if (r==null) r = this.getClip("r")
	if (b==null) b = this.getClip("b"); if (l==null) l = this.getClip("l")
	if (is.ns) { clip.top = t; clip.right = r; clip.bottom = b; clip.left = l }
	else if (is.ie) this.css.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)"
}
DynLayer.prototype.getClip = function(s) {
	var clip = this.css.clip
	if (is.ie) var v = clip.split("rect(")[1].split(")")[0].split("px")
	switch (s) {
		case "t" : return is.ns ? clip.top : Number(v[0])
		case "r" : return is.ns ? clip.right : Number(v[1])
		case "b" : return is.ns ? clip.bottom : Number(v[2])
		case "l" : return is.ns ? clip.left : Number(v[3])
	}
}
DynLayer.prototype.setClipBy = function(t,r,b,l) {
	this.setClip(
		t+this.getClip("t"),r+this.getClip("r"),
		b+this.getClip("b"),l+this.getClip("l"))
}

DynLayer.prototype.onDelete = function () {return true}
DynLayer.all = []
DynLayer.nullCount = 0
DynLayer.winW = 0
DynLayer.winH = 0

function MouseListener (target) { this.target = target }

MouseListener.prototype.add = function () {
	for (var i = 0; i < arguments.length; i++) {
		var dlyr = arguments[i]
		if (!dlyr.events) dlyr.events = []
		if (dlyr.events[this]) return
		dlyr.events[dlyr.events.length] = this
		if (!dlyr.eventsAttached) dlyr.attachEvents()		
	}
	if (is.ns4 && !document.eventsAttached) {
		document.captureEvents(Event.MOUSEMOVE)
		document.onmousemove = DynLayerMouseMove
		document.eventsAttached = true
	}
}
MouseListener.prototype.remove = function () {
	for (var i = 0; i < arguments.length; i++) {
		var dlyr = arguments[i]
		var temp = []
		for (var j = 0; j < dlyr.events.length; j++)
			if (dlyr.events[j] != this) temp[temp.length] = dlyr.events[j]
		dlyr.events = temp
	}
}
DynLayer.prototype.attachEvents = function () {
	var elm = this.elm
	if (is.ns4)	elm.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.MOUSEOVER |
		Event.MOUSEOUT | Event.DBLCLICK )
	elm.onmousedown = elm.onmouseup = elm.onmouseover = DynLayerEvent
	elm.onmouseout = elm.ondblclick = DynLayerEvent
	elm.onmousemove = DynLayerMouseMove
	this.eventsAttached = true
}
function DynLayerEvent (e) {
	if (is.ie) { 
		e = event; 
		if (e.type != "mouseout" && e.type != "mouseover") e.cancelBubble = true
		if (e.type == "mouseout" && this.contains(e.toElement)) return
		if (e.type == "mouseover" && this.contains(e.fromElement)) return
	}
	var dlyr = is.ie ? this.obj : e.target.obj	 
	var ev = DynLayer.event; 
		ev.type = e.type
		ev.src = dlyr
		ev.altKey = is.ie ? e.altKey : (e.modifiers & Event.ALT_MASK) ? true : false
		ev.shiftKey = is.ie ? e.shiftKey : (e.modifiers & Event.SHIFT_MASK) ? true : false
		ev.ctrlKey = is.ie ? e.ctrlKey : (e.modifiers & Event.CONTROL_MASK) ? true : false
		ev.rightButton = is.ns4 ? e.which!=1 : e.button!=1

	dlyr.invokeEvent(e.type, ev)
	if (ev.bubble && dlyr.isChild && (e.type == "mousedown" || e.type == "mouseup"))
		DynLayerEventBubble(dlyr.parent, e.type)
}
document.invokeEvent = DynLayer.prototype.invokeEvent = function (type, ev) {
	var etype = DynLayerEventGet(type)
	for (var i in this.events)
		if (this.events[i][etype]) {
			this.events[i].target._e =  this.events[i][etype]
			this.events[i].target._e(ev)
		}
	if (type == "mouseup") { ev.type = "click"; this.invokeEvent(ev.type, ev)}
}
function DynLayerEventGet(w) {
	switch (w) {
		case "mousedown" : return "onMouseDown"; case "mouseup" : return "onMouseUp"
		case "mouseover" : return "onMouseOver"; case "mouseout" : return "onMouseOut"
		case "mousemove" : return "onMouseMove"; case "click" : return "onClick"; 
		case "dblclick" : return "onDblClick"
	}
}
function DynLayerEventSet(dlyr,x,y,type,e) {
	var ev = DynLayer.event
		ev.src = dlyr; ev.type = type; ev.bubble = true
		ev.pageX = x; ev.x = is.ie ? e.offsetX : e.layerX
		ev.pageY = y; ev.y = is.ie ? e.offsetY : e.layerY
		ev.screenX = e.screenX; ev.screenY = e.screenY
	return ev
}
DynLayer.event = {}

function DynLayerEventBubble(dlyr, type) {
	var ev = DynLayer.event; ev.src = dlyr; ev.bubble = true
	dlyr.invokeEvent(type, ev)
	if (ev.bubble && dlyr.isChild) DynLayerEventBubble(dlyr.parent, type)
}
function DynLayerMouseMove (e) {
	if (is.ie) e = event
	var x = is.ie ? e.x + document.body.scrollLeft : e.pageX - window.pageXOffset
	var y = is.ie ? e.y + document.body.scrollTop : e.pageY - window.pageYOffset
	var dlyr = is.ie ? this.obj : e.target.obj
	if (dlyr) {
		var ev = DynLayerEventSet(dlyr,x,y,e.type,e)
		dlyr.invokeEvent(e.type, ev)
		if (dlyr.isChild && ev.bubble) DynLayerEventBubble(dlyr, e.type)
	}
}	
function createLayer(id, parent) {
	var parentIsLyr = (parent != null && parent.toString().indexOf("DynLayer")>-1)
	if (parent == null) parent = document
	var doc = parentIsLyr ? parent.doc : parent
	var w = this.w ? this.w : 100
	if (is.ns4) lyr = parentIsLyr ? new Layer(w, parent.elm) : new Layer(w)
	var parentElement = (parentIsLyr)? parent.elm : parent.body
	if (is.ie4) {
		parentElement.insertAdjacentHTML("beforeEnd", 
			"<div id='" + id + "' style='position:absolute; '></div>")
		lyr = document.all[id]
	}

	else if (is.ie5 || is.ns5) {
		lyr = document.createElement("DIV")
		lyr.style.position = "absolute"
		lyr.id = id
		parentElement.appendChild(lyr)
	}
	return lyr
}
function deleteDynLayer(dlyr) {
	var id = dlyr.id ? dlyr.id : dlyr
	var dlyr = DynLayer.all[id]
	if (!dlyr) return false
	if (!dlyr.onDelete()) return false
 	dlyr.hide()
 	dlyr.setHTML()
	if (is.ie) dlyr.elm.outerHTML = ""
	if (is.ns4) {
	 	delete dlyr.doc.recycled
	 	if (!dlyr.parent.doc.recycled) dlyr.parent.doc.recycled = []
	 	var r = dlyr.parent.doc.recycled
	 	r[r.length] = dlyr.elm
	}
 	deleteDynLayerEntry(id)
	return true
}
function RemoveFromArray(array, index, id) {
	var temp = []
	var which = typeof index == "object" ? index : array[index]
	for (var i = 0; i < array.length; i++) {
		if (array[i] != which) {
			temp[temp.length] = array[i]
			if (id) temp[array[i].id] = array[i]
		}
	}
	return temp
}
function deleteDynLayerEntry(id) {
	var dlyr = DynLayer.all[id]
	dlyr.parent.children = RemoveFromArray(dlyr.parent.children, dlyr, true)	
	DynLayer.all = RemoveFromArray(DynLayer.all, dlyr, true)
}


function getImage(src,w,h) {
	var i = new Image(w,h)
	i.src = src
	i.w = w
	i.h = h
	return i
}
function DynDocument(frame) {
	this.doc = frame.document
	this.elm = frame
	this.parent = null
	this.isChild = null
	this.children = []
	this.created = true
	this.id = "DynDocument"+DynDocument.count++
	this.ref = this.name+"Ref"
	self[this.ref] = this
}
DynDocument.count = 0
DynDocument.prototype.toString = function() {return this.ref}
DynDocument.prototype.getClass = function() {return "DynDocument"}

DynDocument.prototype.add = function() {
	for (var i = 0; i < arguments.length; i++) {
		var child = arguments[i]
		if (child.created) child.remove()
		this.children[this.children.length] = child
		child.create()
	}
}
DynDocument.prototype.recreateAll = function() {
	for (i in DynLayer.all) DynLayer.all[i].deleteLayer()
	for (i in this.children) this.children[i].create()
}

DynLayer.document = new DynDocument(self)

function DynLayerInit() {
	for (var i = 0; i < DynLayer.all.length; i++) 
		if (!DynLayer.all[i].isChild) DynLayer.document.add(DynLayer.all[i])
}
DynApi = {}; DynApi.all = []
DynApi.add = function (widget) { DynApi.all[DynApi.all.length] = widget }
DynApi.remove = function (widget) { DynApi.all = RemoveFromArray(DynApi.all, widget)}
DynApi.init = function () {
	for (var i = 0; i < DynApi.all.length; i++) {
		var widget = DynApi.all[i]
		if (!widget.created) {
			widget.create()
			widget.created = true
		}
	}
}
function Menu(x, y, w, iH) {
	DynApi.add(this)
	this.id = "Menu" + Menu.count++
	this.ref = this.id + "Ref"
	self[this.ref] = this
	
	this.i = Menu.count - 1
	
	this.enable  = true
	this.itemDrag = null

	this.x = x;
	this.y = y; 
	this.w = w;
	this.h = 0

	this.css = this.div = ""
	this.table = 
		["<TABLE CELLSPACING=1 CELLPADDING=1 BORDER=0><TR><TD>", "</TD></TR></TABLE>"]
	this.visibility = "hidden"
	
	this.items = []
	this.itemHeight = iH
	this.itemResize = false
	
	if (is.ie) this.textCSS = "font: bold 11px Arial; padding-left: 3px; color: black;"
	else this.textCSS = "font: bold 12px Arial; padding-left: 3px; color: black;"		      
	if (is.ie) this.textOverCSS = "font: bold 11px Arial; padding-left: 3px; color: black;"
	else this.textOverCSS = "font: bold 12px Arial; padding-left: 3px; color: black;"
	
	this.onItemOver = this.onItemOut = this.onItemDown = 
		this.onItemUp = new Function("return true")

	this.div = ""
	
	var sty = this.style = {}
		sty.itemSpacing = 0
		sty.borderColor = "black"
		sty.borderWidth = 1
		sty.useTextOver = true
		sty.bgColor = sty.bgColorOut = "White"
		sty.bgColorOver = sty.bgColorDown = "FFCC33"

}
Menu.prototype.toString = function() {return this.ref}
Menu.prototype.getClass = function() {return "Menu"}
Menu.prototype.getDynLayer = function () {return this.container}
Menu.prototype.setPos = function (x,y) {
	var dlyr = this.getDynLayer()
	dlyr.setPos(x,y)
	this.x = dlyr.x
	this.y = dlyr.y
}
Menu.prototype.setPosBy = function(x,y) {this.setPos(this.x+x,this.y+y)}
Menu.prototype.show = function () {this.getDynLayer().show()}
Menu.prototype.hide = function () {this.getDynLayer().hide()}

Menu.count = 0

Menu.prototype.add = function (url, text, disabled) {
	var html = 
		this.table[0] + "<DIV ID=q CLASS="+this.id+"Normal>"+text+"<br>"+"</DIV>"+this.table[1]
 
	var item = this.items[this.items.length] = []
	
		item.i = this.items.length-1
		item.id = this.id + "Item" + item.i
		item.x = this.style.borderWidth
		item.y = this.style.borderWidth

		if (item.i > 0) item.y += (item.i*this.itemHeight) + (item.i*this.style.itemSpacing)

		item.h = this.itemHeight
		item.w = this.w-(this.style.borderWidth*2)

		item.bgColor = this.style.bgColor
		item.bgColorOut = this.style.bgColorOut
		item.bgColorOver =  this.style.bgColorOver
		item.bgColorDown =  this.style.bgColorDown
	
		item.text = text
		item.url = url
		item.disabled = disabled

	item.normal = html.replace("<TABLE", "<TABLE HEIGHT=" + item.h).replace("<TABLE",
			"<TABLE WIDTH=" + item.w)

	if (is.ns4) {
		item.normal = 
			item.normal.replace("ID=q CLASS="+this.id+"Normal", "STYLE='"+this.textCSS+"'")
		item.over = item.normal.replace(this.textCSS, this.textOverCSS)
	}
	return item
}
Menu.prototype.build = function() {
	if (is.ie) document.createStyleSheet().cssText +=
			"." + this.id + "Normal { " + this.textCSS + " }\n" +
			"." + this.id + "Over { " + this.textOverCSS + " }\n"

	this.container = new DynLayer(null,this.x,this.y,this.w,this.h,
		this.style.borderColor,"hidden")
	
	for (var i in this.items) {
		var item = this.items[i]
		
		item.lyr = new DynLayer(null, item.x, item.y, item.w, item.h, item.bgColor, "inherit")
		item.lyr.html = item.normal
		this.container.add(item.lyr)
		
		if (is.ns4 && (this.style.useTextOver || !item.disabled)) {
			item.o = new DynLayer(null,item.x,item.y,item.w,item.h,item.bgColorOver,"hidden")
			item.o.html = item.over
			this.container.add(item.o)
		}
		if (!item.disabled) {
			item.e = new DynLayer(null, item.x,item.y, item.w, item.h, null, "inherit")
			this.container.add(item.e)
		}
	}
	var ev = this.event = new MouseListener(this)
		ev.onMouseUp = MenuItemUp
		ev.onMouseDown = MenuItemDown
		ev.onMouseOver = MenuItemOver
		ev.onMouseOut = MenuItemOut
}
Menu.itemCount = -1
Menu.itemCount2 = 0

Menu.prototype.create = function () {
	if (this.created) return
	this.container.create()
	this.container.elm.onselectstart = new Function("return false")
	this.container.css.cursor = "default"

	for (var i in this.items) {
		var item = this.items[i]
		var lyr = this.items[i].lyr
		lyr.i = i

		if (!item.disabled) {
			this.event.add(lyr, item.e)
			item.e.i = i
			if (is.ns4 && this.style.useTextOver) { this.event.add(item.o); item.o.i = i }
		}
		if (i == 0)	this.h = this.style.borderWidth

		item.y = this.h

		if (this.itemResize) {
			lyr.setPos(null, item.y)		
			if (!item.disabled) {
				if (is.ns4 && this.style.useTextOver) item.o.setPos(null,item.y)
				item.e.setPos(null,item.y)
			}
		}
		var h = lyr.getH()
		
		if (h > item.h || this.itemHeight == null) {
			this.itemResize = true
			item.h = h
			lyr.setSize(item.w, item.h)
			
			if (!item.disabled) {
				item.e.setSize(item.w, item.h)
				if (is.ns4 && this.style.useTextOver) item.o.setSize(item.w, item.h)
			}		
		}
		this.h += item.h + this.style.itemSpacing
	}
		this.h += this.style.borderWidth - this.style.itemSpacing
	
		this.container.setSize(this.w, this.h)
		
		if (window.Drag && this.enableDrag)	{
			drag.add(this.container)
			if (this.itemDrag != null) {
				var which = this.itemDrag
				item = this.items[which]
				drag.setGrab(this.container, item.y, item.w, item.y + item.h, item.x)
			}
		}
		else drag = []
	
	if (this.visibility == "visible") this.container.show()
	this.created = true
}
Menu.prototype.destroy = function() {
	if (is.ie) this.container.elm.outerHTML = ""
	if (is.ns) this.container.hide()
	this.container.setClip(0,0,0,0)
	this.container.setHTML()
	Menu.count--
}
function MenuItemUp(e) {
	var item = this.items[e.src.i]
	if (this.container.dragActive) return

	if (this.onItemUp(e) == false) return
	
	var target = (parent.frames[this.target])?parent.frames[target]:self;
	
	if (item.url.indexOf("javascript:") != -1) eval(item.url)
	else target.location = item.url

}
function MenuItemDown(e) {
	if (drag.active) return
	var item = this.items[e.src.i]
	if (this.onItemDown(e) == false) return
	item.lyr.setBgColor(this.style.bgColorDown)
}
function MenuItemOver(e) {
	if (drag.active) return
	var item = this.items[e.src.i]
	status = item.text

	if (this.onItemOver(e) == false) return

	item.lyr.setBgColor(item.bgColorOver)
	if (this.style.useTextOver) {
		if (is.ie) item.lyr.elm.all.q.className = this.id + "Over"
		else item.o.show()
	}
}
function MenuItemOut(e) {
	if (drag.active) return
	var item = this.items[e.src.i]
	status = ""
	
	if (this.onItemOut(e) == false) return
	item.lyr.setBgColor(item.bgColorOut)
	
	if (this.style.useTextOver) {
		if (is.ie) item.lyr.elm.all.q.className = this.id + "Normal"
		else item.o.hide()
	}
	
}

function Open_In_Frame(url)
{ parent.main.location = url; }

function Open_Top_Frame(url)
{ top.location = url  }

