/*****************************************************
* ypSlideOutMenu
* 3/04/2001
*
* a nice little script to create exclusive, slide-out
* menus for ns4, ns6, mozilla, opera, ie4, ie5 on 
* mac and win32. I've got no linux or unix to test on but 
* it should(?) work... 
*
* Revised:
* - 08/29/2002 : added .hideAll()
*
* --youngpup--
*****************************************************/
function cm_bwcheck(){
	//In theory we should use object detection, but this script needs work-arounds for almost every browser...
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent.toLowerCase()
	this.dom=document.getElementById?1:0
	this.ns4=(!this.dom && document.layers)?1:0;
	this.op=window.opera 
	this.moz=(this.agent.indexOf("gecko")>-1 || window.sidebar)
	this.ie=this.agent.indexOf("msie")>-1 && !this.op
	if(this.op){
		this.op5=(this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1)
		this.op6=(this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1)
		this.op7=this.dom&&!this.op5&&!this.op6 //So all higher opera versions will use it
	}else if(this.moz) this.ns6 = 1
	else if(this.ie)
	{
		this.ie4 = !this.dom && document.all
  		this.ie5 = (this.agent.indexOf("msie 5")>-1)
  		this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1)
  		this.ie6 = this.dom && !this.ie4 && !this.ie5 && !this.ie55
	}
	this.mac=(this.agent.indexOf("mac")>-1)
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6 || this.op7)
	this.usedom=this.ns6||this.op7//Use dom creation
	this.px=this.dom&&!this.op5?"px":""
	this.filter=(this.ie55||this.ie6) && !this.mac;
	return this
}
var bw=new cm_bwcheck()

var g_strMenuOrientation = "horizontal";
var g_strCurSection = "";
var g_lngMenuWidth;
var g_lngMenuHeight;
var g_lngMenuLeft = 0;
var g_lngMenuTop = 0;
ypSlideOutMenu.Registry = []
ypSlideOutMenu.aniLen = 250
ypSlideOutMenu.hideDelay = 600
ypSlideOutMenu.minCPUResolution = 10
// constructor
function ypSlideOutMenu(id, dir, left, top, width, height)
{
this.dom = document.getElementById ? 1 : 0
if (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.aniTimer = false
this.open = false
this.over = false
this.startTime = 0
this.gRef = "ypSlideOutMenu_"+id
eval(this.gRef+"=this")
ypSlideOutMenu.Registry[id] = this
var d = document
var strCSS = '<style type="text/css">';
strCSS += '#' + this.id + 'Container { visibility:hidden; '
strCSS += 'left:' + left + 'px; '
strCSS += 'top:' + top + 'px; '
strCSS += 'overflow:hidden; }'
strCSS += '#' + this.id + 'Container, #' + this.id + 'Content { position:absolute; '
strCSS += 'width:' + width + 'px; '
strCSS += 'height:' + height + 'px; '
strCSS += 'clip:rect(0 ' + width + ' ' + height + ' 0); '
strCSS += '}'
strCSS += '</style>'
d.write(strCSS)
this.load()
}
}
ypSlideOutMenu.prototype.load = function() {
var d = document
var lyrId1 = this.id + "Container"
var lyrId2 = this.id + "Content"
var obj1 = d.getElementById(lyrId1)
if (obj1) var obj2 = d.getElementById(lyrId2)
var temp
if (!obj1 || !obj2) window.setTimeout(this.gRef + ".load()", 100)
else {
this.container = obj1
this.menu = obj2
this.style = this.menu.style
this.homePos = eval("0" + this.dirType + this.dim)
this.outPos = 0
this.accelConst = (this.outPos - this.homePos) / ypSlideOutMenu.aniLen / ypSlideOutMenu.aniLen 
// set event handlers.
this.menu.onmouseover = new Function("ypSlideOutMenu.showMenu('" + this.id + "')")
this.menu.onmouseout = new Function("ypSlideOutMenu.hideMenu('" + this.id + "')")
this.act = d.getElementById(this.id);
this.act.onmouseover = new Function("ypSlideOutMenu.showMenu('" + this.id + "'); window.status='" + this.act.innerHTML + "'; return true");
this.act.onmouseout = new Function("ypSlideOutMenu.hideMenu('" + this.id + "'); window.status=''; return true");
var oX,oY;
switch(this.dir)
{
	case "right": oX = g_lngMenuWidth; oY = 0; break;
	case "down": oX = 0; oY = g_lngMenuHeight; break;
}
this.offsetX = oX;
this.offsetY = oY;

//set initial state
this.endSlide()
}
}
ypSlideOutMenu.showMenu = function(id)
{
var reg = ypSlideOutMenu.Registry
var obj = ypSlideOutMenu.Registry[id]
if (obj.container) {
if (obj.act.className != 'section') obj.act.className='active'
obj.over = true
for (menu in reg) if (id != menu) ypSlideOutMenu.hide(menu)
if (obj.hideTimer) { reg[id].hideTimer = window.clearTimeout(reg[id].hideTimer) }
if (!obj.open && !obj.aniTimer)
{ 
var aPos = findMenuPos(id);
obj.container.style.display = "block";
obj.container.style.top = (aPos[1] + obj.offsetY) + "px"
obj.container.style.left = (aPos[0] + obj.offsetX) + "px"
reg[id].startSlide(true)
}
}
}
ypSlideOutMenu.hideMenu = function(id)
{
var obj = ypSlideOutMenu.Registry[id]
if (obj.container) {
//if (obj.act.className != 'section') obj.act.className=''
if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
obj.hideTimer = window.setTimeout("ypSlideOutMenu.hide('" + id + "')", ypSlideOutMenu.hideDelay);
}
}
ypSlideOutMenu.hideAll = function()
{
var reg = ypSlideOutMenu.Registry
for (menu in reg) {
ypSlideOutMenu.hide(menu);
if (menu.hideTimer) window.clearTimeout(menu.hideTimer);
}
}
ypSlideOutMenu.hide = function(id)
{
var obj = ypSlideOutMenu.Registry[id]
obj.over = false
if (obj.hideTimer) window.clearTimeout(obj.hideTimer)
obj.hideTimer = 0
if (obj.open && !obj.aniTimer) obj.startSlide(false)
}
ypSlideOutMenu.prototype.startSlide = function(open) {
this[open ? "onactivate" : "ondeactivate"]()
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.act.className != 'section') this.act.className='';
}
if ((this.open && !this.over) || (!this.open && this.over)) {
this.startSlide(this.over)
}
}
ypSlideOutMenu.prototype.setVisibility = function(bShow) { 
var s = this.container.style
s.visibility = bShow ? "visible" : "hidden"
}
ypSlideOutMenu.prototype.moveTo = function(p) { 
this.style[this.orientation == "h" ? "left" : "top"] = p + "px"
}
ypSlideOutMenu.prototype.getPos = function(c) {
return parseInt(this.style[c])
}
ypSlideOutMenu.prototype.onactivate = function() { }
ypSlideOutMenu.prototype.ondeactivate = function() { }

// Added by Me

var lngTest = 1;
var lngAttempts = 0;

window.onresize = new Function("positionMenu()");

try
{
	onload = window.setTimeout("positionMenu()",1);
}
catch (e) {}

function positionMenu()
{
	try
	{
		
		var aPos = findMenuPos("MainTable")
		if ((aPos[0] == 0) && (aPos[1] == 0) && (lngAttempts < 2))
		{
			//document.title += "W";
			window.setTimeout("positionMenu()",100);
			lngAttempts++;
			return;
		}
		
		var objMenu = document.getElementById("menubar");
		
		//document.title += "[" + aPos[0] + "," + aPos[1] + "," + g_lngMenuLeft + "] ";
		objMenu.style.left = aPos[0] + g_lngMenuLeft + "px";
		objMenu.style.top = aPos[1] + g_lngMenuTop + "px";
		
		objMenu.style.visibility = "visible";
		
		var lngLength;
		var objList = objMenu.childNodes;
		var objMenuItem;
		var lngLeft = 0;
		var lngTop = 0;
		var blnDir = g_strMenuOrientation == "horizontal" ? 1 : 0
		var strID;
		
		if (blnDir)
		{
			lngLength = objList.length;
	
			for (lngItem = 0; lngItem < lngLength; lngItem++)
			{
				objMenuItem = objList[lngItem];
				//document.title += "[" + lngLeft + "]";
				strID = objMenuItem.id;
				
				if (strID.substring(0,2) == "c_")
				{
					/*try
					{
						var objContainer = document.getElementById(strID.substring(2) + "Container");
						objContainer.style.display = "block";
					}
					catch (e) { } */
					objMenuItem.style.left = lngLeft + "px";
					objMenuItem.style.top = lngTop + "px";
					objMenuItem.style.visibility = "visible";
				
					lngLeft += g_lngMenuWidth;
				}
			}
		}
		
		
		if (lngTest)
		{
			window.setTimeout("positionMenu()", 10)
			lngTest = 0;
		}
		else
			lngTest = 1;
	}
	catch (e)
	{
		//alert(e.toString());
	}
}

function findMenuPos(strDiv)
{
	try
	{
		//document.title += "1";
		var x=0; 
		var y=0; 
		var el,temp;
		el = document.getElementById(strDiv);
		//document.title += "2" + el.offsetParent.offsetLeft; 
		if(el.offsetParent)
		{
			//document.title += "3";
			temp = el
			while(temp.offsetParent)
			{ 
				//document.title += "!";
				temp=temp.offsetParent; 
				x+=temp.offsetLeft
				y+=temp.offsetTop;
			}
		}
		x+=el.offsetLeft
		y+=el.offsetTop
		//document.title += "[" + x + "," + y + "]";
		return [x,y];
		
	}
	catch(e)
	{
		//alert(e.toString());
		return [0,0]
	}
}

function SetMenuSection(strSection)
{
	try
	{
		if (g_strCurSection != "")
		{
			var objOld = document.getElementById(g_strCurSection);
			objOld.className = "";
		}
	
		var objNew = document.getElementById(strSection);
		objNew.className = "section";
		g_strCurSection = strSection;
	}
	catch(e)
	{
		//document.title = "Error setting section (" + strSection + ")";
	}
}