/*
Eric's pulldown menus v2.1 
Fixed menu generation and display bugs.
Added improved rightlimit support.
*/

// Important variables
var rightlimit= 780
var menuwidth= 120
var boxoffset= 17
var menudelay= 250
var currentItem= ""
var priorItem= ""
var menuOn= false
var killList= []
var kids=[]
var showlist= []
var kcnt=0


// master menu constructor
function pd_menu(mbase)
{
if (! document.getElementById) return

for (x in mbase)
	{
	pd_menu_block(mbase[x][0], mbase[x][1], kcnt)
	}
kcnt++
kidsthere=true
while (kidsthere)
	{
	var kc= new ArrayCopy(kids)
	kids.length=0
	buildKids(kc, kcnt)
	kcnt++
	if (kids.length==0) kidsthere= false
	}
}


function buildKids(arry, lvl)
{
for (x in arry)
	{
	pd_menu_block(arry[x][0][0], arry[x], lvl)
	}
}

// menu block constructor
function pd_menu_block(blockid, items, level)
{
killList[killList.length]=blockid

document.write('<div mlevel="'+level+'" class="menublock" id="'+blockid+'" onmouseout="outItem()">')

for (mi=0; mi<items.length; mi++)
	{
	if (items[mi][6])
		{
		child= items[mi][6][0][0]
		kids[kids.length]= items[mi][6]
		}
			
	document.write('<a href="'+items[mi][2]+'" target="'+items[mi][3]+'" id="'+items[mi][5]+'" class="'+items[mi][4]+'" '+(items[mi][6] ? "onmouseover=\""+getMover(child, items[mi][5])+"\" onmouseout=\"outItem()\"":"onmouseover=\"newItem('"+blockid+"',false)\" onmouseout=\"outItem()\"")+'>'+items[mi][1]+'</a>')
	}	
document.write('</div>')
}

// display functions

function showMenu(who, what, base)
{
el= document.getElementById(who)
that= document.getElementById(what)
if (!base)
	{
	el.style.left= getLeft(that, true)+ that.offsetWidth
	el.style.top= getTop(that)
	currentItem= who
	showlist[el.getAttribute("mlevel")]= el.id
	}
else
	{
	newItem(who, true)
	el.style.top= getTop(that)+ that.offsetHeight
	el.style.left= getLeft(that, false)
	currentItem= who
	menuOn= false
	img_off()
	menuOn= true
	img_on(what)
	showlist.length=0
	showlist[0]= el.id
	}
//selectOff()
el.style.visibility= 'visible'
menuOn= true
}

function hideMenu(who)
{
el= document.getElementById(who)
if (el) el.style.visibility= 'hidden'
}

function newItem(who, nodelay)
{
menuOn=true
priorItem= currentItem
currentItem= who
if (priorItem != currentItem)
	{
	if (nodelay) 
		{
		md= 0
		}
	else md= menudelay
	setTimeout('hideMenu("'+priorItem+'")', md)
	}
}

function outItem(that)
{
menuOn=false
setTimeout('killAll()',menudelay)

}

function killAll()
{
if (!menuOn)
	{
	//selctOn()
	killThis(killList)
	}
else
	{
	tmpa= []
	for (x=0; x<killList.length; x++)
		{
		match= false
		for (z in showlist)
			{
			if (showlist[z]==killList[x]) match=true
			}
		if (! match) tmpa[tmpa.length]= killList[x]
		}
	killThis(tmpa)
	}
img_off()
}

// Helper functions

function getLeft(Obj, subo)
{
xPos = Obj.offsetLeft;
tempObj = Obj.offsetParent;

while (tempObj != null)
	{
    xPos   += tempObj.offsetLeft;
    tempObj = tempObj.offsetParent;
    }
overby= (xPos+menuwidth+boxoffset)-rightlimit
if (subo) overby+= menuwidth+boxoffset

if (overby>30)
	{
	if (subo) {xPos= xPos-(menuwidth+boxoffset)*2}
	else {xPos= rightlimit-menuwidth-boxoffset}
	}
return xPos;
}  
  
function getTop(Obj){
  yPos = Obj.offsetTop;
  tempObj = Obj.offsetParent;
  while (tempObj != null){
    yPos += tempObj.offsetTop;
    tempObj = tempObj.offsetParent;
    }
  return yPos;
  }  
  
function getMover(child, parent)
{
return "showMenu('"+child+"', '"+parent+"', false)"
}

function killThis(arr)
	{
	for (q in arr) hideMenu(arr[q])
	}

function ArrayCopy(arr)
{
for (p in arr)
	{
	this[p]= arr[p]
	}
}	

	
// Some workaround script because IE does forms and z-index wrong
function selectOff()
{
sels= document.getElementsByTagName('select')
for (x=0; x<sels.length; x++)
	{
	sels[x].style.visibility= 'hidden'
	}
}

function selctOn()
{
sels= document.getElementsByTagName('select')
for (x=0; x<sels.length; x++)
	{
	sels[x].style.visibility= 'visible'
	}
}

// Image rollover script

var IMG_OVER=[]
var IMG_OFF= []
var currentIMG

// Deprecated with new CSS items
function preloadIMG(pics)
{
return
}

function img_on(what)
{
iel= document.getElementById(what)
iel.className= "pdhover"
currentIMG= what
}

function img_off()
{
iel= document.getElementById(currentIMG)
if (iel && menuOn==false)
	{
	iel.className= ""
	}
} 

function ss(txt)
{
document.getElementById("ss").innerHTML=txt
}

function hh(txt)
{
document.getElementById("hh").innerHTML=txt
}
