

ssmenu.Registry 	= []
ssmenu.mLength 		= 150
ssmenu.hideDelay 	= 200
ssmenu.minCPUResolution = 10


function ssmenu(id, dir, left, top, width, height)
{
	coordinates 	= getAnchorPosition( id );
	left			= left + coordinates.x;
	top				= top + coordinates.y;

	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.id				= id
		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.mTimer	 		= false
		this.open			= false
		this.over			= false
		this.startTime	 	= 0

		this.mReference 	= "ssmenu_"+id
		eval(this.mReference+"=this")

		ssmenu.Registry[id] = this

		var d = document

        var staticStyle = '<style type="text/css">';
        staticStyle += '#' + this.id + 'Container { visibility:hidden; '
		staticStyle += 'left:' + left + 'px; '
		staticStyle += 'top:' + top + 'px; '
		staticStyle += 'overflow:hidden; z-index:102; }'
		staticStyle += '#' + this.id + 'Container, #' + this.id + 'Content { ';
		staticStyle	+= 'position:absolute; '
		staticStyle += 'width:' + width + 'px; '
		staticStyle += 'height:' + height + 'px; '
		staticStyle += 'clip:rect(0 ' + width + ' ' + height + ' 0); '
		staticStyle += '}'
        staticStyle += '</style>';

        d.write(staticStyle)

		this.load()
	}
}

ssmenu.prototype.load = function() {
	var d 		= document
	var mId1 	= this.id + "Container"
	var mId2 	= this.id + "Content"
	var obj1 	= this.dom ? d.getElementById(mId1) : this.ie ? d.all[mId1] : d.layers[mId1]

	if (obj1) var obj2 = this.ns4 ? obj1.layers[mId2] : this.ie ? d.all[mId2] : d.getElementById(mId2)

	var temp

	if (!obj1 || !obj2) window.setTimeout(this.mReference + ".load()", 100)
	else {
		this.container	= obj1
		this.menu	= obj2
		this.style	= this.ns4 ? this.menu : this.menu.style
		this.homePos	= eval("0" + this.dirType + this.dim)
		this.outPos	= 0
		this.accelConst	= (this.outPos - this.homePos) / ssmenu.mLength / ssmenu.mLength 

		if (this.ns4) this.menu.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
		this.menu.onmouseover = new Function("ssmenu.showMenu('" + this.id + "')")
		this.menu.onmouseout = new Function("ssmenu.hideMenu('" + this.id + "')")

		this.endSlide()
	}
}
	
ssmenu.showMenu = function(id, parent)
{
	var reg = ssmenu.Registry
	var obj = ssmenu.Registry[id]
	
	if ( parent ){ 
		var obj2 = ssmenu.Registry[parent]
	}
	
	if (obj.container) {
		obj.over = true

		for (menu in reg){
			if (id != menu && parent != menu) ssmenu.hide(menu)
		}

		if (obj.hideTimer) { reg[id].hideTimer = window.clearTimeout(reg[id].hideTimer) }
		if (parent){
			if (obj2.hideTimer) { reg[parent].hideTimer = window.clearTimeout(reg[parent].hideTimer) }
		}

		if (!obj.open && !obj.mTimer) reg[id].startSlide(true)
	}
}

ssmenu.hideMenu = function(id)
{
	
	var obj = ssmenu.Registry[id]

	if (obj.container) {
		if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
		obj.hideTimer = window.setTimeout("ssmenu.hide('" + id + "')", ssmenu.hideDelay);
	}


}

ssmenu.hide = function(id)
{
	var obj 	= ssmenu.Registry[id]
	obj.over 	= false

	if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
	
	obj.hideTimer = 0

	if (obj.open && !obj.mTimer) obj.startSlide(false)
}

ssmenu.prototype.startSlide = function(open) {

	this[open ? "onactivate" : "ondeactivate"]()
	this.open 	= open

	if (open) this.setVisibility(true)

	this.startTime = (new Date()).getTime()	
	this.mTimer = window.setInterval(this.mReference + ".slide()", ssmenu.minCPUResolution)
}

ssmenu.prototype.slide = function() {

	var elapsed 	= (new Date()).getTime() - this.startTime

	if (elapsed > ssmenu.mLength) this.endSlide()
	else {
		var d = Math.round(Math.pow(ssmenu.mLength-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)
	}
}

ssmenu.prototype.endSlide = function() {

	this.mTimer 	= window.clearTimeout(this.mTimer)
	this.moveTo(this.open ? this.outPos : this.homePos)

	if (!this.open) this.setVisibility(false)

	if ((this.open && !this.over) || (!this.open && this.over)) {
		this.startSlide(this.over)
	}
}

ssmenu.prototype.setVisibility = function(bShow) { 

	var s 	= this.ns4 ? this.container : this.container.style

	s.visibility = bShow ? "visible" : "hidden"
}

ssmenu.prototype.moveTo = function(p) { 

	this.style[this.orientation == "h" ? "left" : "top"] = this.ns4 ? p : p + "px"
}

ssmenu.prototype.getPos = function(c) {

	return parseInt(this.style[c])
}

ssmenu.prototype.onactivate	= function() { }
ssmenu.prototype.ondeactivate	= function() { }

/*
 * Get the Anchor Position
 */

function getAnchorPosition( anchorname ) {

	var useWindow	= false;
	var coordinates	= new Object();
	var x			= 0;
	var y			= 0;
	var use_gebi	= false;	
	var use_css		= false;
	var use_layers	= false;

	if (document.getElementById) { 
		use_gebi	= true; 
	}
	else if (document.all) { 
		use_css		= true; 
	}
	else if (document.layers) { 
		use_layers	= true; 
	}
	
	if (use_gebi && document.all) {
		x	= AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y	= AnchorPosition_getPageOffsetTop(document.all[anchorname]);
	}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x	= AnchorPosition_getPageOffsetLeft(o);
		y	= AnchorPosition_getPageOffsetTop(o);
	}
 	else if (use_css) {
		x	= AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y	= AnchorPosition_getPageOffsetTop(document.all[anchorname]);
	}
	else if (use_layers) {
		var found	= 0;
		for (var i = 0; i < document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { 
				found=1; 
				break; 
			}
		}
		if (found==0) {
			coordinates.x	= 0; 
			coordinates.y	= 0; 
			return coordinates;
		}
		x	= document.anchors[i].x;
		y	= document.anchors[i].y;
	}
	else {
			coordinates.x	= 0; 
			coordinates.y	= 0; 
			return coordinates;
	}

	coordinates.x	= x;
	coordinates.y	= y;

	return coordinates;
}

function AnchorPosition_getPageOffsetLeft (el) {
	var ol	= el.offsetLeft;
	while ((el=el.offsetParent) != null) { 
		ol 	+= el.offsetLeft; 
	}
	
	return ol;
}

function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
}	

function AnchorPosition_getPageOffsetTop (el) {
	var ot	= el.offsetTop;
	while((el=el.offsetParent) != null) { 
		ot += el.offsetTop; 
	}
	
	return ot;
}

function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
}

