var curMenu = 1;
var menu;
var menu2;
var menu3;
var pnav_count = 0;
var curI = -1;
var curJ = 1;
var maxitems = 9; //adjust this to allow for more nav items
var navcount = 0;
var selpipe1 = -1;
var selpipe2 = -1;

/*
	Override standard menu buildout in this file with functions for NYCO deployment 
*/

function addNewMenu(name, curImage, overImage)
{
//	alert(name)

 	menu = ms.addMenu(document.getElementById(name));
/*menu.addItem("testing3", "blah.jsp");
	menu.addItem("testing2", "blah.jsp");*/
	menu.onactivate = function() { changeImages(name, overImage) };
	menu.ondeactivate = function() { changeImages(name, curImage) };	
}

function addNewMenuOff(name, curImage, overImage)
{
//	alert(name)

 	menu = ms.addMenu(document.getElementById(name));

}

function addSub(name, url,sel)
{
	menu.addItem(name, url,sel);
}

function addSub2(name, url, i, j, sel)
{
	i = i -1;
	if (curI != i || curJ != j)
	{
		//alert("New Menu#: " + i + ", " + j);
		// have to create new submenu
		menu2 = menu.addMenu(menu.items[i],sel);
		curI = i;
		curJ = j;

	}
	menu2.addItem(name, url,sel);
}
	// set up drop downs anywhere in the body of the page. I think the bottom of the page is better.. 
	// but you can experiment with effect on loadtime.
	if (mtDropDown.isSupported()) {


		var ms = new mtDropDownSet(mtDropDown.direction.down, 0, 0, mtDropDown.reference.bottomLeft);

		
	}
	
function pipeSwap(strID,ident,state)
{
	if (state ==1) //on
	{
		strID.height = 30;
	}
	else //off
	{
		if ((ident != selpipe1) && (ident != selpipe2))
			strID.height = 10;
	}
}

function addPrimaryNav(strname,strlink,sel)
{
	navcount = navcount + 1;
	var prevpipe = navcount - 1;
	var strClass = '';
	var pipeheight = '10';
	var onMouseover = 'pipeSwap(pipe' + navcount + ',' + navcount + ',1);this.className=\'PrimaryNavTDOver\';pnav_' + navcount + '.className=\'PrimaryNavLinkOver\';';
	var onMouseout = 'pipeSwap(pipe' + navcount + ',' + navcount + ',0);this.className=\'PrimaryNavTD' + strClass + '\';pnav_' + navcount + '.className=\'PrimaryNavLink\';';
	var strHREF = '<a href="' + strlink + '" id="pnav_' + navcount + '">' + strname + '</a>';
	
	if (sel == 1)
	{
		strClass = 'Over';
		onMouseover = '';
		onMouseout = '';
		pipeheight = '30';
	}
			
	if (navcount <= maxitems)
	{
		if (navcount == 1) //first item
		{
			document.write('<td onmouseover="' + onMouseover + '" onmouseout="' + onMouseout + '" valign="middle" height="30" class="PrimaryNavTD' + strClass + '">' + strHREF + '</td>');
			if (sel == 1)
			{
				selpipe1 = navcount;
				selpipe2 = navcount;
			}
		}
		else if((navcount==pnav_count) || (navcount==maxitems)) //last item
		{
			onMouseover = 'pipe' + navcount + '.src=\'/images/' + pageFolder + '_pipe.gif\';pipeSwap(pipe' + prevpipe + ',' + prevpipe + ',1);pipeSwap(pipe' + navcount + ',' + navcount + ',1); this.className=\'PrimaryNavTDOver\';pnav_' + navcount + '.className=\'PrimaryNavLinkOver\';';
			onMouseout = 'pipe' + navcount + '.src=\'/images/transpix.gif\';pipeSwap(pipe' + prevpipe + ',' + prevpipe + ',0);this.className=\'PrimaryNavTD\';pnav_' + navcount + '.className=\'PrimaryNavLink\';';
			if (sel == 1) 
			{
				onMouseover = '';
				onMouseout = '';
				selpipe1 = prevpipe;
				selpipe2 = navcount;
				document.getElementById('pipe' + prevpipe).height = 30;
			}
			
			document.write('<td onmouseover="' + onMouseover + '" onmouseout="' + onMouseout + '" valign="middle" height="30" class="PrimaryNavTD' + strClass + '">' + strHREF + '</td>');
		}
		else //all other items
		{
			onMouseover = 'pipeSwap(pipe' + navcount + ',' + navcount + ',1);pipeSwap(pipe' + prevpipe + ',' + prevpipe + ',1); this.className=\'PrimaryNavTDOver\';pnav_' + navcount + '.className=\'PrimaryNavLinkOver\';';
			onMouseout = 'pipeSwap(pipe' + navcount + ',' + navcount + ',0); pipeSwap(pipe' + prevpipe + ',' + prevpipe + ',0); this.className=\'PrimaryNavTD\';pnav_' + navcount + '.className=\'PrimaryNavLink\';';
			if (sel == 1) 
			{	
				onMouseover = '';
				onMouseout = '';
				selpipe1 = prevpipe;
				selpipe2 = navcount;
				document.getElementById('pipe' + prevpipe).height = 30;
			}
			document.write('<td onmouseover="' + onMouseover + '" onmouseout="' + onMouseout + '" valign="middle" height="30" class="PrimaryNavTD' + strClass + '">' + strHREF + '</td>');
		}
		
		if ((navcount < pnav_count) && (navcount < maxitems))
		{
			document.write('<td style="width: 2px;"><img id="pipe' + navcount + '" src="/images/' + pageFolder + '_pipe.gif" width="2" height="' + pipeheight + '" ></td>');
		}
		else if ((navcount==pnav_count) || (navcount==maxitems))
		{
			if (sel==1)
				document.write('<td style="width: 2px;"><img id="pipe' + navcount + '" src="/images/' + pageFolder + '_pipe.gif" width="2" height="' + pipeheight + '" ></td>');
			else
				document.write('<td style="width: 2px;"><img id="pipe' + navcount + '" src="/images/transpix.gif" width="2" height="' + pipeheight + '" ></td>');
			
		}
	}
}

