//This is        ***        RIGHT  MenuOps        ***

var oRPrimary,oRSecondary,oRTertiary;
var oOpen1, oOpen2;
var oSniffer = new SnifferClass();
if(oSniffer.isIE && oSniffer.version >= 5 && oSniffer.isWin)
{
	var oRPrimaryBG = document.getElementById("RPrimaryBG");
	var oRSecondaryBG = document.getElementById("RSecondaryBG");
	var oRTertiaryBG1 = document.getElementById("RTertiaryBG1");
	var oRTertiaryBG2 = document.getElementById("RTertiaryBG2");
	var oRBull1 = new Image();
	oRBull1.src = "RPrimaryMenu_Bullet.gif";
	var oRBull2 = new Image();
	oRBull2.src = "RSecondaryMenu_Bullet.gif";
	var oRBull3 = new Image();
	oRBull3.src = "RTertiaryMenu_Bullet.gif";
	var oRArrow1 = new Image();
	oRArrow1.src = "RPrimaryMenu_Arrow.gif";
	var oRArrow2 = new Image();
	oRArrow2.src = "RSecondaryMenu_Arrow.gif";
	var oDot = new Image();
	oDot.src = "menudot.gif";
}

var nRMaxRows = 9
var oRSTable1, oRSTable2, oRTTable1, oRTTable2;


function EngageRMenus()
{
                //alert("EngageRMenus");
	 document.getElementById("iRHotSpot").releaseCapture();
               document.getElementById("iRPopsideMenus").style.display = "block";
               document.getElementById("iRPopsideMenus").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";
		document.getElementById("iRPopsideMenus").style.display = "none";


               }
}


function RLink(oRow)
{
	var oSniffer = new SnifferClass();
	if(oSniffer.isIE)
		if(oRow.target)
		{
			var oNew = window.open(oRow.href)
		} else {
			window.location = oRow.href;
		}
	
}


function InactiveRMenuState()
{
	
	var oSniffer = new SnifferClass();
	if((oSniffer.isIE && oSniffer.version < 5) || !oSniffer.isWin || !oSniffer.isIE)
		return;
	//alert("InactiveRMenuState");
	var oTemp = event.toElement
	while(oTemp != null && oTemp != document.body && oTemp != document.getElementById("RItemsDiv") && oTemp.parentElement)
		oTemp = oTemp.parentElement

	if(oTemp == document.body || oTemp == null)
	{
		document.getElementById("RPrimaryBG").style.display = "none";
		document.getElementById("RSecondaryBG").style.display = "none";
		document.getElementById("RTertiaryBG1").style.display = "none";
		document.getElementById("RTertiaryBG2").style.display = "none";

		var oRSecondarySpacer = document.getElementById("RSecondarySpacer");
		oRSecondarySpacer.width = nSecondarySpWidth;
		nSecondarySpWidth = -1;
		
		
		if(oRPrimary != null) 
		{
			oRPrimary.cells[1].firstChild.src = oDot.src;
			oRPrimary.cells[1].lastChild.style.fontWeight = "";
			oRPrimary.cells[1].lastChild.style.textDecoration = "none";
			oRPrimary.className = "";
			oRPrimary.style.backgroundColor = ""
			oRPrimary = null
		}
		
		if(oRSecondary != null) 
		{
			oRSecondary.cells[1].firstChild.src = oDot.src;
			oRSecondary.cells[1].lastChild.style.fontWeight = "";
			oRSecondary.cells[1].lastChild.style.textDecoration = "none";
			oRSecondary.className = "";
			oRSecondary.style.backgroundColor = ""
			if(oRSecondary.Highlight) {
				var sTemp = oRSecondary.cells[1].lastChild.innerText
				oRSecondary.cells[1].lastChild.innerText = oRSecondary.Highlight;
				oRSecondary.Highlight = sTemp;
			}
			oRSecondary = null
		}
		
		if(oRTertiary != null) 
		{
			oRTertiary.cells[1].firstChild.src = oDot.src;
			oRTertiary.cells[1].lastChild.style.fontWeight = "";
			oRTertiary.cells[1].lastChild.style.textDecoration = "none";
			oRTertiary.className = "";
			oRTertiary.style.backgroundColor = "";
			if(oRTertiary.Highlight) {
				var sTemp = oRTertiary.cells[1].lastChild.innerText
				oRTertiary.cells[1].lastChild.innerText = oRTertiary.Highlight;
				oRTertiary.Highlight = sTemp;
			}
			oRTertiary = null
		}
		

		var SC = document.getElementById("RSecondaryContainer");
		var TC = document.getElementById("RTertiaryContainer");
		
		if(oRSTable1 != null)
		{
			SC.removeChild(oRSTable1);
			oRSTable1 = null;
		}
		if(oRSTable2 != null)
		{
			SC.removeChild(oRSTable2);
			oRSTable2 = null;
		}
		if(oRTTable1 != null) 
		{
			TC.removeChild(oRTTable1);
			oRTTable1 = null;
		}
		if(oRTTable2 != null)
		{
			TC.removeChild(oRTTable2);
			oRTTable2 = null;
		}

		alert("Completing Flush via InactiveRMenuState.\n\nSC Children = "+oRSecondaryContainer.children.length);

	}

	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("iRPopsideMenus").style.display = "none";
               }


}


var nSecondarySpWidth = -1;

function RExpand(oRow,nLevel,nIndex)
{
	
	var oSniffer = new SnifferClass();
	if((oSniffer.isIE && oSniffer.version < 5) || !oSniffer.isWin || !oSniffer.isIE)
		return;
	//alert("RExpand");

	oRow.setCapture();
	
	var oRSecondaryContainer = document.getElementById("RSecondaryContainer")
	var oRTertiaryContainer = document.getElementById("RTertiaryContainer")
	
	var oRSecondarySpacer = document.getElementById("RSecondarySpacer");
	if(nSecondarySpWidth == -1)
		nSecondarySpWidth = oRSecondarySpacer.width;
	switch(nLevel)
	{
		case 1:
			//alert("case 1");

			if(oRPrimary != null) 
			{
				oRPrimary.cells[1].firstChild.src = oDot.src;
				oRPrimary.cells[1].lastChild.style.fontWeight = "";
				oRPrimary.cells[1].lastChild.style.textDecoration = "none";
				oRPrimary.className = "";
				oRPrimary.style.backgroundColor = ""
			}
			
			document.getElementById("RSecondaryBG").style.display = "block";
			document.getElementById("RSecondaryBG").style.visibility = "visible";
			document.getElementById("RPrimaryBG").style.display = "none";
			document.getElementById("RTertiaryBG1").style.display = "none";
			document.getElementById("RTertiaryBG2").style.display = "none";
			
			if(oRSTable1 != null)
			{
				ResetTable(oRSTable1);
				oRSecondaryContainer.removeChild(oRSTable1);
				oRSTable1 = null;
			}
			if(oRSTable2 != null)
			{
				ResetTable(oRSTable2);
				oRSecondaryContainer.removeChild(oRSTable2);
				oRSTable2 = null;
			}
			if(oRTTable1 != null)
			{
				ResetTable(oRTTable1);
				oRTertiaryContainer.removeChild(oRTTable1);
				oRTTable1 = null;
			}
			if(oRTTable2 != null)
			{
				ResetTable(oRTTable2);
				oRTertiaryContainer.removeChild(oRTTable2);
				oRTTable2 = null;
			}


			var aNextIndexes = oRMenu[nIndex][2].split("|");


			if(oRMenu[nIndex][6])
			{
				oRSTable1 = oRMenu[nIndex][6];
			} else {

				oRSTable1 = buildRTable(aNextIndexes,2,1);
				oRMenu[nIndex][6] = oRSTable1;
			}

			oRSecondaryContainer.appendChild(oRSTable1);


			if(oRMenu[nIndex][7])
			{
				oRSTable2 = oRMenu[nIndex][7];
				oRSecondaryContainer.appendChild(oRSTable2);
			} else {
				if(aNextIndexes.length > (nRMaxRows + 1)) 
				{
					oRSTable2 = buildRTable(aNextIndexes,2,2);
					oRSecondaryContainer.appendChild(oRSTable2);
					oRMenu[nIndex][7] = oRSTable2;
				}
			}   

			
			oRow.cells[1].firstChild.src = oRBull1.src;
			oRow.cells[1].lastChild.style.fontWeight = "bold";
			oRow.cells[1].lastChild.style.textDecoration = "underline";
			oRow.style.backgroundColor = "#730000"
	
			oRPrimary = oRow;
			
			break;
		case 2:
			//alert("case2");

			if(oRSecondary != null)
			{
				oRSecondary.cells[1].firstChild.src = oDot.src;
				oRSecondary.cells[1].lastChild.style.fontWeight = "normal";
				oRSecondary.className = "";
				oRSecondary.style.backgroundColor = ""
				oRSecondary.cells[1].lastChild.style.textDecoration = "none";
				
				if(oRSecondary.Highlight)
				{
					var sTemp = oRSecondary.cells[1].lastChild.innerText
					oRSecondary.cells[1].lastChild.innerText = oRSecondary.Highlight;
					oRSecondary.Highlight = sTemp;
				}
			}

			var aNextIndexes = oRMenu[nIndex][2].split("|");
			
			if(oRPrimary != null) 
			{		
				oRPrimary.cells[1].firstChild.src = oRArrow1.src;
				oRPrimary.cells[1].lastChild.style.textDecoration = "none";
			}
			
			
			oRow.cells[1].firstChild.src = oRBull2.src;
			oRow.cells[1].lastChild.style.fontWeight = "bold";
			oRow.cells[1].lastChild.style.textDecoration = "underline";
			oRow.style.backgroundColor = "#680000"
			
			if(oRow.Highlight || oRMenu[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 = oRMenu[nIndex][3];
				oRow.Highlight = sTemp;
			}

			if(oRTTable1 != null)
			{
				ResetTable(oRTTable1);
				oRTertiaryContainer.removeChild(oRTTable1);
				oRTTable1 = null;
			}
			if(oRTTable2 != null)
			{
				ResetTable(oRTTable2);
				oRTertiaryContainer.removeChild(oRTTable2);
				oRTTable2 = null;
			}
			
			if(oRMenu[nIndex][2] != "") 
			{
				
				if(oRSecondaryContainer.children.length == 1)
                                                        {
					oRSecondarySpacer.width = 151;
					document.getElementById("RTertiaryBG1").style.display = "block";
					document.getElementById("RTertiaryBG1").style.visibility = "visible";
					document.getElementById("RTertiaryBG2").style.display = "none";
				}
				
				if(oRSecondaryContainer.children.length == 2)
				{
					oRSecondarySpacer.width = 303;
					document.getElementById("RTertiaryBG2").style.display = "block";
					document.getElementById("RTertiaryBG2").style.visibility = "visible";
					document.getElementById("RTertiaryBG1").style.display = "none";
				}

				//alert(oRSecondaryContainer.children.length)

				if(oRMenu[nIndex][6])
				{
					oRTTable1 = oRMenu[nIndex][6];
				} else {
					oRTTable1 = buildRTable(aNextIndexes,3,1);
					oRMenu[nIndex][6] = oRTTable1;
				}
				if(oRTTable1 != null)
					oRTertiaryContainer.appendChild(oRTTable1);
			
				if(oRMenu[nIndex][7])
				{
					oRTTable2 = oRMenu[nIndex][7];
					oRTertiaryContainer.appendChild(oRTTable2);
				} else {
					if(aNextIndexes.length > (nRMaxRows + 1)) 
					{
						oRTTable2 = buildRTable(aNextIndexes,3,2);
						oRTertiaryContainer.appendChild(oRTTable2);
						oRMenu[nIndex][7] = oRTTable2;
					}
				}
				
				
				document.getElementById("RPrimaryBG").style.display = "none";
				document.getElementById("RSecondaryBG").style.display = "none";
			} else {

				document.getElementById("RSecondaryBG").style.display = "block";
				document.getElementById("RSecondaryBG").style.visibility = "visible";
				document.getElementById("RPrimaryBG").style.display = "none";
				document.getElementById("RTertiaryBG1").style.display = "none";
				document.getElementById("RTertiaryBG2").style.display = "none";				
			}
				oRSecondary = oRow;
			break;
		case 3:
			//alert("case3");
			if(oRTertiary != null)
			{
				oRTertiary.cells[1].firstChild.src = oDot.src;
				oRTertiary.cells[1].lastChild.style.fontWeight = "normal";
				oRTertiary.className = "";
				oRTertiary.style.backgroundColor = ""
				oRTertiary.cells[1].lastChild.style.textDecoration = "none";
				
				if(oRTertiary.Highlight)
				{
					var sTemp = oRTertiary.cells[1].lastChild.innerText
					oRTertiary.cells[1].lastChild.innerText = oRTertiary.Highlight;
					oRTertiary.Highlight = sTemp;
				}
			}
			
			
			if(oRSecondary) { 
				oRSecondary.cells[1].firstChild.src = oRArrow2.src;
				oRSecondary.cells[1].lastChild.style.textDecoration = "none";
			}
			
			oRow.cells[1].firstChild.src = oRBull3.src;
			oRow.cells[1].lastChild.style.fontWeight = "bold";
			oRow.cells[1].lastChild.style.textDecoration = "underline";
			oRow.style.backgroundColor = "#5C0000"
			
			if(oRow.Highlight || oRMenu[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 = oRMenu[nIndex][3];
				oRow.Highlight = sTemp;
			}
			
			oRTertiary = oRow;
			break
	}
}

function buildRTable(aItems,nLevel,nCol)
{
	var oTable = document.createElement("Table");
	oTable.align = "left";
	oTable.cellSpacing = 0;
	oTable.cellPadding = 0;
	oTable.border = 0;
	var oRow 
	var i

	//alert("aItems,nLevel,nCol = "+ aItems+" "+nLevel+" "+nCol);

	if(nCol == 2)
	{
		i = nRMaxRows;
		nEnd = aItems.length;
		//alert("nCol is 2.  nEnd = "+nEnd);
	} else {
		i = 0;
		if(aItems.length > nRMaxRows)
			nEnd = nRMaxRows;
		else
			nEnd = aItems.length;
		//alert("nCol, nEnd = "+nCol+"  "+nEnd);
	}

	//alert("i, nEnd = "+i+" "+nEnd);
	//alert("aItems[i] = >"+aItems[i]+"<");


	while(i < nEnd && aItems[i] != "")
	{
	//alert("made it into While");		

		oRow = oTable.insertRow();
		oRow.href = oRMenu[aItems[i]][1]
		if(oRMenu[aItems[i]][5] != "")
			oRow.target = oRMenu[aItems[i]][5]

		if(oRMenu[aItems[i]][3]) 
		{
			oRow.Highlight = oRMenu[aItems[i]][3]
		}

		oRow.onmouseover = new Function("RExpand(this," + nLevel +"," + aItems[i] + ")")
		oRow.onmouseout = new Function("RContract(this," + nLevel +"," + aItems[i] + ")")
		oRow.onclick = new Function("RLink(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='" + oRMenu[aItems[i]][1] + "'class='rmenutext' >" + oRMenu[aItems[i]][0] + "</a>";
		
		++i;

	}

	//alert("Completed While:")
	//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 RContract(oRow)
{	
	var oSniffer = new SnifferClass();
	if((oSniffer.isIE && oSniffer.version < 5) || !oSniffer.isWin || !oSniffer.isIE)
		return;
	oRow.releaseCapture();	
}


