var gevt = null ;
var gevtsub = null ;
var target = null ;
var subtarget = null ;

var DELAY = 1000 ;
var SHOWDELAY = 200 ;

var timerID = null ;
var timerIDSub = null ;
var currentMenu = null ;
var currentItem = null ;

var menuTimerID = null ;
var menuSubTimerID = null ;

var currentSubMenu = null ;
var currentSubItem = null ;

var menuNames = new Array() ;


menuNames["Fasteners"]                                  = "menuFast" ;
menuNames["Industrial Fasteners"]                       = "menuFast" ;
menuNames["Timber"]                                     = "menuTimb" ;
menuNames["Paints"]                                     = "" ;
menuNames["Sealants & Adhesives"]                       = "" ;
menuNames["Aluminium"]                                  = "menuAlum" ;
menuNames["Aluminium Sheets & Sections"]                = "menuAlum" ;
menuNames["Door Locking Gear & Gaskets"]                = "menuDoor" ;
menuNames["Steel Plate & Sections"]                     = "menuSPlt" ;
menuNames["Steel Fabrications"]                         = "menuSFab" ;
menuNames["Skips"]                                      = "menuSkip" ;
menuNames["Welding Equipment & Consumables"]            = "menuWeld" ;
menuNames["Welding Equipment"]                          = "menuWeld" ;
menuNames["Cutting Equipment"]                          = "menuDCGE" ;
menuNames["Protective Clothing"]                        = "menuPClo" ;
menuNames["Flat-Rack Parts"]                            = "menuFRak" ;
menuNames["Corner Castings & Twistlocks"]               = "menuCast" ;
menuNames["Trailer Parts"]                              = "menuTrai" ;
menuNames["T.I.R. Lashings & Ancilliaries"]             = "" ;
menuNames["Cleaning Materials"]                         = "" ;
menuNames["Container Decals"]                           = "menuDeca" ;

menuNames["Container Corner Posts"]                     = "submCorn" ;
menuNames["Crossmembers"]                               = "submXmem" ;
menuNames["Container Panels"]                           = "submCorr" ;
menuNames["Container Roof Panels"]                      = "submRoof" ;
menuNames["NW Trailers, Henred Fruehauf"]               = "submNWTr" ;

menuNames["Contact Us"]                                 = "menuCont" ;

var menuItems = new Array() ;


menuItems["menuFast"] = [ "open-pop-rivets.html"   , "Open Pop Rivets",
                          "sealed-pop-rivets.html" , "Sealed Pop Rivets",
                          "avdelok.html"           , "Avdelok Pins & Collars",
                          "magnagrip.html"         , "Magnagrip Pins & Collars",
                          "magnalok.html"          , "Magnalok & Monobolts",
                          "floorscrews.html"       , "Floorscrews",
                          "avtainers.html"         , "Avtainers",
                          "setscrews.html"         , "Hexagon Setscrews, Nuts & Bolts"
                        ] ;

menuItems["menuTimb"] = [ "container-floor-panels.html" , "Container Floor Panels",
                          "container-floor-planks.html" , "Container Floor Planks",
                          "plywood-sheets.html"         , "Plywood Sheets",
                          "softwood-planks.html"        , "Softwood Flat-Rack Planks"
                        ] ;

menuItems["menuAlum"] = [ "aluminium-treadplate.html"   , "Aluminium Treadplate",
                          "plain-aluminium-sheets.html" , "Plain Aluminium Sheets",
                          "white-aluminium-sheets.html" , "White Aluminium Sheets",
                          "aluminium-sections.html"     , "Aluminium Sections"
                        ] ;

menuItems["menuDoor"] = [ "doorset.htm"             , "Door Gear Set - Forged Lever" ,
                          "flatlevr.htm"            , "Flat Lever (Alternative Parts)" ,
                          "container-hinges.html"   , "Container Hinges" ,
                          "drgasket.htm"            , "Door Gaskets" ,
                          "antiluce-fasteners.html" , "Antiluce Fasteners" ,
                          "sprgbolt.htm"            , "Spring Bolts" 
                        ] ;

menuItems["menuSPlt"] = [ "msplate.htm"            , "Mild Steel Plates",
                          "durbar-treadplate.html" , "Durbar Treadplate",
                          "galvsht.htm"            , "Galvanised Sheets",
                          "weldmesh.htm"           , "Galvanised Weldmesh",
                          "msround.htm"            , "Round Bar",
                          "mssquare.htm"           , "Square Bar",
                          "msflat.htm"             , "Flat Bar",
                          "chs.htm"                , "CHS Circular Hollow Section",
                          "shs.htm"                , "SHS Square Hollow Section",
                          "rhs.htm"                , "RHS Rectangular Hollow Section",
                          "msangle.htm"            , "RSA Rolled Steel Angles",
                          "rschnl.htm"             , "RSC Rolled Steel Channel",
                          "rsj.htm"                , "RSJ Rolled Steel Joists",
                          "ubeams.htm"             , "Universal Beams",
                          "ucolumns.htm"           , "Universal Columns"
                        ] ;

menuItems["menuSFab"] = [ "corrpanl.htm" , "Container Panels" ,
                          "cornpost.htm" , "Container Corner Posts" ,
                          "xmembers.htm" , "Crossmembers" ,
                          "sills.htm"    , "Front & Rear Sills" ,
                          "headers.htm"  , "Front & Rear Headers" ,
                          "flp.htm"      , "Fork Lift Pockets" ,
                          "btmrail.htm"  , "Bottom Rails" ,
                          "rprangle.htm" , "Repair Angles" ,
                          "goosenck.htm" , "Gooseneck Tunnel Section" ,
                          "container-conversion-kits.html" , "Container Conversion Kits"
                        ] ;

menuItems["menuSkip"] = [ "roro-containers.html" , "RORO Skip Containers" ,
                          "recycling-skips.html" , "Recycling Skips" ,
                          "builders-skips.html"  , "Builders Skips"
                        ] ;

menuItems["submCorn"] = [ "shape2.htm"   , "Standard Shape 2 Front Post" , 
                          "shape1.htm"   , "Standard Shape 1 Front Post" ,
                          "modshp1.htm"  , "Modified Shape 1 Front Post" ,
                          "multbend.htm" , "Shape 29 Multi Bend Post" ,
                          "rearpost.htm" , "Standard Rear Post"
                        ] ;

menuItems["submXmem"] = [ "evenchan.htm" , "Channel - Even Leg" , 
                          "oddchan.htm"  , "Channel - Odd Leg" ,
                          "zbearer.htm"  , "'Z' Section"
                        ] ;

menuItems["submCorr"] = [ "sidepanl.htm" , "Front & Side Wall Panels" ,
                          "decapanl.htm" , "Container Decal Panels",
                          "roofpanl.htm" , "Container Roof Panels"
                        ] ;

menuItems["submRoof"] = [ "roof3cor.htm" , "3 Flute Roof Panel" ,
                          "roof4cor.htm" , "4 Flute Roof Panel" ,
                          "roof5cor.htm" , "5 Flute Roof Panel"
                        ] ;

menuItems["menuWeld"] = [ "earth-clamps.html"      , "Earth Clamps" ,
                          "electrode-holders.html" , "Electrode Holders" ,
                          "mig-wire.html"          , "MIG Welding Wire" ,
                          "mig-torches.html"       , "MIG Welding Torches & Spares"
                        ] ;

menuItems["menuDCGE"] = [ "cuttips.htm"  , "Cutting Tips" ,
                          "welding-bottle-trolleys.html" , "Welding Bottle Trolleys" ,
                          "burngun.htm"  , "Cutting & Welding Guns" ,
                          "flintgun.htm" , "Flint Guns & Bottle Spanners" ,
                          "regulate.htm" , "Regulators & Flashback Arrestors"
                        ];

menuItems["menuPClo"] = [ "facemask.htm" , "Respirators" ,
                          "gloves.htm"   , "Gloves & Gauntlets" 
                        ] ;


menuItems["menuFRak"] = [ "nwtrail.htm"  , "NW Trailers, Henred Fruehauf" ,
                          "rmttrail.htm" , "R.M.T. Twistlock Assembly",
                          "pivotpin.htm" , "Headboard Pivot Pins"
                        ] ;

menuItems["submNWTr"] = [ "nwtpin.htm"   , "Twistlock Pin & Nut" ,
                          "topcam.htm"   , "Top Cam" ,
                          "bottcam.htm"  , "Bottom Cam"
                        ] ;

menuItems["menuCast"] = [ "castings.htm" , "Corner Castings" ,
                          "twist-locks.html" , "Container Trailer Twistlocks" ,
                          "stdcast.htm"  , "Standard ISO Casting Drawing" ,
                          "minicast.htm" , "Mini Casting Drawing" ,
                          "marine-twistlock.html" , "Marine Twistlock Drawing"
                        ] ;

menuItems["menuTrai"] = [ "sidegrds.htm"             , "Side Guards & Fittings",
                          "rubber-buffers.html"      , "Rubber Buffers",
                          "albumper.htm"             , "Aluminium Bumpers",
                          "sliding-roof-sheets.html" , "Sliding Roof Sheets",
                          "lockgear.htm"             , "Locking Gear & Hinges",
                          "foldstep.htm"             , "Folding Steps",
                          "toolbox.htm"              , "Plastic Toolboxes",
                          "restrain.htm"             , "Load Restraining Equipment",
                          "ratchet-straps.html"      , "Ratchet Straps",
                          "lashing-rings.html"       , "Lashing Rings",
                          "mudguard.htm"             , "Mudguards",
                          "mudflaps.htm"             , "Mudflaps"
                        ] ;


menuItems["menuDeca"] = [ "iddecals.htm" , "Container Identification Decals" ,
                          "wtdecals.htm" , "Container Door Weight Decals" ,
                          "htdecals.htm" , "Container Height Decals"
                        ] ;

menuItems["menuCont"] = [ "econtact.php"         , "Contact Us Online",
                          "contact.html"         , "Northwest Depot (Sales Office)",
                          "southeast-depot.html" , "Southeast Depot"
                        ] ;

function getOffsetTop ( currentMenu ) {

 if ( currentMenu.offsetParent.className == "popupmenu" ) {
  return currentMenu.parentNode.offsetTop - 1 ;
 }

 var nextParent = currentMenu.parentNode.offsetParent ;
 var totalOffsetTop = currentMenu.parentNode.offsetTop ;

 while ( nextParent ) {
  totalOffsetTop += nextParent.offsetTop ;
  nextParent = nextParent.offsetParent ;
 }

 return totalOffsetTop - 1 ;

}

function getOffsetLeft ( currentMenu ) {

 if ( currentMenu.offsetParent.className == "popupmenu" ) {
  return currentMenu.parentNode.offsetWidth ;
 }

 var nextParent = currentMenu.parentNode.offsetParent ;
 var totalOffsetLeft = currentMenu.parentNode.offsetLeft ;

 while ( nextParent ) {
  totalOffsetLeft += nextParent.offsetLeft ;
  nextParent = nextParent.offsetParent ;
 }

 return totalOffsetLeft + currentMenu.parentNode.offsetWidth ;

}

function stripSignPost ( str ) {

  var strSignPost = "You are here - "

  if ( str.substring(0,strSignPost.length) == strSignPost ) {
    return str.substring( strSignPost.length , str.length ) ;
  } else {
    return str ;
  }

}

function stripAmpersand ( str ) {

  var i = 0;
  var strNew = str ;

  while ( i < strNew.length) {
    i = strNew.indexOf( "amp;" )
    if ( i == -1 ) {
      break ;
    } else {
      strNew = strNew.substring( 0 , i ) + strNew.substring( i+4 , strNew.length ) ;
    }
  }

  return strNew ;

}





function initialise ( ) {

  if (document.getElementById) {
    var container = document.getElementById("leftpane");
    var operaOffset = 0 ;
    var home = document.getElementById("home");
    var products = document.getElementById("products");
    var info = document.getElementById("info");
    products.onmouseout = hideMenuDelay ;

    document.body.onclick = hideMenu ;

    if ( document.all ) {
      home = container.childNodes[0].childNodes[0];
      info = container.childNodes[0].childNodes[2];
      if ( !container.childNodes[0].childNodes[0] ) {
        home = container.childNodes[1].childNodes[1];
        info = container.childNodes[1].childNodes[5];
        operaOffset = 8 ;
      }
    } else {
      home = container.childNodes[1].childNodes[1];
      info = container.childNodes[1].childNodes[5];
    }

    home.onmouseout = hideMenuDelay ;
    info.onmouseout = hideMenuDelay ;

    var menuName = "" ;
    var menuObjects = [ home , products , info ] ;

    for ( menuObject in menuObjects ) {
      for ( i = 0 ; i < menuObjects[menuObject].childNodes.length ; i++ ) {
        node = menuObjects[menuObject].childNodes[i]

        if ( node.innerHTML ) {
          if ( node.title == "You are here" ) {
            node.title += " - " + stripAmpersand(node.innerHTML);
          } else {
            node.title = stripAmpersand(node.innerHTML);
          }
          menuName = menuNames[stripSignPost(node.title)] ;
          if ( menuName ) {
            newMenu = document.createElement("div") ;
            newMenu.className = "popupmenu" ;
            newMenu.id = menuName ;
            newMenu.style.display = "none" ;

            for ( j = 0 ; j < menuItems[menuName].length ; j++ ) {
              newItem = document.createElement("a") ;
              newItem.href= "/" + menuItems[menuName][j] ;
              newItem.style.width = node.parentNode.offsetWidth + "px" ;

              if ( menuNames[menuItems[menuName][j+1]] ) { 

                newMenu1 = document.createElement("div") ;
                newMenu1.className = "popupmenu" ;
                newMenu1.id = menuNames[menuItems[menuName][j+1]] ;
                newMenu1.style.display = "none" ;
                for ( k = 0 ; k < menuItems[menuNames[menuItems[menuName][j+1]]].length ; k++ ) {

                  newItem1 = document.createElement("a") ;

                  newItem1.href= "/" + menuItems[menuNames[menuItems[menuName][j+1]]][k] ;
                  newItem1.style.width = node.parentNode.offsetWidth + "px" ;

                  newText1 = document.createTextNode(menuItems[menuNames[menuItems[menuName][j+1]]][++k]) ;

                  newItem1.appendChild(newText1) ;
                  newItem1.title = stripAmpersand( newItem1.innerHTML ) ;
                  newItem1.onmouseover = clearDelay ;
                  newMenu1.appendChild( newItem1 ) ;

                } // end for

                newMenu1.style.left = document.body.offsetLeft + node.offsetLeft + node.offsetWidth + node.parentNode.offsetWidth + operaOffset + 7 + "px" ;

                if ( document.all ) {
                  newMenu1.style.top = container.offsetTop + document.body.offsetTop + node.offsetTop + "px" ;
                } else {
                  newMenu1.style.top = "0px" ;
                }

    
                newItem.onmouseover = showSubMenu ;

                newItem.onmouseout = hideSubMenuDelay ;

                newMenu1.onmouseover = clearAutoHide ;
                newMenu1.onmouseout = hideSubMenuDelay ;

                document.body.appendChild(newMenu1);

                if ( document.all ) {
                  node.onmouseout = clearMouseOver ;
                }
              }

              newItem.onmouseover = showSubMenu;
              j++;
              if ( menuNames[menuItems[menuName][j]] ) { 
                newText = document.createTextNode(menuItems[menuName][j]) ;
                newItem.appendChild(newText);
                //Add nav arrow
                newItem.innerHTML = '<span class="navarrow" title="' + menuItems[menuName][j] + '">»</span>' + newItem.innerHTML
              } else {
                newText = document.createTextNode(menuItems[menuName][j]) ;
                newItem.appendChild(newText);
              }

              newItem.id = menuItems[menuName][j];
              newItem.title = menuItems[menuName][j];
              newMenu.appendChild(newItem);
            }

if ( document.body.offsetTop == 0 ) {
operaOffset = 0 ;
}
            newMenu.style.left = document.body.offsetLeft + node.offsetLeft + node.offsetWidth + operaOffset + "px" ;

/*
            if ( document.all ) {
              newMenu.style.top = container.offsetTop + document.body.offsetTop + node.offsetTop - 1 + "px" ;
            } else {
              newMenu.style.top = node.offsetTop - 1 + "px" ;
            }
*/
	    if ( document.body.offsetTop != 0 ) {
              newMenu.style.top = container.offsetTop + document.body.offsetTop + node.offsetTop - 1 + "px" ;
	    } else {
              newMenu.style.top = node.offsetTop - 1 + "px" ;
 	    }


            //Add nav arrow
            node.innerHTML = '<span class="navarrow" title="' + node.title + '">»</span>' + node.innerHTML
    
            newMenu.onmouseover = clearAutoHide ;
            newMenu.onmouseout = hideMenuDelay ;

            document.body.appendChild(newMenu);

          }

          node.onmouseover = showMenu ;

          if ( document.all ) {
            node.onmouseout = clearMouseOver ;
          }

        }


      }
    }
  }
}

function clearMouseOver ( evt ) {

  if ( !evt ) { evt = window.event } ;

  var element = ( evt.target ) ? evt.target : evt.srcElement ;

  element.style.backgroundColor = "" ;
  element.style.color = "" ;

}

function showSubMenu ( evt ) {

  if ( menuSubTimerID ) { 
    window.clearInterval( menuSubTimerID ) ;
    menuSubTimerID = null ;
  }

  if ( evt ) { 
    subtarget = evt.target
  } else {
    subtarget = window.event.srcElement ;
  }


  if ( currentSubMenu ) {
    menuSubTimerID = window.setInterval(showSubMenuDelay , SHOWDELAY )
  } else {
    showSubMenuDelay( ) ;
  }
}

function showSubMenuDelay ( ) {

//  var evt = gevtsub ;

  if ( menuTimerID ) {
    window.clearInterval( menuTimerID ) ;
    menuTimerID = null ;
  }

  if ( menuSubTimerID ) {
    window.clearInterval( menuSubTimerID ) ;
    menuSubTimerID = null ;
  }

  if ( timerIDSub ) {
    window.clearInterval( timerIDSub ) ;
    timerIDSub = null ;
  }

  if ( subtarget == null ) { return ; }

  if ( currentSubMenu ) {
    currentSubMenu.style.display = "none" ;
    currentSubMenu = null ;
  }

  if ( currentSubItem ) {
    hilite ( currentSubItem , false ) ;
  }

  var element = subtarget ;
  subtarget = null ;
  
  currentSubItem = element ;

  if ( element.className == "current" ) {
    if ( document.all ) {
      element.style.backgroundColor = "#147" ;
      element.style.color = "#fff" ;
    }
  }

  var menuName = menuNames[ stripSignPost( element.title ) ] ;
  var menu = document.getElementById( menuName ) ;

  if ( menu ) {
    if ( element.className == "navarrow" ) {
      menu.style.top = element.parentNode.parentNode.offsetTop + element.parentNode.offsetTop + "px";
    } else {    
      menu.style.top = element.parentNode.offsetTop + element.offsetTop + "px";
    }
    menu.style.display = "block" ;
    currentSubMenu = menu ;
  }

}

function showMenu ( evt ) {

  if ( menuTimerID ) { 
    window.clearInterval( menuTimerID ) ;
    menuTimerID = null ;
  }

  if ( evt ) { 
    target = evt.target
  } else {
    target = window.event.srcElement ;
  }

  menuTimerID = window.setInterval(showMenuDelay , SHOWDELAY )

}

function showMenuDelay ( ) {

  var evt = gevt ;

  if ( timerID ) {
    window.clearInterval( timerID ) ;
    timerID = null ;
  }
  
  if ( target == null ) { return ; }
  
  if ( currentMenu ) {
    currentMenu.style.display = "none" ;
  }

  if ( currentItem ) {
    hilite ( currentItem , false ) ;
  }

  if ( currentSubMenu ) {
    currentSubMenu.style.display = "none" ;
  }

  if ( currentSubItem ) {
    hilite ( currentSubItem , false ) ;
  }

  var element = target ;
  target = null ;
  
  currentItem = element ;

  if ( element.className == "current" ) {
    if ( document.all ) {
      element.style.backgroundColor = "#147" ;
      element.style.color = "#fff" ;
    }
  }

  var menuName = menuNames[stripSignPost(element.title)] ;
  var menu = document.getElementById(menuName);

  if ( menu ) {
    menu.style.display = "block" ;
    currentMenu = menu ;
  }

}

function hideMenuDelay ( ) {

  if ( timerID ) { window.clearInterval( timerID ) }

  timerID = window.setInterval( hideMenu , DELAY ) ;

}

function hideSubMenuDelay ( ) {

  if ( timerIDSub ) { window.clearInterval( timerIDSub ) }

  timerIDSub = window.setInterval( hideSubMenu , DELAY ) ;

}

function clearAutoHide ( ) {

  hilite ( currentItem , true ) ;
  hilite ( currentSubItem , true ) ;

  if ( timerID ) {
    window.clearInterval( timerID ) ;
    timerID = null ;
  }

  if ( timerIDSub ) {
    window.clearInterval( timerIDSub ) ;
    timerIDSub = null ;
  }

}

function hideMenu ( ) {

  hilite( currentItem , false ) ;

  if ( currentSubMenu ) {
    currentSubMenu.style.display = "none" ;
    currentSubMenu = null ;
  }

  if ( currentMenu ) {
    currentMenu.style.display = "none" ;
    currentMenu = null ;
  }

  if ( timerID ) {
    window.clearInterval( timerID ) ;
    timerID = null ;
  }

}

function hideSubMenu ( ) {

  hilite( currentSubItem , false ) ;

  if ( currentSubMenu ) {
    currentSubMenu.style.display = "none" ;
  }

  if ( timerIDSub ) {
    window.clearInterval( timerIDSub ) ;
    timerIDSub = null ;
  }

  hideMenu( ) ;

}

function hilite( item , highlight ) {

  if ( item ) {
    if (item.className == "navarrow") { item = item.parentNode }
    if ( highlight ) {
      item.style.backgroundColor = "#147" ;
      item.style.color = "#fff" ;
    } else {
      item.style.backgroundColor = "" ;
      item.style.color = "" ;
    }
  }

}

function clearDelay ( ) {

  if ( menuSubTimerID ) {
    window.clearInterval( menuSubTimerID ) ;
    menuSubTimerID = null ;
  }

}




jElf.loadEvent(initialise);