//********************************* Begin MenuUtility ****************************************//

/**************
Copyright (c) 2001 Ryan Schaeffer

Version 1.1

**************/

var activated = false;
{
var g_z, g_curmenu;
var g_delay = 100;
var g_speed = 50;
var g_divs = [];
var g_menus = [];
var g_submenus = [];
var timeoutVar = [];
var g_rollstate = 0;
var g_build = '';
}

function g_ReturnMenu(index) { return g_menus[index] }
function g_ReturnSubmenu(index) { return g_submenus[index] }
function g_getOffsets(id) {
	var offsets = new Object()
	var p = eval(docObj + q + id + q + divObj)
	offsets.l = offsets.t = 0
	while(p!=null) {
		offsets.l += p.offsetLeft
		offsets.t += p.offsetTop
		p = p.offsetParent
	}
	return offsets
}
function g_closeOpenMenu(menu) {
	for(var i=0; i<g_submenus.length; i++)
	{	
		if (g_submenus[i].active && menu.id!=g_submenus[i].id) {
			var lyr = g_submenus[i]
			var p = lyr.getParent()
			if (lyr.slide && !lyr.justdown) {
				lyr.stop = true
				g_submenus[i].active = false
				clearTimeout(timeoutVar[i])
				lyr.slideOut()
			} else timeoutVar[lyr.globalsubmenuindex] = setTimeout(lyr.obj+".hide()",g_delay)
		}
	}
}

function setSpeed(ms) { g_speed = ms }
function setTimeoutDelay(delay) { g_delay = delay }
function activateMenus() { for (var i=0; i<g_menus.length; i++) g_menus[i].activate() }
function buildMenus() { for (var i=0; i<g_menus.length; i++) g_build += g_menus[i].build() }
function writeMenus() {
	if (is.supported || is.ns4) document.write((is.ns?"<div style='visibility:hidden;left:-1000;top:-1000;'>":"") + g_build + (is.ns?"</div>":"") ) 
}
function destroyMenus() { for (var i=0; i<g_menus.length; i++) g_menus[i].destroy() }
	
// REQUIRES browsercheck.js
//*******************************************************************************************
//***************************** Menu ********************************************************

function Menu(refid,w,h) {
	if (refid == null) {
		alert("Missing reference DIV id")
	}
	this.id = refid
	this.width = w
	this.height = h

	this.submenu = null
	this.div = ''

	this.position = 'absolute'
	this.firstover = true
	
	this.rolloverfunc = null
	this.bounds = new Object()

	this.globalmenuindex = g_menus.length
	g_menus[g_menus.length] = this

	this.obj = this.id + "Object"
	eval(this.obj + "=this")
}
{
var p = Menu.prototype
p.setFix			= Menu_SetFix
p.getID				= Menu_GetID
p.setRolloverInfo	= Menu_SetRolloverInformation
p.setSubmenu		= Menu_SetSubmenu
p.getSubmenu		= Menu_GetSubmenu
p.inBounds			= Menu_InBounds
p.initCoords		= Menu_InitCoordinates
p.build				= Menu_BuildMenu
p.activate			= Menu_ActivateMenu
}
Menu.count = 0

function Menu_SetFix(img) { if(is.ns4) this.fix = img }
function Menu_GetID() {	return this.id }
function Menu_SetSubmenu(subm) { 
	subm.setParent(this)
	this.submenu = subm 
}
function Menu_GetSubmenu() { return this.submenu }
function Menu_SetRolloverInformation(func, params_over, params_off) {
	this.rolloverfunc = new Object()
	this.rolloverfunc.func = func

	var fix = (this.fix) ? "fix" : ""
	var paramlist = ''
	for (var i=0; i < params_over.length; i++) paramlist += '"' + params_over[i] + ((i==(params_over.length-1))? fix : '') + '",'
	if (params_over.length!=0) paramlist = paramlist.substring(0,paramlist.length-1)
	this.rolloverfunc.params_over = "(" + paramlist + ")"
	
	paramlist = ''
	for (var i=0; i < params_off.length; i++) paramlist += '"' + params_off[i] + ((i==(params_off.length-1))? fix : '') + '",'
	if (params_off.length!=0) paramlist = paramlist.substring(0,paramlist.length-1)
	this.rolloverfunc.params_off = "(" + paramlist + ")"
}

function Menu_InBounds(l, t) {
	var menu_l = this.bounds.l
	var menu_t = this.bounds.t
	var menu_r = menu_l + this.bounds.w
	var menu_b = menu_t + this.bounds.h
	
	return ( l>=menu_l && l<=(menu_r) && t>=menu_t  && t<=(menu_b) )
}

function Menu_InitCoordinates() {
	var offsets = (!is.ns4) ? g_getOffsets(this.getID()) : null
	var ns6_offsetY = (is.ns6) ? this.height - 15 : 0
	this.bounds.l = (is.ns4) ? document.anchors[this.id].x : offsets.l
	this.bounds.t = (is.ns4) ? document.anchors[this.id].y : offsets.t - ns6_offsetY
	var testoffsets = (!is.ns4) ? g_getOffsets(this.id+"test") : null
	this.bounds.w = this.width
	this.bounds.h = this.height
	this.firstover = false
}

function Menu_BuildMenu() {	
	return (this.getSubmenu()) ? this.getSubmenu().build() : ''
}

function Menu_ActivateMenu() {
	var menuobj = (is.ns4) ? document.anchors[this.id] : eval(docObj + q + this.id + q + divObj)
	this.initCoords()
	menuobj.globalmenuindex = this.globalmenuindex

	if (this.getSubmenu()) this.getSubmenu().activate()
	activated = true
}

function Menu_Rollover(menu) {
	var menuobj = (is.ns4) ? document.anchors[menu] : eval(docObj + q + menu + q + divObj)
	var lyr = g_menus[menuobj.globalmenuindex]
	var subm = lyr.getSubmenu()
	g_rollstate = 0
	g_closeOpenMenu(subm)

	if (subm != null && subm.active) return
	if (lyr.rolloverfunc!=null) eval(lyr.rolloverfunc.func+lyr.rolloverfunc.params_over)
	if (subm) {
		if (subm.slide) {
			subm.state = 'opening'
			subm.initSlide()
			subm.active = true
			clearTimeout(subm.globalsubmenuindex)
			subm.slideIn()
		} else subm.expand()
	}
}

//*******************************************************************************************
//***************************** Submenu *****************************************************

function Submenu(begintbl,endtbl, parent, align) {
	this.id = 'libSubmenu'+(Submenu.count++)
	this.type = 'Submenu'
	this.align = (align || 'left')
	this.items = []
	this.div = ''
	parent.setSubmenu(this)
	this.parent = parent
	
	this.vert = false
	this.slide = true
	this.justdown = false
	this.inc = 0
	this.zindex = 20
	this.stop = true
	this.state = 'closed'
	if (is.slowbrowser) this.justdown = true

	this.bounds = new Object()
	this.begintable = (begintbl || "<table cellpadding=0 cellspacing=0 border=0>")
	this.endtable = (endtbl || "</table>")
	this.clip = new Object()

	this.globalsubmenuindex = g_submenus.length
	g_submenus[g_submenus.length] = this

	this.obj = this.id + "Object"
	eval(this.obj + "=this")
}
{
var p = Submenu.prototype
p.getID				= Submenu_GetID
p.setBeginTable		= Submenu_SetBeginTable
p.setEndTable		= Submenu_SetEndTable
p.setVerticalExpand = Submenu_SetVerticalExpand
p.getMenuItems		= Submenu_GetMenuItems
p.addMenuItem		= Submenu_AddMenuItem
p.setParent			= Submenu_SetParent
p.getParent			= Submenu_GetParent
p.isEmpty			= Submenu_IsEmpty
p.expand			= Submenu_Expand
p.moveTo			= Submenu_MoveTo
p.moveBy			= Submenu_MoveBy
p.initSlide			= Submenu_InitSlide
p.slideIn			= Submenu_SlideIn
p.slideOut			= Submenu_SlideOut
p.stopSlide			= Submenu_StopSlide
p.hide				= Submenu_Hide
p.collapse			= Submenu_Collapse
p.inBounds			= Menu_InBounds
p.build				= Submenu_BuildMenu
p.initCoords		= Submenu_InitCoordinates
p.activate			= Submenu_ActivateMenu
p.clipTo			= Submenu_ClipTo
p.clipBy			= Submenu_ClipBy
}
Submenu.count = 0

function Submenu_GetID() { return this.id }
function Submenu_SetBeginTable(tabletxt) {	this.begintable = tabletxt }
function Submenu_SetEndTable(tabletxt) { this.endtable = tabletxt }
function Submenu_SetVerticalExpand(flag) {	this.vert = flag }
function Submenu_GetMenuItems() { return this.items }
function Submenu_AddMenuItem(menuitem) { 
	menuitem.parent = this
	this.items[this.items.length] = menuitem 
}
function Submenu_SetParent(p) { this.parent = p }
function Submenu_GetParent() { return this.parent }
function Submenu_IsEmpty() { return (this.items.length==0) }

function Submenu_Expand() {
	if (is.ns6) eval(docObj + q + this.getID()+"_parent" + q + styleObj + '.visibility=' + visible)
	eval(docObj + q + this.getID() + q + styleObj + '.visibility=' + visible)
}

function Submenu_MoveTo(id, x, y) {
	eval(docObj + q + id + q + styleObj + layerLeft + '=' + (x) )
	eval(docObj + q + id + q + styleObj + layerTop + '=' + (y) )
}

function Submenu_MoveBy(id, x, y) {
	var newx = parseInt(eval(docObj + q + id + q + styleObj + layerLeft)) + x
	var newy = parseInt(eval(docObj + q + id + q + styleObj + layerTop)) + y
	Submenu_MoveTo(id,newx,newy)
}

function Submenu_Collapse() { 
	if (is.ns6) eval(docObj + q + this.getID()+"_parent" + q + styleObj + '.visibility=' + visible)
	eval(docObj + q + this.getID() + q + styleObj + '.visibility=' + hidden)
}

function Submenu_BuildMenu() {
	if (!this.isEmpty()) {
		this.div = 	"<DIV ID='"+this.getID()+"' STYLE='position:absolute; left:0; top:0; z-index:"+this.zindex+"; visibility:hidden;"+(!is.ie4?"width:0;":"")+"'>"
		this.div += this.begintable
		for (var i=0; i < this.items.length; i++) {
			this.div += this.items[i].build()
		}
		this.div += this.endtable + "</DIV>"
		if (is.ns6) this.div = "<DIV ID='"+this.getID()+"_parent' STYLE='position:absolute; left:0; top:0; z-index:"+this.zindex+"; visibility:hidden'>" + this.div + "</DIV>"
	}
	return this.div
}

function Submenu_InitCoordinates() {
	var divw = eval(docObj + q + this.getID() + q + divObj + dynWidth)
	var divh = eval(docObj + q + this.getID() + q + divObj + dynHeight)
	if (!is.ie4) {
		eval(docObj + q + this.getID() + q + styleObj + '.width='+divw)
		eval(docObj + q + this.getID() + q + styleObj + '.height='+divh)
	}
	this.bounds.h = divh
	this.bounds.w = divw

	var p = this.getParent()
	var dif = is.ns6 ? 5 : 1
	if (this.vert) {
		if (this.align=='left') dif += (this.bounds.w - p.bounds.w)/2
		else if (this.align=='right') dif += (this.bounds.w - p.bounds.w)
		this.bounds.l = (p.bounds.l-dif)
		this.bounds.t = (p.bounds.t+p.bounds.h)
		if (this.slide) {
			if (is.ns6) {
				this.moveTo(this.getID()+"_parent", this.bounds.l, (p.bounds.t+p.bounds.h) )
				this.moveTo(this.getID(), 0, -(this.bounds.h) )
				eval(docObj + q + this.getID()+"_parent" + q + styleObj + ".clip = 'rect("+0+" "+this.bounds.w+" "+this.bounds.h+" "+0+")'")
			} else this.moveTo(this.getID(), this.bounds.l, ((p.bounds.t+p.bounds.h)-this.bounds.h) )
		} else {
			if (is.ns6) {
				this.moveTo(this.getID()+"_parent", this.bounds.l, (p.bounds.t+p.bounds.h) )
				this.moveTo(this.getID(), 0, 0 )
			} else this.moveTo(this.getID(), this.bounds.l, (p.bounds.t+p.bounds.h) )
		}
	}
	else { // horizontal menu
		if (this.align=='center') dif += (this.bounds.h - p.bounds.h)/2
		else if (this.align=='bottom') dif += (this.bounds.h - p.bounds.h) - ((is.ns6) ? 4 : 0)
		this.bounds.l = (p.bounds.l+p.bounds.w)
		this.bounds.t = (p.bounds.t-dif)
		if (this.slide) {
			if (is.ns6) {
				this.moveTo(this.getID()+"_parent", (p.bounds.l+p.bounds.w), this.bounds.t )
				this.moveTo(this.getID(), -(this.bounds.w), 0 )
				eval(docObj + q + this.getID()+"_parent" + q + styleObj + ".clip = 'rect("+0+" "+this.bounds.w+" "+this.bounds.h+" "+0+")'")
			} else this.moveTo(this.getID(), ((p.bounds.l+p.bounds.w)-this.bounds.w), this.bounds.t)
		} else {
			if (is.ns6) {
				this.moveTo(this.getID()+"_parent", (p.bounds.l+p.bounds.w), this.bounds.t )
				this.moveTo(this.getID(), 0, 0 )
			} else this.moveTo(this.getID(), (p.bounds.l+p.bounds.w), this.bounds.t )
		}
	}
}

function Submenu_ActivateMenu() {
	var submenu = eval(docObj + q + this.getID() + q + divObj)
	submenu.globalsubmenuindex = this.globalsubmenuindex
	submenu.onmouseover = Submenu_Rollover
	submenu.onmouseout = Submenu_Rolloff

	this.initCoords()
	if (is.ns4) { this.clip = eval(docObj + q + this.getID() + q + styleObj + ".clip") }
}

function Submenu_Rollover(e) {
	var lyr = g_ReturnSubmenu(this.globalsubmenuindex)
	if (!lyr.slide || lyr.justdown) {
		lyr.state = 'opening'
		lyr.active = true
		clearTimeout(lyr.globalsubmenuindex)
		lyr.slideIn()
	} else lyr.expand()
}

function Submenu_Rolloff(e) {
	if (!activated) return
	var evt = (is.ns) ? e : window.event
	var l = ((is.ns)? evt.pageX : (evt.clientX + document.body.scrollLeft))
	var t = ((is.ns)? evt.pageY : (evt.clientY + document.body.scrollTop))

	for(var i=0; i<g_submenus.length; i++)
	{	
		if (g_submenus[i].active) {
			var lyr = g_submenus[i]
			var p = lyr.getParent()
			if (!lyr.inBounds(l, t) && !p.inBounds(l, t)) {
				if (lyr.slide && !lyr.justdown) {
					lyr.stop = true
					g_submenus[i].active = false
					clearTimeout(timeoutVar[i])
					lyr.slideOut()
				} else timeoutVar[lyr.globalsubmenuindex] = setTimeout(lyr.obj+".hide()",g_delay)
			}
		}
	}
}

function Submenu_Hide() {
	if (this.justdown) this.stopSlide('closed')
	else this.collapse()
	if (this.parent.rolloverfunc!=null) eval(this.parent.rolloverfunc.func+this.parent.rolloverfunc.params_off)
}

function Submenu_ClipTo(t, r, b, l) {
	this.clip.top = t
	this.clip.right = r
	this.clip.bottom = b
	this.clip.left = l
	if (!is.ns) eval(docObj + q + this.getID() + q + styleObj + ".clip = 'rect("+t+" "+r+" "+b+" "+l+")'")
}

function Submenu_ClipBy(t, r, b, l) {
	this.clip.top += t
	this.clip.right += r
	this.clip.bottom += b
	this.clip.left += l
	if (!is.ns) eval(docObj + q + this.getID() + q + styleObj + ".clip = 'rect("+this.clip.top+" "+this.clip.right+" "+this.clip.bottom+" "+this.clip.left+")'")
}

function Submenu_InitSlide() {
	if (this.inc == 0) this.inc = Math.ceil(this.bounds.h/(this.bounds.h*.05))
	var p = this.getParent()
	if (this.vert) {
		this.clipTo(this.bounds.h, this.bounds.w, this.bounds.h, 0)	
		if (is.ns6) this.moveTo(this.getID(), 0, -(this.bounds.h) )
		else this.moveTo(this.getID(), this.bounds.l, ((p.bounds.t+p.bounds.h)-this.bounds.h) )
	} else {
		this.clipTo(0, this.bounds.w, this.bounds.h, this.bounds.w)	
		if (is.ns6) this.moveTo(this.getID(), -(this.bounds.w), 0 )
		else this.moveTo(this.getID(), ((p.bounds.l+p.bounds.w)-this.bounds.w), this.bounds.t )
	}
	this.stop = false
	this.zindex = (!g_z) ? g_z = this.zindex : g_z++
	if (is.ns6) {
		eval(docObj + q + this.getID()+"_parent" + q + styleObj + ".zIndex = "+this.zindex)
	}
	this.expand()
}

function Submenu_SlideIn() {
	if (!this.stop ) {
		if (this.vert) {
			if (this.clip.top > this.inc) {
				this.clipBy(-(this.inc),0,0,0)
				this.moveBy(this.getID(), 0, this.inc)
				timeoutVar[this.globalsubmenuindex] = setTimeout(this.obj+".slideIn()",g_speed)
			} else this.stopSlide('open')
		} else {
			if (this.clip.left > this.inc) {
				this.clipBy(0,0,0,-(this.inc))
				this.moveBy(this.getID(), this.inc, 0)
				timeoutVar[this.globalsubmenuindex] = setTimeout(this.obj+".slideIn()",g_speed)
			} else this.stopSlide('open')
		}
	}
}

function Submenu_SlideOut() {
	if (this.stop ) {
		if (this.vert) {
			if (this.clip.top < (this.bounds.h-this.inc)) {
				this.clipBy(this.inc,0,0,0)
				this.moveBy(this.getID(), 0, -(this.inc))
				timeoutVar[this.globalsubmenuindex] = setTimeout(this.obj+".slideOut()",g_speed)
			} else this.stopSlide('closed')
		} else {
			if (this.clip.left < (this.bounds.w-this.inc)) {
				this.clipBy(0,0,0,this.inc)
				this.moveBy(this.getID(), -(this.inc), 0)
				timeoutVar[this.globalsubmenuindex] = setTimeout(this.obj+".slideOut()",g_speed)
			} else this.stopSlide('closed')
		}
	}
}

function Submenu_StopSlide(newstate) {
	var p = this.getParent()
	if (is.ns6) this.moveTo(this.getID(), 0, 0 )
	else { 
		if (this.vert) this.moveTo(this.getID(), this.bounds.l, (p.bounds.t+p.bounds.h) )
		else this.moveTo(this.getID(), (p.bounds.l+p.bounds.w), this.bounds.t )
	}
	this.stop = true
	this.state = newstate
	if (this.state=='open') this.clipTo(0, this.bounds.w, this.bounds.h, 0)
	else {
		this.clipTo(0, this.bounds.w, this.bounds.h, this.bounds.w)
		this.collapse()
		if (p.rolloverfunc!=null) eval(p.rolloverfunc.func+p.rolloverfunc.params_off)
	}
}

//*******************************************************************************************
//***************************** MenuItem ****************************************************

function MenuItem(content, begintxt, endtxt, submenu) {
	this.id = 'libMenuItem'+(MenuItem.count++)
	this.type = 'MenuItem'
	this.content = content
	this.beginitem = (begintxt || '')
	this.enditem = (endtxt || '')
	this.cell = ''

	this.obj = this.id + "Object"
	eval(this.obj + "=this")
}
{
var p = MenuItem.prototype
p.getID				= Menu_GetID
p.setContent		= MenuItem_SetContent
p.getContent		= MenuItem_GetContent
p.setBeginItem		= MenuItem_SetBeginItem
p.setEndItem		= MenuItem_SetEndItem
p.build				= MenuItem_Build
}
MenuItem.count = 0

function MenuItem_SetContent() { this.content = content }
function MenuItem_GetContent() { return this.content }
function MenuItem_SetBeginItem(begintxt) { this.beginitem = begintxt }
function MenuItem_SetEndItem(endtxt) { this.enditem = endtxt }
function MenuItem_Build() {
	this.cell = this.beginitem + this.content + this.enditem
	return this.cell
}