// JavaScript include file menusupt.js
// Coded for IE ONLY to reduce size

// *** WITH A SHADOW THAT ACTUALLY WORKS -- DEC. '03 ***

//Initalize
initdoc();
buildMenu();
UpdateIt();

function initdoc()
{
//window.onerror=new Function("return true")
document.body.onclick=hideAll;
document.body.onscroll=hideAll;
document.body.onmousemove=updatexy;
document.write("<body leftmargin=0 topmargin=0>"); //for flush menu

//Write style definition for menu links
document.write("<style>");
document.write(".clsMenuItemIE {text-decoration: none; font: bold 10px Verdana; color: "+forecolour+"; cursor: hand;}");
document.write("A.clsMenuItemIE:hover {color: "+backcolour+"; background-color: "+forecolour+";}");

//hard-edge shadow
//document.write(".shadow {filter:progid:DXImageTransform.Microsoft.dropShadow(OffX=4,OffY=4,Color=#c0c0c0,Positive=true)} ");
//soft-edge shadow
document.write(".shadow {filter:progid:DXImageTransform.Microsoft.Shadow(Color=#a0a0a0,direction=135,strength=5)} ");

document.write("</style>");
}

//Reposition menu
function UpdateIt()
{
document.all["MainTable"].style.top = document.body.scrollTop;
setTimeout("UpdateIt()", 100);
}

//Build menu string
function Menu()
{
//this.bgColor     = "#008080";
this.addItem    = addItem;
this.addSubItem = addSubItem;
this.showMenu   = showMenu;
this.mainPaneBorder = 1;
this.subMenuPaneBorder = 1;
this.subMenuPaneWidth = 155;
this.subMenuShadowWidth = this.subMenuPaneWidth + 5;

lastMenu = null;

rightX = 0;
rightY = 0;
leftY = 0;
leftX = 0;

HTMLstr = "";
HTMLstr += "<!-- MENU PANE DECLARATION BEGINS -->\n";
HTMLstr += "\n";
HTMLstr += "<div id='MainTable' style='position:relative; z-index:100;'>\n";
//HTMLstr += "<table width='100%' bgcolor='"+this.bgColor+"' border='"+this.mainPaneBorder+"'>\n";
HTMLstr += "<table width='100%' bgcolor='"+backcolour+"' border='"+this.mainPaneBorder+"' class=shadow>\n";
HTMLstr += "<tr valign=top style='font-size:10px;'>\n";
HTMLstr += "<!-- MAIN MENU STARTS -->\n";
HTMLstr += "<!-- MAIN_MENU -->\n";
HTMLstr += "<!-- MAIN MENU ENDS -->\n";
HTMLstr += "</tr>\n";
HTMLstr += "</table>\n";
HTMLstr += "\n";
HTMLstr += "<!-- SUB MENU STARTS -->\n";
HTMLstr += "<!-- SUB_MENU -->\n";
HTMLstr += "<!-- SUB MENU ENDS -->\n";
HTMLstr += "\n";
HTMLstr+= "</div>\n";
HTMLstr += "<!-- MENU PANE DECLARATION ENDS -->\n";
}

//Add menu main item
function addItem(idItem, text, hint, location)
{
var Lookup = "<!-- ITEM "+idItem+" -->";
if (HTMLstr.indexOf(Lookup) != -1)
  {
  alert(idParent + " already exists");
  return;
  }
var MENUitem = "";
MENUitem += "\n<!-- ITEM "+idItem+" -->\n";
MENUitem += "<td>\n";
MENUitem += "<div id='"+idItem+"' style='position:relative; z-index:100;'>\n";
MENUitem += "<a ";
MENUitem += "class=clsMenuItemIE ";
if (hint != null) MENUitem += "title='"+hint+"' ";
if (location == null) MENUitem += "href='.' onclick=\"return false;\" "
else MENUitem += "href='"+location+"' ";
MENUitem += "onmouseover=\"displaySubMenu('"+idItem+"')\" ";
MENUitem += "onfocus=this.blur() "; //gets rid of hotspot box
MENUitem += ">";
//MENUitem += "&nbsp;\n"; //puts space before menu item
MENUitem += text;
MENUitem += "</a>\n";
MENUitem += "</div>\n";
MENUitem += "</td>\n";
MENUitem += "<!-- END OF ITEM "+idItem+" -->\n\n";
MENUitem += "<!-- MAIN_MENU -->\n";
HTMLstr = HTMLstr.replace("<!-- MAIN_MENU -->\n", MENUitem);
}

//Add menu sub item
function addSubItem(idParent, text, hint, location)
{
var MENUitem = "";
Lookup = "<!-- ITEM "+idParent+" -->";
if (HTMLstr.indexOf(Lookup) == -1)
  {
  alert(idParent + " not found");
  return;
  }
Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->";
if (HTMLstr.indexOf(Lookup) == -1)
  {
  MENUitem += "\n";
//  MENUitem += "<div id='"+idParent+"submenu' style='position:absolute; visibility: hidden; width: "+this.subMenuPaneWidth+"; font: "+this.menuFont+"; top: -300;'>\n";
  MENUitem += "<div id='"+idParent+"submenu' style='position:absolute; visibility: hidden; width: "+this.subMenuShadowWidth+"; font: "+this.menuFont+"; top: -300;'>\n";
//  MENUitem += "<table border='"+this.subMenuPaneBorder+"' bgcolor='"+backcolour+"' width="+this.subMenuPaneWidth+" class=shadow>\n";
  MENUitem += "<table border='"+this.subMenuPaneBorder+"' bgcolor='"+backcolour+"' width="+this.subMenuPaneWidth+" class=shadow>\n";
  MENUitem += "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
  MENUitem += "</table>\n";
  MENUitem += "</div>\n";
  MENUitem += "\n";
  MENUitem += "<!-- SUB_MENU -->\n";
  HTMLstr = HTMLstr.replace("<!-- SUB_MENU -->\n", MENUitem);
  }
Lookup = "<!-- NEXT ITEM OF SUB MENU "+ idParent +" -->\n";
MENUitem = "<tr><td><a class=clsMenuItemIE title='"+hint+"' href='"+location+"'>"+text+"</a><br></td></tr>\n";
MENUitem += Lookup;
HTMLstr = HTMLstr.replace(Lookup, MENUitem);
}

//Display menu
function showMenu()
{
document.writeln(HTMLstr);
}

//Display submenu
function displaySubMenu(idMainMenu)
{
var menu;
var submenu;
menu = eval(idMainMenu);
if (HTMLstr.indexOf(idMainMenu+"submenu") == -1) return; //bail if no submenu
submenu = eval(idMainMenu+"submenu.style");
submenu.left = calculateSumOffset(menu, 'offsetLeft');
submenu.top  = menu.style.top+25; //adjust for main menu size
submenu.visibility = "visible";
if (lastMenu != null && lastMenu != submenu) hideAll();
leftX  = document.all[idMainMenu+"submenu"].style.posLeft;
rightX = leftX + document.all[idMainMenu+"submenu"].offsetWidth;
leftY  = document.all[idMainMenu+"submenu"].style.posTop+document.all[idMainMenu+"submenu"].offsetHeight;
rightY = leftY;
lastMenu = submenu;
}

//Hide all submenus
function hideAll()
{
if (lastMenu != null) {lastMenu.visibility = "hidden";lastMenu.left = 0;}
}

//Calc offset size
function calculateSumOffset(idItem, offsetName)
{
var totalOffset = 0;
var item = eval('idItem');
do {
    totalOffset += eval('item.'+offsetName);
    item = eval('item.offsetParent');
   } while (item != null);
return totalOffset;
}

//Update mouse position on move
function updatexy(e)
{
var x = window.event.clientX;
var y = window.event.clientY;
if (x > rightX || x < leftX) hideAll();
else if (y > rightY) hideAll();
}

function togglediv (divid) 
{
// turn display style for div on ("") or off ("none")
if (divid.style.display == "") divid.style.display = "none";
else divid.style.display = "";
}
// eof
