//This is        ***        MenuOps        ***

var oPrimary,oSecondary,oTertiary;
var oOpen1, oOpen2;
var oSniffer = new SnifferClass();
if(oSniffer.isIE && oSniffer.version >= 5 && oSniffer.isWin)
{
	var oPrimaryBG = document.getElementById("PrimaryBG");
	var oSecondaryBG = document.getElementById("SecondaryBG");
	var oTertiaryBG1 = document.getElementById("TertiaryBG1");
	var oTertiaryBG2 = document.getElementById("TertiaryBG2");
	var oBull1 = new Image();
	oBull1.src = "PrimaryMenu_Bullet.gif";
	var oBull2 = new Image();
	oBull2.src = "SecondaryMenu_Bullet.gif";
	var oBull3 = new Image();
	oBull3.src = "TertiaryMenu_Bullet.gif";
	var oArrow1 = new Image();
	oArrow1.src = "PrimaryMenu_Arrow.gif";
	var oArrow2 = new Image();
	oArrow2.src = "SecondaryMenu_Arrow.gif";
	var oDot = new Image();
	oDot.src = "menudot.gif";
}

var nMaxRows = 9
var oSTable1, oSTable2, oTTable1, oTTable2;

function EngageMenus()
{
               //alert("EngageMenus");
	 document.getElementById("iHotSpot").releaseCapture();
               document.getElementById("iPopsideMenus").style.display = "block";
               document.getElementById("iPopsideMenus").style.visibility = "visible";
               document.getElementById("iMagazine").style.display = "none";
}

function RestorePage()
{
	var nMouseY = event.y;
	if((nMouseY > 135) || (nMouseY < 10))
               {

		//alert(nMouseY);
		document.getElementById("iMagazine").style.display = "block";
		document.getElementById("iMagazine").style.visibility = "visible";
		document.getElementById("iPopsideMenus").style.display = "none";

		

               }
}


function Link(oRow)
{
	var oSniffer = new SnifferClass();
	if(oSniffer.isIE)
		if(oRow.target)
		{
			var oNew = window.open(oRow.href)
		} else {
			window.location = oRow.href;
		}
	
}


function InactiveMenuState()
{
	
	var oSniffer = new SnifferClass();
	if((oSniffer.isIE && oSniffer.version < 5) || !oSniffer.isWin || !oSniffer.isIE)
		return;
	//alert("InactiveMenuState");
	var oTemp = event.toElement
	while(oTemp != null && oTemp != document.body && oTemp != document.getElementById("ItemsDiv") && oTemp.parentElement)
		oTemp = oTemp.parentElement

	if(oTemp == document.body || oTemp == null)
	{

		document.getElementById("PrimaryBG").style.display = "none";
		document.getElementById("SecondaryBG").style.display = "none";
		document.getElementById("TertiaryBG1").style.display = "none";
		document.getElementById("TertiaryBG2").style.display = "none";

		var oSecondarySpacer = document.getElementById("SecondarySpacer");
		oSecondarySpacer.width = nSecondarySpWidth;
		nSecondarySpWidth = -1;
		
		
		if(oPrimary != null) 
		{
			oPrimary.cells[1].firstChild.src = oDot.src;
			oPrimary.cells[1].lastChild.style.fontWeight = "";
			oPrimary.cells[1].lastChild.style.textDecoration = "none";
			oPrimary.className = "";
			oPrimary.style.backgroundColor = ""
			oPrimary = null
		}
		
		if(oSecondary != null) 
		{
			oSecondary.cells[1].firstChild.src = oDot.src;
			oSecondary.cells[1].lastChild.style.fontWeight = "";
			oSecondary.cells[1].lastChild.style.textDecoration = "none";
			oSecondary.className = "";
			oSecondary.style.backgroundColor = ""
			if(oSecondary.Highlight) {
				var sTemp = oSecondary.cells[1].lastChild.innerText
				oSecondary.cells[1].lastChild.innerText = oSecondary.Highlight;
				oSecondary.Highlight = sTemp;
			}
			oSecondary = null
		}
		
		if(oTertiary != null) 
		{
			oTertiary.cells[1].firstChild.src = oDot.src;
			oTertiary.cells[1].lastChild.style.fontWeight = "";
			oTertiary.cells[1].lastChild.style.textDecoration = "none";
			oTertiary.className = "";
			oTertiary.style.backgroundColor = "";
			if(oTertiary.Highlight) {
				var sTemp = oTertiary.cells[1].lastChild.innerText
				oTertiary.cells[1].lastChild.innerText = oTertiary.Highlight;
				oTertiary.Highlight = sTemp;
			}
			oTertiary = null
		}
		

		var SC = document.getElementById("SecondaryContainer");
		var TC = document.getElementById("TertiaryContainer");
		
		if(oSTable1 != null)
		{
			SC.removeChild(oSTable1);
			oSTable1 = null;
		}
		if(oSTable2 != null)
		{
			SC.removeChild(oSTable2);
			oSTable2 = null;
		}
		if(oTTable1 != null) 
		{
			TC.removeChild(oTTable1);
			oTTable1 = null;
		}
		if(oTTable2 != null)
		{
			TC.removeChild(oTTable2);
			oTTable2 = null;
		}
		
	}

	var nMouseY = event.y;
               if((nMouseY > 135) || (nMouseY < 10))
               {
		//alert(nMouseY);
		document.getElementById("iMagazine").style.display = "block";
		document.getElementById("iMagazine").style.visibility = "visible";
		document.getElementById("iPopsideMenus").style.display = "none";
               }

}


var nSecondarySpWidth = -1;

function Expand(oRow,nLevel,nIndex)
{
	
	var oSniffer = new SnifferClass();
	if((oSniffer.isIE && oSniffer.version < 5) || !oSniffer.isWin || !oSniffer.isIE)
		return;
	//alert("Expand");

	oRow.setCapture();
	
	var oSecondaryContainer = document.getElementById("SecondaryContainer")
	var oTertiaryContainer = document.getElementById("TertiaryContainer")
	
	var oSecondarySpacer = document.getElementById("SecondarySpacer");
	if(nSecondarySpWidth == -1)
		nSecondarySpWidth = oSecondarySpacer.width;
	switch(nLevel)
	{
		case 1:
			//alert("case 1:");
			if(oPrimary != null) 
			{
				oPrimary.cells[1].firstChild.src = oDot.src;
				oPrimary.cells[1].lastChild.style.fontWeight = "";
				oPrimary.cells[1].lastChild.style.textDecoration = "none";
				oPrimary.className = "";
				oPrimary.style.backgroundColor = ""
			}
			
			document.getElementById("SecondaryBG").style.display = "block";
			document.getElementById("SecondaryBG").style.visibility = "visible";
			document.getElementById("PrimaryBG").style.display = "none";
			document.getElementById("TertiaryBG1").style.display = "none";
			document.getElementById("TertiaryBG2").style.display = "none";
			
			if(oSTable1 != null)
			{
				ResetTable(oSTable1);
				oSecondaryContainer.removeChild(oSTable1);
				oSTable1 = null;
			}
			if(oSTable2 != null)
			{
				ResetTable(oSTable2);
				oSecondaryContainer.removeChild(oSTable2);
				oSTable2 = null;
			}
			if(oTTable1 != null)
			{
				ResetTable(oTTable1);
				oTertiaryContainer.removeChild(oTTable1);
				oTTable1 = null;
			}
			if(oTTable2 != null)
			{
				ResetTable(oTTable2);
				oTertiaryContainer.removeChild(oTTable2);
				oTTable2 = null;
			}
			var aNextIndexes = oMenu[nIndex][2].split("|");
			
			if(oMenu[nIndex][6])
			{
				oSTable1 = oMenu[nIndex][6];
			} else {
				oSTable1 = buildTable(aNextIndexes,2,1);
				oMenu[nIndex][6] = oSTable1;
			}
			oSecondaryContainer.appendChild(oSTable1);
			
			if(oMenu[nIndex][7])
			{
				oSTable2 = oMenu[nIndex][7];
				oSecondaryContainer.appendChild(oSTable2);
			} else {
				if(aNextIndexes.length > (nMaxRows + 1)) 
				{
					oSTable2 = buildTable(aNextIndexes,2,2);
					oSecondaryContainer.appendChild(oSTable2);
					oMenu[nIndex][7] = oSTable2;
				}
			}
			
			oRow.cells[1].firstChild.src = oBull1.src;
			oRow.cells[1].lastChild.style.fontWeight = "bold";
			oRow.cells[1].lastChild.style.textDecoration = "underline";
			oRow.style.backgroundColor = "#730000"
	
			oPrimary = oRow;
			
			break;
		case 2:
			//alert("case2:");
			if(oSecondary != null)
			{
				oSecondary.cells[1].firstChild.src = oDot.src;
				oSecondary.cells[1].lastChild.style.fontWeight = "normal";
				oSecondary.className = "";
				oSecondary.style.backgroundColor = ""
				oSecondary.cells[1].lastChild.style.textDecoration = "none";
				
				if(oSecondary.Highlight)
				{
					var sTemp = oSecondary.cells[1].lastChild.innerText
					oSecondary.cells[1].lastChild.innerText = oSecondary.Highlight;
					oSecondary.Highlight = sTemp;
				}
			}

			var aNextIndexes = oMenu[nIndex][2].split("|");
			
			if(oPrimary != null) 
			{		
				oPrimary.cells[1].firstChild.src = oArrow1.src;
				oPrimary.cells[1].lastChild.style.textDecoration = "none";
			}
			
			
			oRow.cells[1].firstChild.src = oBull2.src;
			oRow.cells[1].lastChild.style.fontWeight = "bold";
			oRow.cells[1].lastChild.style.textDecoration = "underline";
			oRow.style.backgroundColor = "#680000"
			
			if(oRow.Highlight || oMenu[nIndex][3]) 
			{
				var sTemp = oRow.cells[1].lastChild.innerText
				if(oRow.Highlight)
					oRow.cells[1].lastChild.innerText = oRow.Highlight;
				else
					oRow.cells[1].lastChild.innerText = oMenu[nIndex][3];
				oRow.Highlight = sTemp;
			}

			if(oTTable1 != null)
			{
				ResetTable(oTTable1);
				oTertiaryContainer.removeChild(oTTable1);
				oTTable1 = null;
			}
			if(oTTable2 != null)
			{
				ResetTable(oTTable2);
				oTertiaryContainer.removeChild(oTTable2);
				oTTable2 = null;
			}
			
			if(oMenu[nIndex][2] != "") 
			{
				
				if(oSecondaryContainer.children.length == 1)
                                                        {
					oSecondarySpacer.width = 151;
					document.getElementById("TertiaryBG1").style.display = "block";
					document.getElementById("TertiaryBG1").style.visibility = "visible";
					document.getElementById("TertiaryBG2").style.display = "none";
				}
				
				if(oSecondaryContainer.children.length == 2)
				{
					oSecondarySpacer.width = 303;
					document.getElementById("TertiaryBG2").style.display = "block";
					document.getElementById("TertiaryBG2").style.visibility = "visible";
					document.getElementById("TertiaryBG1").style.display = "none";
				}

				//alert(oSecondaryContainer.children.length)

				if(oMenu[nIndex][6])
				{
					oTTable1 = oMenu[nIndex][6];
				} else {
					oTTable1 = buildTable(aNextIndexes,3,1);
					oMenu[nIndex][6] = oTTable1;
				}
				if(oTTable1 != null)
					oTertiaryContainer.appendChild(oTTable1);
			
				if(oMenu[nIndex][7])
				{
					oTTable2 = oMenu[nIndex][7];
					oTertiaryContainer.appendChild(oTTable2);
				} else {
					if(aNextIndexes.length > (nMaxRows + 1)) 
					{
						oTTable2 = buildTable(aNextIndexes,3,2);
						oTertiaryContainer.appendChild(oTTable2);
						oMenu[nIndex][7] = oTTable2;
					}
				}
				
				
				
				document.getElementById("PrimaryBG").style.display = "none";
				document.getElementById("SecondaryBG").style.display = "none";
			} else {

				document.getElementById("SecondaryBG").style.display = "block";
				document.getElementById("SecondaryBG").style.visibility = "visible";
				document.getElementById("PrimaryBG").style.display = "none";
				document.getElementById("TertiaryBG1").style.display = "none";
				document.getElementById("TertiaryBG2").style.display = "none";				
			}
				oSecondary = oRow;
			break;
		case 3:
			//alert("case3:");
			if(oTertiary != null)
			{
				oTertiary.cells[1].firstChild.src = oDot.src;
				oTertiary.cells[1].lastChild.style.fontWeight = "normal";
				oTertiary.className = "";
				oTertiary.style.backgroundColor = ""
				oTertiary.cells[1].lastChild.style.textDecoration = "none";
				
				if(oTertiary.Highlight)
				{
					var sTemp = oTertiary.cells[1].lastChild.innerText
					oTertiary.cells[1].lastChild.innerText = oTertiary.Highlight;
					oTertiary.Highlight = sTemp;
				}
			}
			
			
			if(oSecondary) { 
				oSecondary.cells[1].firstChild.src = oArrow2.src;
				oSecondary.cells[1].lastChild.style.textDecoration = "none";
			}
			
			oRow.cells[1].firstChild.src = oBull3.src;
			oRow.cells[1].lastChild.style.fontWeight = "bold";
			oRow.cells[1].lastChild.style.textDecoration = "underline";
			oRow.style.backgroundColor = "#5C0000"
			
			if(oRow.Highlight || oMenu[nIndex][3]) 
			{
				var sTemp = oRow.cells[1].lastChild.innerText
				if(oRow.Highlight)
					oRow.cells[1].lastChild.innerText = oRow.Highlight;
				else
					oRow.cells[1].lastChild.innerText = oMenu[nIndex][3];
				oRow.Highlight = sTemp;
			}
			
			oTertiary = oRow;
			break
	}
}

function buildTable(aItems,nLevel,nCol)
{
	var oTable = document.createElement("Table");
	oTable.align = "left";
	oTable.cellSpacing = 0;
	oTable.cellPadding = 0;
	oTable.border = 0;
	var oRow 
	var i
	if(nCol == 2)
	{
		i = nMaxRows;
		nEnd = aItems.length;
	} else {
		i = 0;
		if(aItems.length > nMaxRows)
			nEnd = nMaxRows;
		else
			nEnd = aItems.length;
	}
	while(i < nEnd && aItems[i] != "")
	{
		
		oRow = oTable.insertRow();
		oRow.href = oMenu[aItems[i]][1]
		if(oMenu[aItems[i]][5] != "")
			oRow.target = oMenu[aItems[i]][5]

		if(oMenu[aItems[i]][3]) 
		{
			oRow.Highlight = oMenu[aItems[i]][3]
		}

		oRow.onmouseover = new Function("Expand(this," + nLevel +"," + aItems[i] + ")")
		oRow.onmouseout = new Function("Contract(this," + nLevel +"," + aItems[i] + ")")
		oRow.onclick = new Function("Link(this)");

		oCell = oRow.insertCell()
		oCell.width = 10;
		oCell.appendChild(newDot(1,10));

		oCell = oRow.insertCell()
		oCell.width = 141;
		oCell.valign = "top";
		oCell.appendChild(newDot(7,10));
			
		oCell.innerHTML += "<a href='" + oMenu[aItems[i]][1] + "'class='menutext' >" + oMenu[aItems[i]][0] + "</a>";
		
		++i;
	}
	//alert(oTable.innerHTML);
	return oTable;
}	

function newDot(nH, nW)
	{
		var oI = document.createElement("IMG")
		oI.src = oDot.src;
		oI.width = nW;
		oI.height = nH;
	
		return oI;
	
	}

function ResetTable(oT)
{
	var oCell;
	for(var i = 0; i < oT.rows.length;i++)
	{
		oCell = oT.rows[i].cells[1];
		oCell.firstChild.src = oDot.src;
		oCell.lastChild.style.fontWeight = "";
		oCell.lastChild.style.textDecoration = "none";
		oT.rows[i].className = "";
		oT.rows[i].style.backgroundColor = ""
	}
}



function Contract(oRow)
{	
	var oSniffer = new SnifferClass();
	if((oSniffer.isIE && oSniffer.version < 5) || !oSniffer.isWin || !oSniffer.isIE)
		return;
	oRow.releaseCapture();	
}



