/*****************************************************

* ypSlideOutMenu

* Code used with permission from  www.youngpup.net

* --youngpup--  3/04/2001

*****************************************************/



ypSlideOutMenu.Registry = []

ypSlideOutMenu.aniLen = 250

ypSlideOutMenu.hideDelay = 100

ypSlideOutMenu.minCPUResolution = 10



function ypSlideOutMenu(id, dir, left, top, width, height, parentid, degrade, debug)

{

	this.ie = document.all ? 1 : 0

	this.ns4 = document.layers ? 1 : 0

	this.dom = document.getElementById ? 1 : 0

	if (this.ie || this.ns4 || this.dom) {

		this.degrade = degrade;

		this.debug = debug;

		this.id = id

		this.parentid = parentid

		this.dir = dir

		this.orientation = dir == "left" || dir == "right" ? "h" : "v"

		this.dirType = dir == "right" || dir == "down" ? "-" : "+"

		this.dim = this.orientation == "h" ? width : height

		this.hideTimer = false

		this.aniTimer = false

		this.open = false

		this.over = false

		this.startTime = 0

		this.gRef = "ypSlideOutMenu_"+id

		eval(this.gRef+"=this")

		ypSlideOutMenu.Registry[id] = this

		

		this.initleft = left

		this.inittop = top

		this.initwidth = width

		this.initheight = height





// The following code where it invokes "document.write" crashed when we had

// more than 31 menus total.  Some kind of buffer overrun I'm assuming.

// What crashed is that the styles that were declared in the css disappeared

// with 31 menus, where 32 menus caused the d.write call to fail entirely.

// As a workaround I created the function setStyle (below).

// if you want to put more then 31 menus, comment this out from "START" to "END".



// START

		var d = document

		d.write('<style type="text/css">')

		d.write('#' + this.id + 'Container { visibility:hidden; ')

		d.write('left:' + left + 'px; ')

		d.write('z-index:' + 50 + '; ')

		d.write('top:' + top + 'px; ')

		d.write('overflow:hidden; }')

		d.write('#' + this.id + 'Container, #' + this.id + 'Content { position:absolute; ')

		d.write('width:' + width + 'px; ')

		d.write('height:' + height + 'px; ')

		d.write('z-index:' + 50 + '; ')

		d.write('clip:rect(0 ' + width + ' ' + height + ' 0); ')

		d.write('}')

		d.write('</style>')

// END

		this.load()

	}

}



ypSlideOutMenu.prototype.load = function() {

	var d = document

	var lyrId1 = this.id + "Container"

	var lyrId2 = this.id + "Content"

	var obj1 = this.dom ? d.getElementById(lyrId1) : this.ie ? d.all[lyrId1] : d.layers[lyrId1]

	if (obj1) var obj2 = this.ns4 ? obj1.layers[lyrId2] : this.ie ? d.all[lyrId2] : d.getElementById(lyrId2)

	if (!obj1 || !obj2) {

		window.setTimeout(this.gRef + ".load()", 1000);

	} else {

		this.container = obj1

		this.menu = obj2

		this.style = this.ns4 ? this.menu : this.menu.style

		// SEE NOTE ABOVE.  The following function call for the 31 menus bug.

		//this.setStyle()

		this.homePos = eval("0" + this.dirType + this.dim)

		this.outPos = 0

		this.accelConst = (this.outPos - this.homePos) / ypSlideOutMenu.aniLen / ypSlideOutMenu.aniLen 

		if (this.ns4) this.menu.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);

		this.menu.onmouseover = new Function("ypSlideOutMenu.showMenu('" + this.id + "')")

		this.menu.onmouseout = new Function("ypSlideOutMenu.hideMenu('" + this.id + "')")

		this.endSlide()

	}

}

/*

// See note above.  This function was a workaround for the 31 menus bug.



ypSlideOutMenu.prototype.setStyle = function() {

	var containerstyle = this.ns4 ? this.container : this.container.style

	var menustyle = this.ns4 ? this.menu : this.menu.style



	// might not be able to use the "px" suffix w/ netscape 4



	containerstyle.visibility = "hidden";

	containerstyle.left = this.initleft + "px";

	containerstyle.top = this.inittop + "px";

	containerstyle.overflow = "hidden";



	// Note: in IE4.0 you can't set the position to absolute in

	// the following statement -- it says "object does not

	// support this" or something.

	// if we want to bring this function back so that > 31 menus can

	// be used, something has to be done about this bug.

	containerstyle.position = "absolute";



	containerstyle.width = this.initwidth + "px";

	containerstyle.height = this.initheight + "px";

	containerstyle.clip = "rect(0 " + this.initwidth + " " + this.initheight + " 0)"

	menustyle.position = "absolute";

	menustyle.width = this.initwidth + "px";

	menustyle.height = this.initheight + "px";

	menustyle.clip = "rect(0 " + this.initwidth + " " + this.initheight + " 0)"

}

*/

ypSlideOutMenu.showMenu = function(id)

{

	var reg = ypSlideOutMenu.Registry

	var obj = ypSlideOutMenu.Registry[id]

	if (obj.container) {

		obj.over = true

		if (obj.hideTimer) { reg[id].hideTimer = window.clearTimeout(reg[id].hideTimer) }

		if (obj.degrade) {

			obj.open = true;

			obj.endSlide();

			obj.setVisibility(true);

		}

		var z

		z = (!obj.open && !obj.aniTimer);

		if (z) reg[id].startSlide(true)

	}

	if (obj.ns4) obj.menu.routeEvent(Event.MOUSEOVER);

}



ypSlideOutMenu.hideMenu = function(id)

{

	var obj = ypSlideOutMenu.Registry[id]

	if (obj.container) {

		if (obj.hideTimer) window.clearTimeout(obj.hideTimer)

		obj.hideTimer = window.setTimeout("ypSlideOutMenu.hide('" + id + "')", ypSlideOutMenu.hideDelay);

	}

	if (obj.ns4) obj.menu.routeEvent(Event.MOUSEOUT);

}



ypSlideOutMenu.hide = function(id)

{

	var obj = ypSlideOutMenu.Registry[id]

	var reg = ypSlideOutMenu.Registry

	obj.over = false

	if (obj.hideTimer) window.clearTimeout(obj.hideTimer)

	obj.hideTimer = 0

	var overchild = false;

	for (menu in reg) {

		var pid = ypSlideOutMenu.Registry[menu].parentid

		if (pid == id) overchild = ypSlideOutMenu.Registry[menu].over ? true : overchild		

	}

	if (obj.open && !obj.aniTimer && !overchild) {

		if (obj.degrade) {

			obj.open = false;

			obj.endSlide();

		} else {

			obj.startSlide(false);

		}

	}

}



/*

// in order to keep this parent menu from closing before the

// child menu closes, I want to do something like this.

// However this didn't work, possibly because as you're

// mousing over a menu, hideMenu() and showMenu() get called more

// often than you'd think they should.  Dupe calls get

// ignored by the existing algorithm, but I need to trace

// it through and figure out why.



ypSlideOutMenu.hide = function(id)

{

	var overchild = false;

	var openchild = '';

	var obj = ypSlideOutMenu.Registry[id]

	var reg = ypSlideOutMenu.Registry

	var pid



	if (!obj.open || obj.aniTimer) return

	obj.over = false

	if (obj.hideTimer) window.clearTimeout(obj.hideTimer)

	obj.hideTimer = 0

	for (menu in reg) {

		pid = ypSlideOutMenu.Registry[menu].parentid

		if (pid == id) {

			overchild = ypSlideOutMenu.Registry[menu].over ? true : overchild		

			openchild = ypSlideOutMenu.Registry[menu].open ? menu.id : openchild

		}

	}

	if (!overchild) {

		if (openchild == '') {

			obj.startSlide(false);

		} else {

			ypSlideOutMenu.hide(openchild)

		}

	}

}



*/



ypSlideOutMenu.prototype.startSlide = function(open) {

	this.open = open

	if (open) this.setVisibility(true)

	this.startTime = (new Date()).getTime() 

	this.aniTimer = window.setInterval(this.gRef + ".slide()", ypSlideOutMenu.minCPUResolution)

}



ypSlideOutMenu.prototype.slide = function() {

	var elapsed = (new Date()).getTime() - this.startTime

	if (elapsed > ypSlideOutMenu.aniLen) this.endSlide()

	else {

		var d = Math.round(Math.pow(ypSlideOutMenu.aniLen-elapsed, 2) * this.accelConst)

		if (this.open && this.dirType == "-") d = -d

		else if (this.open && this.dirType == "+") d = -d

		else if (!this.open && this.dirType == "-") d = -this.dim + d

		else d = this.dim + d

		this.moveTo(d)

	}

}



ypSlideOutMenu.prototype.endSlide = function() {

	this.aniTimer = window.clearTimeout(this.aniTimer)

	this.moveTo(this.open ? this.outPos : this.homePos)

	if (!this.open) this.setVisibility(false)

	if (((this.open && !this.over) || (!this.open && this.over)) && (!this.parent || this.parent.open)) {

		this.startSlide(this.over)

	} else {

		var overchild = false;

		var reg = ypSlideOutMenu.Registry

		for (menu in reg) {

			var pid = ypSlideOutMenu.Registry[menu].parentid

			if (pid == this.id) overchild = ypSlideOutMenu.Registry[menu].over ? true : overchild		

		}

		if (!overchild && this.parentid && !ypSlideOutMenu.Registry[this.parentid].over) ypSlideOutMenu.hide(this.parentid);

	}

}



ypSlideOutMenu.prototype.setVisibility = function(bShow) { 

	var s = this.ns4 ? this.container : this.container.style

	// the browser crash that happens in some installations of IE 6 and 5.5

	// happened when I set the visibility in the following line.

	// when I commented the following line out it did not happen, but

	// when I moved the line up to the top of the call stack so that

	// it was the first statement executed, it did occur.

	s.visibility = bShow ? "visible" : "hidden"

}



ypSlideOutMenu.prototype.moveTo = function(p) { 

	this.style[this.orientation == "h" ? "left" : "top"] = p

}



ypSlideOutMenu.prototype.getPos = function(c) {

	return parseInt(this.style[c])

}

