// these are used for determining browser information
var isVisible = "visible"
var isHidden  = "hidden"
var isNN4     = false
var isNN      = false
var isIE      = false
var isOpera   = false
var isMac     = false
var isWin     = false
var isUnix    = false
var isInit    = true
var isNN6     = false
var CURSOR_WIDTH 
var CURSOR_HEIGHT

/////////////////////////////////////////////////////////////////////////////////////////
//
//			Menu Registry
//
/////////////////////////////////////////////////////////////////////////////////////////

// collection of all menu objects created in the session
var m_oMenuRegistry = new Object
var m_lMenuCount = 0
var m_oActiveMenu 							// 8/10/03 
var m_oNewActiveMenu            // 8/26/03 

// collection of all menu item objects created in the session
var m_oMenuItemRegistry = new Object
var m_lMenuItemCount = 0
var m_oActiveMenuItem							// 8/10/03 

//find a menu with given id
function FindMenu(id){
  if (strlen(id) == 0){  return null }
  return m_oMenuRegistry[genId(id,"menu")]
}

//find a menu with given id
function FindMenuItem(id){
  if (strlen(id) == 0){  return null }
  return m_oMenuItemRegistry[id]
}

//destroys the menu registry
function DestroyMenuRegistry(){
  m_oMenuRegistry = null
  m_oActiveMenu = null
}

//destroys the menu item registry
function DestroyMenuItemRegistry(){
  m_oMenuItemRegistry = null
  m_oActiveMenuItem = null
}

// destroys both registries
function Destroy(){
  m_oMenuRegistry = null
  m_oActiveMenu = null
  m_oMenuItemRegistry = null
  m_oActiveMenuItem = null
}

/////////////////////////////////////////////////////////////////////////////////////////
//
//						Menu
//
/////////////////////////////////////////////////////////////////////////////////////////

// constructor for the menu object
function Menu(sCaption,lTop,lLeft,lHeight,lWidth,lItemHeight,lItemWidth,kind,isRoot,thisMenuItem,makeVisible){ 
  var sId
  
  // the number of all menus registered in the session
  m_lMenuCount = m_lMenuCount + 1
  sId = m_lMenuCount

  // currently supported are 'h'-horizontal, 'v'-vertical, default is vertical
  if ((kind != "v") && (kind != "h")) {  kind = "v";  }
  
  this.kind        = kind;           
  this.id          = genId(sId,"menu");
  this.caption     = sCaption;
  this.top         = lTop;         			// coordinates and size
  this.left        = lLeft;
  this.height      = lHeight;
  this.width       = lWidth; 
  this.move        = MoveMenu;                          // functions to move/resize the menu
  this.resize      = ResizeMenu;
  this.redraw      = RedrawMenu;
  this.level       = 0;                                 // level of the menu
	
  if (kind == "v"){					// default item height and width
    this.defaultitemheight = lItemHeight;		// all items must have same width as the menu
    this.defaultitemwidth  = lWidth;	 		// also set the corresponding menu item here
    if (thisMenuItem == null){
      if (isRoot){
        this.menuitem        = new MenuItem("",lTop,lLeft,0,0,"");
      }else{
        this.menuitem        = new MenuItem(sCaption,lTop,lLeft,lItemHeight,lWidth,"");
      }
    }else{
      this.menuitem = thisMenuItem;
    }
  }else{
    this.defaultitemheight = lHeight;			// all items must have same height as the menu
    this.defaultitemwidth  = lItemWidth;
    if (thisMenuItem == null){
      if (isRoot){
        this.menuitem        = new MenuItem("",lTop,lLeft,0,0,"");
      }else{
        this.menuitem        = new MenuItem(sCaption,lTop,lLeft,lHeight,lItemWidth,"");
      }
    }else{
      this.menuitem = thisMenuItem;
    }
  }

  this.menuItemStyle = "";       		        // user should provide a .css file with the definition
  this.menuItemStyleOver = "";	               		// of the style. The same functions are defined here and
  this.menuItemStyleLink = "";                          // for the menu item. The purpose of having them here is 
  this.menuItemStyleText = "";        			// so that if the user wants all the items in a menu to
  this.setMenuItemStyle  = SetMenuStyles;               // have the same style, then he can specify it here instead of
                                                        // having to manually set these properties for each item
  if (makeVisible){
    this.visible     = isVisible;			// whether or not this.item is visible or not
  }else{
    this.visible     = isHidden;                        // +-1 8/03 
  }
  this.setVisible  = SetMenuVisible;                    // function to set the visible property of the menu object 
  							// and all the menu item objects that constitute the menu
  this.expanded    = false;			        // whether the list of subitems is currently displayed or not
                                                        // only applies if there are subitems
  this.subItems    = new Object;                        // this array contains all the menu items that belong to
                                                        // this item, this array is indexed by integers
  this.subItemsCount = 0;                               // the number of direct subitems in this menu
  this.subItemsKey = new Object;                        // this is also the array that contains all menu items
                                                        // but they are indexed by key, not by integer							
                                                        // functions to add and remove items from a menu
  this.addItem     = AddMenuItem;
  this.removeItem  = RemoveMenuItem;
  this.itemByIndex = MenuItemByIndex;
  this.itemByKey   = MenuItemByKey;
  this.getMenuItemPos = GetMenuItemPos;
  this.getMenuItemFromPoint = GetMenuItemFromPoint;     // given coordinates (x,y), find the menu item that contains the point 8/10/03
  this.parent      = null;                              // parent item of this menu (for non-root menus only) 8/10/03
	                                                    
  this.innerHTML   = MenuInnerHTML;                     // function that generates the inner HTML of the menu
  //[ 7/03 used for submenus
  this.containsPoint = MenuContainsPoint;               // whether the menu rectangle contains the specified point
  // +2 8/10/03 
  //this.onmouseover  = "";   
  //this.onmouseout   = ""; 
  //] 7/03 
  //add to the registry of all menus
  m_oMenuRegistry[this.id] = this;
}

function SetMenuStyles(NewMenuItemStyle,NewMenuItemStyleOver,NewMenuItemStyleLink,NewMenuItemStyleText,AlsoSetSubMenus,UpdateUI){
  var lIndex;
  
  with (this){  
    // set the properties of the menu itself
    menuItemStyle     = NewMenuItemStyle;
    menuItemStyleOver = NewMenuItemStyleOver;
    menuItemStyleLink = NewMenuItemStyleLink;
    menuItemStyleText = NewMenuItemStyleText;
    // also set the properties for each of its menu items
    // AlsoSetSubMenus flag indicates whether the submenus styles should also be reset or not
    // the default is AlsoSetSubMenus = true, so as to allow to set the styles in one statement
    for (lIndex = 1; lIndex <= subItemsCount; lIndex++){
      subItems[lIndex].setMenuItemStyle(NewMenuItemStyle,NewMenuItemStyleOver,NewMenuItemStyleLink,NewMenuItemStyleText,AlsoSetSubMenus,UpdateUI); 
    }
  }
  return
}

// this function sets the visible property of the menu object and all the menu items that 
// constitute the menu. Depending on the UpdateUI parameter, it can do the actual show/hide
// of the html tag representing the menu
function SetMenuVisible(NewVisible,AlsoUpdateSubMenu,UpdateUI,MenuTag){
  var lIndex;
  var oMenuTag;
  var oMenuItem;
  var UpdateSubMenu;
  var UpdateSubUI;

  with (this){
    visible = NewVisible;
    UpdateSubMenu = (NewVisible != isVisible);
    //+1 8/14/03 for NN6, update ui even when hiding the menu +1 8/27/03 added check for Opera
    UpdateSubUI = UpdateUI && ((NewVisible == isVisible)  || isNN6 || isOpera || (isMac && isIE));
    for (lIndex = 1; lIndex <= subItemsCount; lIndex++){
      oMenuItem = subItems[lIndex];
      if (oMenuItem != null){
	      // show/hide the menu items that constitute this menu
	      oMenuItem.setVisible(NewVisible,UpdateSubMenu,UpdateSubUI);
	      oMenuItem = null;
      }
    }   
    if (UpdateUI){
      if (MenuTag == null){
		// +1 8/27/03 added check for Opera
	    if ((level == 0) || isNN6 || isOpera || (isMac && isIE)){
          oMenuTag = document.getElementById(genId(id,"div"));
	    }else{
          oMenuTag = document.getElementById(genId("level"+level,"div"));
	    }
      }else{
        oMenuTag = MenuTag;
      }
      if (oMenuTag != null){
			  //+1 8/27/03 added check for Opera
				if (isNN6 || isOpera || (isMac && isIE)){ 
					oMenuTag.style.visibility = NewVisible;
					if (level == 0){
						oMenuTag = document.getElementById(id);
					}else{
						oMenuTag = document.getElementById("level"+level);
					}
					if (oMenuTag) oMenuTag.style.visibility = NewVisible;
				}else{
					// +5 8/03  //+1 8/14/03
					if (NewVisible == isVisible){
						oMenuTag.innerHTML = innerHTML(false,true); 
					}else{
						oMenuTag.innerHTML = "";
          }
				}
				oMenuTag = null;
      }
    }
  }
  return
}

// whether the menu rectangle contains the point (X,Y)
function MenuContainsPoint(X,Y){
  var ContainsPoint;
  var lSubMenuLeft;
  var oActiveItem;
	
  with (this){
	oActiveItem = getMenuItemFromPoint(X,Y)
    if ((oActiveItem) && (oActiveItem.submenu)){
      lSubMenuLeft = Math.min(left+width,oActiveItem.submenu.left);
    }else{
      lSubMenuLeft = left+width;
    }
	ContainsPoint = (X >= left+CURSOR_WIDTH/2) && (X < lSubMenuLeft+CURSOR_WIDTH/2) && (Y>= top+CURSOR_HEIGHT/2) && (Y < top + height+CURSOR_HEIGHT/2)
  }
  return ContainsPoint
}

// this function removes a menu item from the menu
function RemoveMenuItem(){
  return 1;
}

// this function adds a menu item to the menu
// if Index is non-zero, it will be used (all the items will be shifted up, and the menu item will be
// inserted in the Index-th position. In order to insert after a given menu item, pass Index = GivenItem.index+1
// and to insert before a given menu item, pass Index = GivenItem.index - 1
// else the item will be added as the last subitem (currently this is the only one supported)
// if menu type is "vertical", the Width parameter is not used (it must be the same as the width of the menu)
// if menu type is "horizontal", the Height parameter is not used (it must be the same as the height of the menu)
function AddMenuItem(sCaption,Height,Width,Index,sAction){ 
  var oThisItem;
  var oPrevItem;
  var oNextItem;
  var lIndex;
  var lTop;
  var lLeft;
  var lWidth;
  var lHeight;
  var lIndex;
  var lLoopIndex;
  var lNumSubItems;
  var aPosSize = new Array(5);                //Success, Top, Left, Height, Width
  
  lNumSubItems = this.subItemsCount;
  if (Index > 0){
    lIndex = Index;
  }else{
    // just add it to the end, this is the easiest case since don't have to update all the menu items
    lIndex = this.subItemsCount + 1;
  }
  
  // get the coordinates of the menu item
  aPosSize = this.getMenuItemPos(Height,Width,lIndex);
  if (aPosSize[0] == 0){ return null;  }
  
  // create the menu item
  oThisItem = new MenuItem(sCaption,aPosSize[1],aPosSize[2],aPosSize[3],aPosSize[4],sAction);  
  // set the index property to the index of this menu item in the subItems array
  with (oThisItem){
    index = lIndex;
    // update the pointers accordingly
    if (lIndex < lNumSubItems){
      oNextItem = this.subItems[lIndex+1];
      if (oNextItem != null){ oNextItem.prevSibling = oThisItem;  }
    }else{
      oNextItem = null;
    }
    if (lIndex > 1){
      oPrevItem = this.subItems[lIndex-1];
      if (oPrevItem != null){ oPrevItem.nextSibling = oThisItem;  }
    }else{
      oPrevItem = null;
    }
    prevSibling = oPrevItem;
    nextSibling = oNextItem;
    parent      = this;

    // set the styles for the menu item to be the style defined at the menu level
    // the user can override this if he wishes, by setting the properties of the menu item
    // the UpdateUI parameter is set to false, since at this time (we are adding the menu item to the menu)
    // there is no tag corresponding to the menu item yet
    setMenuItemStyle(this.menuItemStyle,this.menuItemStyleOver,this.menuItemStyleLink,this.menuItemStyleText,true,false); 
    //+1 8/14/03 make invisible if containing menu is invisible
    visible = this.visible
  }
  with (this){
    // if needed, shift all the items in the array up by one, so that we could insert this item
    // in the lIndex-th position
    for (lLoopIndex = lNumSubItems+1; lLoopIndex > lIndex; lLoopIndex--){
      subItems[lLoopIndex] = this.subItems[lLoopIndex-1];
      subItems[lLoopIndex].index = lLoopIndex;          // the index was lLoopIndex-1, so need to update
    }
    // store the new item in the array of all subitems
    subItems[lIndex] = oThisItem;
    // store the new item in the keyed array of all subitems
    subItemsKey[oThisItem.id] = oThisItem;
    // increment the number of subitems
    subItemsCount = lNumSubItems + 1;  
    // change the width(or height) of the menu, to accomodate the added item
    if (kind == "v"){
      height = height + oThisItem.height;
    }else{
      width = width + oThisItem.width;
    }
  }
  // return the item that has been added
  return oThisItem;
}

// determine the position of the menu item in the WhichMenu
// sets the MenuItemTop,MenuItemLeft,MenuItemHeight and MenuItemWidth parameters
function GetMenuItemPos(Height,Width,Index){
  var lNumSubItems;
  var lIndex;
  var lTotal;
  var MenuItemWidth;
  var MenuItemHeight;
  var MenuItemTop;
  var MenuItemLeft;
  
  // quit if Menu object is not passed
  if (this == null){  return [0,0,0,0,0];  }  
  
  lNumSubItems = this.subItemsCount;

  // quit if Index is out of bounds, lNumSubItems + 1 is allowed since we might be adding a new item
  // and when doing so we do not increment .subItemsCount until we know it was added successfully
  if ((Index > lNumSubItems + 1) || (Index < 1)){  return [0,0,0,0,0];  }
  
  // determine the position and size of the menu item
  with (this){
  if (kind == "v"){
    // this is a vertical menu, all items must have the same width as the width of the menu
    // and the left is the same as the left of the menu
    MenuItemWidth   = width;
    if (MenuItemWidth == 0){ MenuItemWidth = Width;}
    MenuItemLeft    = left;  
    // determine the top of the menu item  
    MenuItemTop = top;
    for (lIndex = 1; lIndex < Index; lIndex++){
      MenuItemTop = MenuItemTop + subItems[lIndex].height;
    }
    // if the height parameter is specified, then use it, otherwise try menu's default height, if that is 0 too,
    // then use the height remaining in the menu  
    if (Height > 0){
       MenuItemHeight = Height;
     }else{
       MenuItemHeight = defaultitemheight;
       if (MenuItemHeight == 0){
       	 lTotal = MenuItemTop;
	 for (lIndex = Index; lIndex <= lNumSubItems; lIndex++){
	   lTotal = lTotal + subItems[lIndex].height;
	 }
         MenuItemHeight = height - lTotal;
       }
     }
     // if the height is negative, then something is wrong, so quit
     if (MenuItemHeight < 0){
       return [0,0,0,0,0];
     }
  }else{
    if (kind == "h"){
      // this is a horizontal menu, all items must have the same height as the height of the menu
      // and the top is the same as the top of the menu
      MenuItemHeight = height;
      if (MenuItemHeight == 0){ MenuItemHeight = Height;}
      MenuItemTop  = top;
      // use the minimum of the width passed as the parameter and the width remaining in the menu    
      MenuItemLeft = left;

      for (lIndex = 1; lIndex < Index; lIndex++){
        MenuItemLeft = MenuItemLeft + subItems[lIndex].width;
      }
      // if the width parameter is specified, then use it, otherwise try menu's default width, if that is 0 too,
      // then use the width remaining in the menu   
      if (Width > 0){
        MenuItemWidth = Width;
      }else{
        MenuItemWidth = defaultitemwidth;
        if (MenuItemWidth == 0){
	  lTotal = MenuItemLeft;
	  for (lIndex = Index; lIndex <= lNumSubItems; lIndex++){
	    lTotal = lTotal + subItems[lIndex].width;
	  }
          MenuItemWidth = width - lTotal;	
        }
      }
      // if the width is negative, then something is wrong, so quit
      if (MenuItemWidth < 0){
        return [0,0,0,0,0];
      }
    }else{
      // something must be wrong, so quit
      return [0,0,0,0,0];
    }
  }
  }
  
  return [1,MenuItemTop,MenuItemLeft,MenuItemHeight,MenuItemWidth];
}

//this function redraws the menu, by changing the innerHTML property of the tag that 
//represents the menu
function RedrawMenu(newTop,newLeft,newHeight,newWidth){
  var oTag

  with (this){
	  //+1 8/27/03 added check for Opera
    if ((level == 0)|| isNN6 || isOpera || (isMac && isIE)){
      oTag = document.getElementById(genId(id,"div"));
    }else{
      oTag = document.getElementById(genId("level"+level,"div"));
    }
  }
  // if the tag representing the menu does not exist, then quit
  if (!oTag) return

  if (newTop    != "same") oTag.style.top = newTop
  if (newLeft   != "same") oTag.style.left = newLeft     
  if (newHeight != "same") oTag.style.height = newHeight
  if (newWidth  != "same") oTag.style.width = newWidth
  return
}

// this function moves the menu to the specified location
function MoveMenu(newTop,newLeft,updateUI,redrawSubMenus){
  var isChanged;
  var lIndex;
  var lTopDiff;
  var lLeftDiff;

  isChanged = false;
  if (this != null){
    lTopDiff = 0;
    lLeftDiff = 0;
    with (this){
      if ((newTop != "same")&&(newTop != top)) { lTopDiff = newTop - top;  top = newTop; isChanged = true;}
      if ((newLeft != "same")&&(newLeft != left)) { lLeftDiff = left; left = newLeft; isChanged = true;}
      // if anything changed, may need to do the same for each item
      if (isChanged){
        if (kind == "v"){
          // vertical menu, left of the item is the same as of the menu
          for (lIndex = 1; lIndex <= subItemsCount; lIndex++){
            subItems[lIndex].move(subItems[lIndex].top + lTopDiff,newLeft,updateUI,redrawSubMenus);
          }
        }else{
          for (lIndex = 1; lIndex <= subItemsCount; lIndex++){
            subItems[lIndex].move(newTop,subItems[lIndex].top + lLeftDiff,updateUI,redrawSubMenus);
          }
	    }
        // if updateUI flag is set, then redraw the menu
        if (updateUI){ this.redraw(newTop,newLeft,"same","same") }
      }
    }
  }
  return isChanged;
}

// this function resizes and moves the menu to the specified location
function ResizeMenu(newTop,newLeft,newHeight,newWidth,updateUI,redrawSubMenus){
  var isChanged;
  var lIndex;
  var lTopDiff;
  var lLeftDiff;
  
  isChanged = false;
  if (this != null){
    lTopDiff = 0;
    lLeftDiff = 0;
    with (this){
      if (newTop != "same")   { lTopDiff = newTop - top;  top = newTop; isChanged = true;}
      if (newLeft != "same")  { lLeftDiff = left; left = newLeft; isChanged = true;}  
      if (newHeight != "same"){   height = newHeight; isChanged = true;}
      if (newWidth != "same") {    width  = newWidth;  isChanged = true;} 
      // if anything changed, may need to do the same for each item
      if (isChanged){
        if (kind == "v"){
	        // vertical menu, left of the item is the same as of the menu
          for (lIndex = 1; lIndex <= subItemsCount; lIndex++){
	          subItems[lIndex].resize(subItems[lIndex].top + lTopDiff,newLeft,newHeight,newWidth,updateUI, redrawSubMenus);
          }
        }else{
          for (lIndex = 1; lIndex <= subItemsCount; lIndex++){
	          subItems[lIndex].resize(newTop,subItems[lIndex].left + lLeftDiff,newHeight,newWidth,updateUI, redrawSubMenus);
          }
	      }
      }
      // if updateUI flag is set, then redraw the menu
      if (updateUI){ this.redraw(newTop,newLeft,newHeight,newWidth) }
    }
  }
  return isChanged;
}

// returns the Position-th item of the menu
function MenuItemByIndex(Position){
  if ((Position > 0) && (Position < this.subItemsCount + 1)){
    return this.subItems[Position];
  }else{
    return null;
  }
}

// returns the item of the menu with the specified key
function MenuItemByKey(Key){
  return this.subItemsKey(Key);
}

// returns the HTML representation of the menu 
function MenuInnerHTML(FirstTime,UseLevel,MakeVisible){
  var sHTML;
  var lIndex;
  var lTop;
  var lHeight;
  var sId;
  var oSubMenu;
	
  if (this == null){ return ""; }
  
  with (this){
    if (MakeVisible){  visible = isVisible; }
    if (menuitem.parent == null){
      lTop = top;
      lLeft = left;
    }else{
      if (menuitem.parent.kind == "v"){
        lTop = top;
        lLeft = left + menuitem.width;
      }else{
        lTop = top + menuitem.height;
        lLeft = left;
      }
    }
	//+1 8/27/03 added check for Opera
    if ((UseLevel)&&(!isNN6)&&(!isOpera)&&(!(isMac && isIE))){
      sId = "level" + level;
    }else{
      sId = id;
    }
    if (FirstTime){
      sHTML = "<div id='" + genId(sId,"div") + "' style='border:0px blue solid; position:absolute; top:" + lTop + "px; left:" + lLeft + "px; width:" + width + "; visibility: " + visible + "'><table id='" + sId + "'";
    }else{
      sHTML = "<table id='" + sId + "'";
    }
    //+5 8/14/03  +1 8/27/03 added check for Opera
    if (isNN6 || isOpera || (isMac && isIE)){
      sHTML = sHTML +' cellspacing="0" cellpadding="0" style="border:0px solid red;">';
    }else{
      sHTML = sHTML + " cellspacing=0 cellpadding=2 style='border:0px solid red'>";
    }
    if (kind == "v"){   // vertical menu
      for (lIndex = 1; lIndex <= subItemsCount; lIndex++){
        sHTML = sHTML + "<tr>" + subItems[lIndex].innerHTML() + "</tr>";
      }
    }else{              // horizontal menu
      sHTML = sHTML + "<tr style='border:0px solid red;'>";
      for (lIndex = 1; lIndex <= subItemsCount; lIndex++){
        sHTML = sHTML + subItems[lIndex].innerHTML();
      }
      sHTML = sHTML + "</tr>";
    }
    sHTML = sHTML + "</table>";
    if (FirstTime){  
      sHTML = sHTML + "</div>"; 
      // Netscape 6 +1 8/27/03 added check for Opera
      if (isNN6 || isOpera || (isMac && isIE)){ 
        for (lIndex = 1; lIndex <= subItemsCount; lIndex++){
          oSubMenu = subItems[lIndex].submenu;
          if (oSubMenu) {
            oSubMenu.setVisible(isHidden,false,false)
            sHTML = sHTML + oSubMenu.innerHTML(true,true,false) 
          }
	    }
      }
    }
  }
  return sHTML;
}

/////////////////////////////////////////////////////////////////////////////////////////
//
//						Menu Item
//
/////////////////////////////////////////////////////////////////////////////////////////

//constructor for the menu item object
function MenuItem(sCaption,lTop,lLeft,lHeight,lWidth,sAction){ 
  var sId;

  // the number of all menus registered in the session
  m_lMenuItemCount = m_lMenuItemCount + 1;
  sId = genId(m_lMenuItemCount,"menuitem");
  
  this.id          = sId;             		                // unique id
  this.caption     = sCaption;     				// caption
  
  this.leftIcon    = "";          				// icon to the left of the text;  when doesn't have focus
  this.rightIcon   = "";          				// icon to the right of the text; when doesn't have focus

  this.leftIconHot   = "";          				// icon to the left of the text;  when has focus
  this.rightIconHot  = "";           				// icon to the right of the text; when has focus 
  this.setMenuItemIcons = SetMenuItemIcons;                     // function to set all the icons in one call

  this.menuItemStyle = "";       		                // user should provide a .css file with the definition
	                            				// of the style. This will define foreground and background
	    					    	                                           // color (when doesn't have focus) etc.
  this.menuItemStyleOver = "";                                  // this style defines background and foreground colors etc
  							                                                 // when the mouse is over the menu item
  this.menuItemStyleLink = "";                                  // this defines the style of the link
  this.menuItemStyleText = "";                                  // this defines the style of the caption of the menu item
  this.setMenuItemStyle = SetMenuItemStyles;                    // function to set all of the styles
															
  this.submenu     = null;                       		// pointer to the associated submenu, if this is a submenu

  this.parent      = null;                                      // pointer to the Menu object to which this menu item belongs
  this.prevSibling = null;                                      // pointers to next and previous menu items in the
  this.nextSibling = null;                                      // this.parent Menu object
  this.index       = 0;                                         // index of this item in the this.parent Menu object
	
  this.visible     = isVisible;   				// whether it is visible or invisible
  this.setVisible  = SetMenuItemVisible;                        // function to set the visible property of the menu item
  
  this.linkURL     = sAction;                                   // url to which this menu item points
  
  this.top         = lTop;         			   	// coordinates and size
  this.left        = lLeft;
  this.height      = lHeight;
  this.width       = lWidth;
  this.move        = MoveMenuItem;     		       	        // functions that move/resize the menu
  this.size        = ResizeMenuItem;
                                       				// functions that define default response to the most common events
  this.addSubMenu  = AddSubMenu;
  this.innerHTML   = MenuItemInnerHTML;                         // function that generates and returns the HTML that 
  							                                                // represents the menu item
  this.containsPoint = MenuItemContainsPoint;                   
  //add to the registry of all menu items
  m_oMenuItemRegistry[sId] = this;  
}

// add a submenu to the current menu item
// this points to the menu item
function AddSubMenu(WhichMenu,UseParentStyle,UseOwnCoords){
  var oParentMenu;
 
  if (!WhichMenu) return null;
	
  with (this){ 
    submenu = WhichMenu;
    // [ 7/03 
    // at first, the submenu is not visible, but the way we generate the code (adding the submenu when it is to be
    // shown for the first time) we have to keep the visible property set to true
    //if (WhichMenu != null) { WhichMenu.setVisible(isHidden,true,true,null) }
    // +2 8/10/03 
    //WhichMenu.onmouseout = onmouseout;
    WhichMenu.parent = this
    // set the style of the menu to be the same as that of the menu item, if UseParentStyle is true
    if (UseParentStyle){
      WhichMenu.setMenuItemStyle(menuItemStyle,menuItemStyleOver,menuItemStyleLink,menuItemStyleText,true,false);
    }
    // ] 7/03 
    // in addition, position the submenu appropriately
    oParentMenu = parent;
    if (oParentMenu != null){
      // the way we have it set up, the menu and the item to which it's added as submenu 
      // have the same top and left. 2*index accounts for cellpadding
      if (!UseOwnCoords){
        if (oParentMenu.kind == "v"){
          WhichMenu.move(top+2*index,left+width+2);
        }else{
          WhichMenu.move(top+height+2,left+2*index);
        }
      }
      WhichMenu.level = oParentMenu.level + 1;  // 8/03 
      linkURL = "";                             // 8/24/03 
    }
  }
  oParentMenu = null;
  return WhichMenu;
}

// this function moves the menu item to the specified location
function MoveMenuItem(newTop,newLeft,updateUI,redrawSubMenus){
  var isChanged;

  isChanged = false;
  if (this != null){
    with (this){
      if (newTop != "same"){  top    = newTop; isChanged = true;}
      if (newLeft != "same"){	left   = newLeft;isChanged = true;}
      if ((submenu)&&(redrawSubMenus)){
        submenu.move(newTop,newLeft,updateUI,redrawSubMenus)
      }
    }
  }
  return isChanged;
}

// this function resizes and moves the menu item to the specified location
function ResizeMenuItem(newTop,newLeft,newHeight,newWidth,updateUI,redrawSubMenus){
  var isChanged;
  
  isChanged = false;
  with (this){
    if (newTop != "same"){      top    = newTop;    isChanged = true;}
    if (newLeft != "same"){     left   = newLeft;   isChanged = true;}
    if (newHeight != "same"){   height = newHeight; isChanged = true;}
    if (newWidth != "same"){    width  = newWidth;  isChanged = true;} 
    if ((submenu)&&(redrawSubMenus)){
      submenu.resize(newTop,newLeft,newHeight,newWidth,updateUI,redrawSubMenus)
    }
  }
  return isChanged;
}

function SetMenuItemIcons(NewRightIcon,NewRightIconHot,NewLeftIcon,NewLeftIconHot,UpdateUI){
  with (this){
    if (UpdateUI){
      ChangeIcon(id,rightIcon,NewRightIcon,"right icon"); 
      ChangeIcon(id,leftIcon,NewLeftIcon,"left icon"); 
    }   
    rightIcon    = NewRightIcon;
    rightIconHot = NewRightIconHot;
    leftIcon     = NewLeftIcon;
    leftIconHot  = NewLeftIconHot;
  }
  return
}

function SetMenuItemStyles(NewMenuItemStyle,NewMenuItemHotStyle,NewMenuItemLinkStyle,NewMenuItemTextStyle,AlsoSetSubMenu,UpdateUI){
  var oMenu;
  
  with (this){
    menuItemStyle     = NewMenuItemStyle; 
    menuItemStyleOver = NewMenuItemHotStyle;  				       
    menuItemStyleLink = NewMenuItemLinkStyle;                 
    menuItemStyleText = NewMenuItemTextStyle;  
    if (AlsoSetSubMenu){
      oMenu = submenu;
      if (oMenu != null){
        oMenu.setMenuItemStyle(NewMenuItemStyle,NewMenuItemHotStyle,NewMenuItemLinkStyle,NewMenuItemTextStyle,AlsoSetSubMenu,UpdateUI);
        oMenu = null;      
      }
    }
  }
  return
}

// this function sets the visible property of the menu item object. 
// Depending on the UpdateUI parameter, it can do the actual show/hide
// of the html tag representing the menu item
function SetMenuItemVisible(NewVisible,AlsoSetSubMenu,UpdateUI){ 
  var oMenuItemTag;
  var oMenu;

  this.visible = NewVisible;
  if (UpdateUI){
    oMenuItemTag = document.getElementById(this.id);  
    if (oMenuItemTag != null){
      //+3 8/14/03 handle NN6 +1 8/27/03 added check for Opera
      if (isNN6 || isOpera || (isMac && isIE)) {
	      oMenuItemTag.style.visibility = NewVisible;
      }else{
	      // 8/5 oMenuItemTag.style.visibility = NewVisible;
	      if (NewVisible == isVisible){ 
	        oMenuItemTag.innerHTML = this.innerHTML();
	      }else{
	        oMenuItemTag.innerHTML = ""; 
	      }
      }
      oMenuItemTag = null;
    }
    if (AlsoSetSubMenu){
      oMenu = this.submenu;
      if (oMenu != null){
        oMenu.setVisible(NewVisible,AlsoSetSubMenu,UpdateUI,null);
        oMenu = null;      
      }
    }
  }
  return
}

//this function defines the default response to the OnMouseOver event
function ShowSubMenu(id,WhichMenuItem,MakeVisible){
  var oMenuItem;
  var oMenu;
  var oMenuTag;
  var oMenuItemTag;

  if (WhichMenuItem != null){
    oMenuItem = WhichMenuItem;
  }else{
    // get the menu item object with the given id
    oMenuItem = FindMenuItem(id);
  }
  if (oMenuItem == null){    return;  }
  
  // show the submenu if there is one
  // if there isn't return nothing
  oMenu = oMenuItem.submenu;
  if (oMenu == null){   return; }	
  // check if the html tag representing the submenu already exists
  // 8/03 use oMenu.level. +1 8/27/03 added check for Opera
  if (isNN6 || isOpera || (isMac && isIE)){
    oMenuTag = document.getElementById(genId(oMenu.id,"div"));
  }else{
    oMenuTag = document.getElementById(genId("level"+oMenu.level,"div"));
  }
  // if the tag does not exist, then add it
  if (oMenuTag == null){ 
    //document.body.innerHTML = document.body.innerHTML + oMenu.innerHTML()
    oMenuItemTag = document.getElementById("tdmenu")
		//+1 8/27/03 added check for Opera
    if ((oMenuItemTag)&&(!isNN6)&&(!isOpera)&&(!(isMac && isIE))){ 
      //+1 8/14/03 
      oMenu.setVisible(isVisible,true,false,null)
      oMenuItemTag.innerHTML = oMenuItemTag.innerHTML + oMenu.innerHTML(true,true,true)
    }
  }else{	
    if (MakeVisible == isVisible){
      oMenu.setVisible(isVisible,true,true,oMenuTag)
    }else{	     
      oMenu.setVisible(isHidden,true,true,oMenuTag)	   
    }
  }
  oMenu = null;
  oMenuItem = null;
  oMenuItemTag = null;
}

// change the icon of the image of the menu item id
function ChangeIcon(id,oldIcon,newIcon,action){
  var sId;
  var oIcon;

  if (strlen(newIcon) > 0){  
    if (newIcon != oldIcon){
      sId = genId(id,action)	
      if (strlen(sId) > 0){
        oIcon = document.getElementById(sId)
        if (oIcon != null) { oIcon.src = newIcon }
      }
    }
  }
  return
}

//this function defines the default response to the OnMouseMove event for the whole window
function DefaultOnMouseMove(e){
  var result
  var x,y
  // get the coordinates of the event
  if (isNN) {	
    if (e){
      x = e.pageX;
      y = e.pageY;
    }
  }else {
    x = event.x;
    y = event.y;
  }
  // if there is an active menu item, then check if it still contains the point (x,y). 
  if (m_oActiveMenuItem) { 
    if (m_oActiveMenuItem.containsPoint(x,y)) { 
      // If it does, then there is nothing more to do
      return 1;
    }else{
      // If not, then we must have left the current active menu item, so we want to call its mouseout event
      result = DefaultOnMouseOut(m_oActiveMenuItem.id,x,y)
    }
  }
  // then we want to find the new active menu (if it changed) and the new active menu item
  if (m_oNewActiveMenu) { 
    // if DefaultOnMouseOut set oNewActiveMenu, then it must be the new active menu
	// hide the previous active menu, if any (And if it's not the root, root is always visible, AND if it's not 
	// the parent of the new active menu), and set the member variable to point to the new active menu.
    hideCurrentActiveMenu()
    m_oActiveMenu = m_oNewActiveMenu
	m_oNewActiveMenu = null
  }else{
    // check if the active menu changed. the following check is more of just a precaution, since if we are here,
    // then m_oActiveMenuItem is set, so m_oActiveMenu must be set too.
    if (m_oActiveMenu) {
      if (!m_oActiveMenu.containsPoint(x,y)){
        // if we are here, then the active menu must have changed, so we must hide the current active menu (if it's not
		// the root, as root is always visible, AND not the parent of the new active menu) and find the new active menu, if any
		hideCurrentActiveMenu()
	    m_oActiveMenu = GetMenuFromPoint(x,y)
      }
    }else{
      // see if any menu contains the point (x,y)
      m_oActiveMenu = GetMenuFromPoint(x,y)
    }
  }
  // m_oActiveMenu should have been already updated (it may very well have become null, if the mouse left the area
  // taken by any of the menus.
  if (m_oActiveMenu) {
    // to find the active menu item, it's faster to loop through just the subitems of the active menu, rather than
    // looping through all the registered menu items
    m_oActiveMenuItem = m_oActiveMenu.getMenuItemFromPoint(x,y)
  } else {
    // if we are here, then we must have left the area taken by any of the menus, so there would be no menu item
    m_oActiveMenuItem = null
  }
  // if there is a new active menu item, then we need to call its mouseover method.
  if (m_oActiveMenuItem){
    return DefaultOnMouseOver(m_oActiveMenuItem.id)
  }else{
    return 0;
  }
}

// hide current active menu
function hideCurrentActiveMenu(){
	var oSubMenu	
	if ((m_oActiveMenu) && (m_oActiveMenu.level > 0) && (m_oActiveMenuItem) && (m_oNewActiveMenu)) {
	  oSubMenu = m_oActiveMenuItem.submenu
 	  if ((oSubMenu) && (oSubMenu.id != m_oNewActiveMenu.id)) { m_oActiveMenu.setVisible(isHidden,true,true) }
	} 
	return 
}

// change the style and the icons of the menu item 
function ChangeIconsAndStyle(oMenuItem){
  var sIcon
  var sIcon2
  var oMenuItemTag

  if (!oMenuItem) return 0
	
  with (oMenuItem){ 
    // change right icon
    sIcon2 = rightIcon; 
    sIcon = rightIconHot;
    ChangeIcon(id,sIcon,sIcon2,"right icon");	
    //change the left icon
    sIcon2 = leftIcon; 
    sIcon = leftIconHot;
    ChangeIcon(id,sIcon,sIcon2,"left icon");
    //change the text style
    if (strlen(menuItemStyleOver) > 0){ 
      oMenuItemTag = document.getElementById(id)
      if (oMenuItemTag) { oMenuItemTag.className = menuItemStyle }
    }
  }
  return 1
}

// this function defines the default response to the OnMouseOut event
// id  - id of the menu item for which this is called.
// x,y - current coordinates of the mouse.
// m_newActiveMenu - this function may set this to reference the new menu that became active.
//                   this will be done to speed-up finding the new active menu. it would be the case when 
//                   the submenu of the menu item becomes active. This ia not a parameter, but rather a member
//                   variable, since in Javascript parameters are passed by value
function DefaultOnMouseOut(id,x,y){
  var oMenuItem
  var oMenu
	
  if (strlen(id) > 0){
    oMenuItem = FindMenuItem(id);
    if (oMenuItem == null){ return null }
    //[ 7/03 if mouseout is due to the fact that the user moved the mouse to the submenu, do not hide the submenu
    oMenu = oMenuItem.submenu
    if ((oMenu) && (oMenu.containsPoint(x,y))) { 
	  // +1 8/10/03 found the new active menu
	  m_oNewActiveMenu = oMenu;
	  oMenu = null;
	  oMenuItem = null;
	  return 1;
	}
    //] 7/03 
    // +1 8/10/03 moved to a function
    ChangeIconsAndStyle(oMenuItem)
    //+1 8/03 pass 3rd parameter as false, hide the submenu of the menu item for which mouseout is called
    ShowSubMenu(id,oMenuItem,isHidden)
    //[ 8/03 if mouseout due to leaving the non-root menu, then hide the menu itself
    oMenu = oMenuItem.parent
    if (oMenu){
      if ((oMenu.level > 0) && (!oMenu.containsPoint(x,y))){
        // +1 8/10/03
        ChangeIconsAndStyle(oMenu.parent)
        oMenu.setVisible(isHidden,true,true)
		//now do the same for the parent. this only handles 2 level menus. To do: handle in general.
		///oMenu.parent is a menu item, oMenu.parent.parent is the menu that contains it.
		oMenu = oMenu.parent.parent
		if ((oMenu.level > 0) && (!oMenu.containsPoint(x,y))){
          ChangeIconsAndStyle(oMenu.parent)
          oMenu.setVisible(isHidden,true,true)
		}
        return null
      }
    }
    //] 8/03  
    oMenuItem = null
    return 1
  } else{
    return 0
  }
}

// this function defines the default response to the OnMouseOver event
// id  - id of the menu item for which this is called.
function DefaultOnMouseOver(id){
  var oMenuItem
  var oMenuItemTag
  var sIcon
  var sIcon2
  if (strlen(id) > 0){
    oMenuItem = FindMenuItem(id); 
    if (oMenuItem == null){  return false }
    with (oMenuItem){ 
      // change right icon
      sIcon2 = rightIconHot; 
      sIcon = rightIcon;
      ChangeIcon(id,sIcon,sIcon2,"right icon");
      //change the left icon
      sIcon2 = leftIconHot; 
      sIcon = leftIcon;
      ChangeIcon(id,sIcon,sIcon2,"left icon");
      //change the text style
      if (strlen(menuItemStyleOver) > 0){ 
        oMenuItemTag = document.getElementById(id)
        if (oMenuItemTag) { oMenuItemTag.className = menuItemStyleOver }
      }
    }
    oMenuItem = null;
    // +1 8/03 pass 3rd parameter as true
    ShowSubMenu(id,oMenuItem,isVisible);
    return true;
  }else{
    return false;
  }
}

// loop through all the registered menus, and find one that contains the given point.
// Quits after the first menu containing the point is found. thus, if there are overlapping menus, they may not be
// handled correctly.
function GetMenuFromPoint(x,y){
  var lIndex
  var oMenu
  // just as a precaution
  if (m_oMenuRegistry == null) return null;
  // loop through all the registered menus, and for each one check if it contains the given point.
  // quit as soon as a menu containing the given point is found.
  for (lIndex = 1; lIndex <= m_lMenuCount; lIndex++){
    oMenu = m_oMenuRegistry[genId(lIndex,"menu")]
    if ((oMenu) && (oMenu.visible == isVisible) && (oMenu.containsPoint(x,y))){ break }
  }
  // if not found, return null
  if ((lIndex > m_lMenuCount) || (!oMenu)) return null
  // else return the reference to the menu
  return oMenu
}

// this is a method of a Menu object.
// loop through all the menu items in the menu, and find one that contains the given point.
function GetMenuItemFromPoint(x,y){
  var lIndex
  var oMenuItem
  // just as a precaution
  if (this == null) return null;
  // loop through all the menu items in the menu, and find one that contains the given point.
  // quit as soon as a menu containing the given point is found.
  with (this){
    for (lIndex = 1; lIndex <= subItemsCount; lIndex++){
      oMenuItem = subItems[lIndex]
      if ((oMenuItem) && (oMenuItem.visible == isVisible) && (oMenuItem.containsPoint(x,y))){ break }
    }
    //+1 8/03 if none of the subitems contain the point, return null
    if (lIndex > subItemsCount) oMenuItem = null
  }
  return oMenuItem
}

// whether the menu item rectangle contains the point (X,Y)
function MenuItemContainsPoint(X,Y){
  var ContainsPoint;
  var lSubMenuLeft;
  
  with (this){
    if (submenu){
      lSubMenuLeft = Math.min(left+width,submenu.left);
    }else{
      lSubMenuLeft = left+width;
    }
    ContainsPoint = (X >= left+CURSOR_WIDTH/2) && (X < lSubMenuLeft+CURSOR_WIDTH/2) && (Y>= top+CURSOR_HEIGHT/2) && (Y < top + height+CURSOR_HEIGHT/2)
  }
  return ContainsPoint
}

// this function generates the html code for the menu item 
function MenuItemInnerHTML(){
  var sHTML;
 
  sHTML = "";
  if (this != null){
    with (this){ 
      sHTML = "<td id='" + id + "' style='width:" + width + "px; height:" + height + "px; visibility:" + visible + "; vertical-align:middle; border:0px solid blue'";
      //[ 8/10/03 everything is now handled in the document's mousemove event
      if (strlen(menuItemStyle) == 0){
        sHTML = sHTML + ">";
      }else{
        sHTML = sHTML + " class='" + menuItemStyle + "'>";
      }
      // beginning of <a tag
      sHTML = sHTML + "<a id='" + genId(id,"caption") + "'";
      if (strlen(linkURL) > 0){     
		sHTML = sHTML + " href='" + linkURL + "'"
		//+5 8/24/03
		// use style menuItemStyleLink only if the caption ofthe menu is indeed a link
		// if the menu item contains a submenu, then linkURL will be "", so we will use the menuItemStyleText instead
		if (strlen(menuItemStyleLink) > 0){  sHTML = sHTML + " class='" + menuItemStyleLink + "'" } 
	  }else{
	    if (strlen(menuItemStyleText) > 0){  sHTML = sHTML + " class='" + menuItemStyleText + "'" } 
	  }
      sHTML = sHTML +  ">";     
      // end of <a tag
      // left icon
      if (strlen(leftIcon) > 0){
        //sHTML = sHTML + "<img id='"  + genId(id,"left icon") + "' style='border:0px; width:" + (height-2) + "px; height:" + (height-2) + "px; text-align:center; vertical-align:middle' hspace=4 src='" + leftIcon + "'>";
        sHTML = sHTML + "<img id='"  + genId(id,"left icon") + "' style='border:0px; text-align:center; vertical-align:middle' hspace=4 src='" + leftIcon + "'>";
      }
      // caption 
	  if (isMac && isIE){
	    sHTML = sHTML + "<span>" + caption + "</span>";
	  }else{
	    sHTML = sHTML + caption;
	  }
      // right icon
      if (strlen(rightIcon) > 0){
        //sHTML = sHTML + "<img id='" + genId(id,"right icon") + "'  style='border:0px; width:" + (height-2) + "px; height:" + (height-2) + "px; text-align:center; vertical-align:middle' hspace=4 src='" + rightIcon + "'>";
        sHTML = sHTML + "<img id='" + genId(id,"right icon") + "'  style='border:0px; text-align:center; vertical-align:middle' hspace=4 src='" + rightIcon + "'>";
      }  
      sHTML = sHTML + "</a></td>";
    }
  }
  return sHTML;
}


/////////////////////////////////////////////////////////////////////////////////////////
//
//						Utility functions
//
/////////////////////////////////////////////////////////////////////////////////////////

// this function returns the length of the string
function strlen(text){
  var oStr = new String(text);
  
  if (oStr != null){ return oStr.length;}
  return 0;
}

// find the first occurrence of strToFind in strToSearch
function inStr(strToSearch,strToFind){
  var oStr
  var lPos
  
  oStr = new String(strToSearch)
  lPos = oStr.indexOf(strToFind)
  return lPos
}

// this function generates the id for different cells of the table that represents the menu item
function genId(id, action){
  if (action ==  "left icon"){   return (id + "li");}
  if (action == "right icon"){   return (id + "ri");} 
  if (action == "caption")   {   return (id + "txt");}  
  if (action == "menu")      {   return (id + "menu");}
  if (action == "menuitem")  {   return (id + "mi");}
  if (action == "div")       {   return (id + "div");}
  return "";
}

// determine the browser version
function browserVersion() {  
  var sUserAgent
  var sAppName
  var sPlatform
  
  with (navigator) {
    sAppName   = appName
    sUserAgent = userAgent
    sVersion   = appVersion
    sPlatform = platform
  }
  isNN  = (sAppName=="Netscape")
  isNN4 = (isNN)&&(parseInt(sVersion)==4) 
  if (isNN4){
    isVisible = "show"
    isHidden  = "hide"
  }
  isOpera = (inStr(sUserAgent,"Opera") != -1)
  isIE    = (!isOpera)&&(inStr(sUserAgent,"MSIE") !=  -1)
  isNN6   = (isNN)&&(inStr(sUserAgent,"Netscape6") !=  -1)
  // platform
  isPC   = (inStr(sPlatform,'Win') != -1)
  isMac  = (inStr(sPlatform,'Mac') != -1)
  //if not PC or Mac, assume some Unix platform
  isUnix = (!isPC) && (!isMac) 
  // 9/03 
  if (isIE && isMac){
    CURSOR_WIDTH = 0
    CURSOR_HEIGHT = 0
  }else{
    CURSOR_WIDTH = 16
    CURSOR_HEIGHT = 16
  }
  return 
}

/////////////////////////////////////////////////////////////////////////////////////////
//
// This code is specific to InteriorDesignCo
//
/////////////////////////////////////////////////////////////////////////////////////////
// function that determines the top position of the root menu
function getMenuTop(){
  var lTop,lLeft
  if (isNN6){
    lTop  = document.getElementById("td02").style.height + document.getElementById("td1").style.height 
    lLeft = 115 
  }else{
    lTop  = 318
    lLeft = 115 
  }
  return [lTop,lLeft]
}

// function that loads the menus
function loadMenu(){
   var lTop,lLeft,Coords
   
   lCoords = getMenuTop()
   lTop = lCoords[0]
   lLeft = lCoords[1]
   var oMenu = new Menu("main",lTop,lLeft,0,150,20,150,"v",true,null,true);
   // add top menu items
   var oIntDesign = oMenu.addItem("integral design",0,0,0,"");
   oIntDesign.setMenuItemIcons("blank.gif","blank.gif","blank.gif","minilogo.gif",false);
   var oWhatsNew = oMenu.addItem("what's new",0,0,0,"new.htm");
   oWhatsNew.setMenuItemIcons("blank.gif","blank.gif","blank.gif","minilogo.gif",false);
   var oAboutUs = oMenu.addItem("about us",0,0,0,"aboutus.htm");
   oAboutUs.setMenuItemIcons("blank.gif","blank.gif","blank.gif","minilogo.gif",false);
   var oContactUs = oMenu.addItem("contact us",0,0,0,"contact.htm");
   oContactUs.setMenuItemIcons("blank.gif","blank.gif","blank.gif","minilogo.gif",false);
   // add submenu to the integral design menu
   var oMenu1 = new Menu("integral design",lTop,lLeft+120,0,165,20,165,"v",false,null,false);
   var oMenuRes = oMenu1.addItem("residential",0,0,0,""); 
   oMenuRes.setMenuItemIcons("blank.gif","blank.gif","blank.gif","blank.gif",false);
   // continue with the integral design menu
   var oMenuItem1 = oMenu1.addItem("commercial",0,0,0,"commercial.htm");
   oMenuItem1.setMenuItemIcons("blank.gif","blank.gif","blank.gif","blank.gif",false);
   oMenuItem1 = oMenu1.addItem("other",0,0,0,"other.htm");	 
   oMenuItem1.setMenuItemIcons("blank.gif","blank.gif","blank.gif","blank.gif",false);
   oMenu1 = oIntDesign.addSubMenu(oMenu1,true,true);	 
   // add submenu to the what's new menu
   var oMenu2 = new Menu("what's new",lTop,lLeft+120,0,165,20,165,"v",false,null,false);
   //var oMenuItem2 = oMenu2.addItem("current events",0,0,0,"events.htm");
   //oMenuItem2.setMenuItemIcons("blank.gif","blank.gif","blank.gif","blank.gif",false);
   //oMenuItem2 = oMenu2.addItem("newsletter archive",0,0,0,"newsletter.htm");
  // oMenuItem2.setMenuItemIcons("blank.gif","blank.gif","blank.gif","blank.gif",false);
   //oMenu2 = oWhatsNew.addSubMenu(oMenu2,true,true);
   // add submenu to the about us menu
   var oMenu3 = new Menu("about us",lTop,lLeft+120,0,165,20,165,"v",false,null,false);
   //var oMenuItem3 = oMenu3.addItem("design",0,0,0,"design.htm");
   //oMenuItem3.setMenuItemIcons("blank.gif","blank.gif","blank.gif","blank.gif",false);
   //oMenuItem3 = oMenu3.addItem("biography",0,0,0,"biography.htm");
   //oMenuItem3.setMenuItemIcons("blank.gif","blank.gif","blank.gif","blank.gif",false);
   //oMenuItem3 = oMenu3.addItem("vision statement",0,0,0,"vision.htm");
   //oMenuItem3.setMenuItemIcons("blank.gif","blank.gif","blank.gif","blank.gif",false);
   //oMenu3 = oAboutUs.addSubMenu(oMenu3,true,true);
   // contact us contains no submenu
   // add sub-submenu to  the residential menu
   var oMenu5 = new Menu("residential",lTop,lLeft+235,0,140,20,140,"v",false,null,false);
   var oMenuItem4 = oMenu5.addItem("kitchens",0,0,0,"kitchens.htm");
   oMenuItem4.setMenuItemIcons("blank.gif","blank.gif","blank.gif","blank.gif",false);
   oMenuItem4 = oMenu5.addItem("bathrooms",0,0,0,"bathrooms.htm");
   oMenuItem4.setMenuItemIcons("blank.gif","blank.gif","blank.gif","blank.gif",false);
   oMenuItem4 = oMenu5.addItem("dining rooms",0,0,0,"diningrooms.htm");
   oMenuItem4.setMenuItemIcons("blank.gif","blank.gif","blank.gif","blank.gif",false);
   oMenu5 = oMenuRes.addSubMenu(oMenu5,true,true);  
   // generate the HTML code for the menu
   oMenu.setMenuItemStyle("menuitem","menuitemover","menuitemlink","menuitemtext",true,true);
   sHTML = oMenu.innerHTML(true,false,true);
   if (isIE && isMac){
     var otdMenuIEMac = document.getElementById("tdMenuIEMac");
     if (otdMenuIEMac) otdMenuIEMac.innerHTML = sHTML;
   }else{ 
     var otdMenu = document.getElementById("tdmenu");
     if (otdMenu) otdMenu.innerHTML = sHTML;
   }
   if (!isNN)  resizePage(false);
   return
}

//reloads the window if Nav4 resized. Assumes that browserVersion() has already been called.
function resizePage(init) {  
  var oMenu
  var lTop,lIndex,lCoords,force

  if (init==true){
    with (navigator) {
      if (isNN4) { document.MM_pgW=innerWidth; document.MM_pgH=innerHeight }
      onresize=resizePage
    }
  }else{
    // NN4
    if (isNN4){
      if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
      return 
    }
    // in all the other cases just reload the menus
    oMenu = FindMenu(1)
    if (oMenu){
	  lCoords = getMenuTop()
	  lTop = lCoords[0]
	  with (oMenu){
	    // update ui, we don't move the submenus in this case, since submenu positions
	    // are not calculated from the root menu positions, submenus use their own
	    // own menu positions, hence they have to be moved separately
	    if (top != lTop) { move(lTop,"same",true,false) }
	  }
	  oMenu = null
	  for (lIndex = 2; lIndex < 6; lIndex++){
	    oMenu = FindMenu(lIndex)
	    if (oMenu){
		  with (oMenu){
		    if (top != lTop)  { move(lTop,"same",true,false)  }
		  }
		  oMenu = null
	    }
	  }
    }
  }
  return
}
