var drpTime = "2";
var drpPixels = 15;
var ieVer = 7;


function drpMenu(ID)
{
	this.expand   = drpMenuExpand;
	this.contract = drpMenuContract;
	this.set = drpMenuSet;
	this.ID = ID;
	return;
}

function drpMenuExpand()
{		

	if (typeof(this.contractTimer) != 'undefined') {
		clearTimeout(this.contractTimer);
	}
	
	if (this.currentHeight < this.expandedHeight) 
	{
		this.currentHeight += drpPixels;

		if (navigator.family == 'nn4') {
			eval('document.layers.Lyr' + this.ID + '.clip.height = this.currentHeight;');
		}
		else if (navigator.family == 'ie4' && navigator.version >= 4 && navigator.version < ieVer) {
			document.all[this.ID].style.height = this.currentHeight;
		}
		else if (navigator.DOMHTML && navigator.DOMCSS2) {
			document.getElementById(this.ID).style.height = this.currentHeight;
		}
		
		this.expandTimer = setTimeout("drpExpandThis(" + this.ID + ")", drpTime);
	}
}

function drpExpandThis(drpMenu)
{
	drpMenu.expand();
}

function drpMenuContract()
{

	if (typeof(this.expandTimer) != 'undefined') {
		clearTimeout(this.expandTimer);
	}

	if (this.currentHeight > this.contractedHeight) 
	{
		this.currentHeight -= drpPixels;		
		
		if (navigator.family == 'nn4') {
			eval('document.layers.Lyr' + this.ID + '.clip.height = this.currentHeight;');
		}
		else if (navigator.family == 'ie4' && navigator.version < ieVer) {
			document.all[this.ID].style.height = this.currentHeight;
		}
		else if (navigator.DOMHTML && navigator.DOMCSS2) {
			document.getElementById(this.ID).style.height = this.currentHeight;
		}
		
		this.contractTimer = setTimeout("drpContractThis(" + this.ID + ")", drpTime);
	}
}

function drpContractThis(drpMenu)
{
	drpMenu.contract();
}

function drpMenuSet(contractedHeight)
{
	eval(this.ID + '.contractedHeight = contractedHeight' );	
	eval(this.ID + '.currentHeight = contractedHeight' );

	if (navigator.family == 'nn4') {
		eval(this.ID + '.expandedHeight = document.layers.Lyr' + this.ID + '.clip.height');
		eval('document.layers.Lyr' + this.ID + '.clip.height = ' + this.ID + '.currentHeight');
		
		eval('document.layers.Lyr' + this.ID + '.visibility="show"');
	}
	else if (navigator.family == 'ie4' && navigator.version < ieVer) {
		eval(this.ID + '.expandedHeight = Table' + this.ID + '.offsetHeight');
		eval('document.all[this.ID].style.height = ' + this.ID + '.currentHeight');
	}
	else if (navigator.DOMHTML && navigator.DOMCSS2) {
		
		// need to find a way to determine the actual expanded height
		eval(this.ID + '.expandedHeight = 10 * contractedHeight');
		eval('document.getElementById(this.ID).style.height = ' + this.ID + '.currentHeight');
	}
}

function addMenu()	// menuName, top, left, width, height, menuHeading, (menuItem, menuLink)
{
	var i, args;
	var menuName;
	var top, left, width;
	var menuHeading, menuItem, menuLink;
	
	args = addMenu.arguments;
	
	menuName	= args[0];
	
	top			= args[1];
	left		= args[2];
	width		= args[3];
	height		= args[4];
	
	menuHeading = args[5];
	menuLink	= args[6];

	eval( menuName + '= new drpMenu("' + menuName + '")' );

	if ((navigator.family == 'nn4') ||
			(navigator.family == 'ie4' && navigator.version < ieVer)) {
		document.write('<LAYER ID=Lyr' + menuName + ' Top=' + top + ' Left=' + left + ' Width=' + width + ' Visibility=HIDDEN Z-Index=200 onMouseOver=\"' + menuName + '.expand()\" onMouseOut=\"' + menuName + '.contract()\">\n');
		document.write('<NOLAYER><DIV ID=' + menuName + ' style=\"POSITION: absolute; TOP: ' + top + 'px; LEFT: ' + left + 'px; WIDTH: ' + width + 'px; OVERFLOW: hidden; Z-INDEX: 200\" onMouseOver=\"' + menuName + '.expand()\" onMouseOut=\"' + menuName + '.contract()\"></NOLAYER>\n');
		document.write('<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 ID=Table' + menuName + '>\n');
		document.write('<TR><TD class=solidBack height=' + height + ' valign=middle>\n');
	
			document.write('<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH=100%>\n');
			document.write('<TR>\n');
			document.write('<TD><A href=\"' + menuLink + '\" CLASS=drpMenuHead><B>' + menuHeading + '</B></A></TD>\n');	
			document.write('</TR>\n');
			document.write('</TABLE>\n');
	
		document.write('</TD></TR>\n');
		document.write('<TR><TD class=solidBack>\n');
		document.write('<IMG SRC=\"' + imgRoot + 'images/white.gif\" width=' + width +  ' height=1>');
		document.write('</TD></TR>\n');
		document.write('<TR><TD class=solidBack>\n');
	
		document.write('<TABLE BORDER=0 CELLSPACING=5 CELLPADDING=0>\n');
	
		for (i=7; i<(args.length-1); i+=2) { //with arg doubles (menuItem, menuLink)
	
			menuItem = args[i];
			menuLink = args[i+1];
			document.write('<TR>\n');
			document.write('<TD valign=top><IMG SRC=\"' + imgRoot + imgOff + '\" name=\"' + menuName +  i + '_arrow\" height=12 width=10></TD>\n');		
			document.write('<TD valign=top><A href=\"' + menuLink + '\" class=drpMenuItem onMouseOver=\"imgArrowOn(\'' + menuName +  i + '\')\" onMouseOut=\"imgArrowOff(\'' + menuName +  i + '\')\">' + menuItem + '</A></TD>\n');
			document.write('</TR>\n');
		}	
		document.write('</TABLE>\n');
	
		document.write('</TD></TR>\n');
		document.write('</TABLE>\n');
		document.write('<NOLAYER></DIV></NOLAYER></LAYER>\n');
	}
	else {

		menuDiv = document.createElement("DIV");
		menuDiv.id = menuName;
		menuDiv.setAttribute("onMouseOver", menuName + ".expand()");
		menuDiv.setAttribute("onMouseOut", menuName + ".contract()");
		menuDiv.style.position = "absolute";
		menuDiv.style.left = left + "px";
		menuDiv.style.top = top + "px";
		menuDiv.style.width = width + "px";
		menuDiv.style.overflow = "hidden";

		table1 = document.createElement("TABLE");
		table1.id = "Table" + menuName;
		table1.setAttribute("BORDER", "0");
		table1.setAttribute("CELLSPACING", "0");
		table1.setAttribute("CELLPADDING", "0");
		menuDiv.appendChild(table1);
		
		tr1 = document.createElement("TR");
		table1.appendChild(tr1);
		
		td1 = document.createElement("TD");
		td1.setAttribute("class", "solidBack");
		td1.setAttribute("HEIGHT", height);
		td1.setAttribute("VALIGN", "middle");
		tr1.appendChild(td1);

		table2 = document.createElement("TABLE");
		table2.setAttribute("WIDTH", "100%");
		table2.setAttribute("BORDER", "0");
		table2.setAttribute("CELLSPACING", "0");
		table2.setAttribute("CELLPADDING", "0");
		td1.appendChild(table2);
		
		tr2 = document.createElement("TR");
		table2.appendChild(tr2);
		
		td2 = document.createElement("TD");
		tr2.appendChild(td2);	

		a1 = document.createElement("A");
		a1.setAttribute("class", "drpMenuHead");
		a1.setAttribute("HREF", menuLink);
		td2.appendChild(a1);	

		b1 = document.createElement("B");
		b1.appendChild(document.createTextNode(menuHeading));
		a1.appendChild(b1);		

		tr1 = document.createElement("TR");
		table1.appendChild(tr1);
		
		td1 = document.createElement("TD");
		td1.setAttribute("class", "solidBack");
		tr1.appendChild(td1);

		img1 = document.createElement("IMG");
		img1.setAttribute("SRC", imgRoot + "images/white.gif");
		img1.setAttribute("HEIGHT", "1");
		img1.setAttribute("WIDTH", width);
		td1.appendChild(img1);

		tr1 = document.createElement("TR");
		table1.appendChild(tr1);
		
		td1 = document.createElement("TD");
		td1.setAttribute("class", "solidBack");
		tr1.appendChild(td1);
	
		table2 = document.createElement("TABLE");
		table2.setAttribute("BORDER", "0");
		table2.setAttribute("CELLSPACING", "5");
		table2.setAttribute("CELLPADDING", "0");
		td1.appendChild(table2);
		
	
		for (i=7; i<(args.length-1); i+=2) { //with arg doubles (menuItem, menuLink)

			menuItem = args[i];
			menuLink = args[i+1];
			
			tr2 = document.createElement("TR");
			table2.appendChild(tr2);
		
			td2 = document.createElement("TD");
			td2.setAttribute("VALIGN", "top");
			tr2.appendChild(td2);

			img1 = document.createElement("IMG");
			img1.setAttribute("SRC", imgRoot + imgOff);
			img1.setAttribute("NAME", menuName +  i + "_arrow");
			img1.setAttribute("WIDTH", "10");
			img1.setAttribute("HEIGHT", "12");
			td2.appendChild(img1);		

			td2 = document.createElement("TD");
			td2.setAttribute("VALIGN", "top");
			tr2.appendChild(td2);
			
			a1 = document.createElement("A");
			a1.setAttribute("class", "drpMenuItem");
			a1.setAttribute("HREF", menuLink);		
			a1.setAttribute("onMouseOver", "imgArrowOn('" + menuName +  i + "')");
			a1.setAttribute("onMouseOut", "imgArrowOff('" + menuName +  i + "')");
			a1.appendChild(document.createTextNode(menuItem));
			td2.appendChild(a1);
		}	
		
		document.body.appendChild(menuDiv);	
	}	
	
	eval( menuName + '.set(' + height + ')');
}