// menus code for www.extreme-java.de
//
// (c) 2001 Andreas Heilwagen <andreas.heilwagen@acm.org>
// (c) 2002 Heike


// global vars

menuoption      = 1;
submenuoption   = 1;
oldmenuoption   = 1;
menuloaded      = 0;
submenuloaded   = 0;

prefix          = '..';
submenus        = new Array ();

empty           = new Image ();
selector        = new Image ();
home            = new Image ();
junitx          = new Image ();
xptools         = new Image ();
jideal          = new Image ();
misc            = new Image ();
homesel         = new Image ();
junitxsel       = new Image ();
xptoolssel      = new Image ();
jidealsel       = new Image ();
miscsel         = new Image ();


// setter

function setMenuVars (newmenuoption, newsubmenuoption, newprefix)
{
  menuoption    = newmenuoption;
  submenuoption = newsubmenuoption;
  prefix        = newprefix;

}


// load and/or refresh menus

function setMenus (newmenuoption, newsubmenuoption, newprefix)
{
  setMenuVars (newmenuoption, newsubmenuoption, newprefix)
  if (menuloaded == 0)
    menuloaded = 1;
  else 
  {
    if (oldmenuoption != menuoption)
    {
      top.window.frames[1].location.href = submenus[menuoption];
      refreshMenu (menuoption);
    }
    else 
    {
      refreshMenu (menuoption);
      refreshSubmenu ();
    }
  }
}


// initialize variables

function initialize (pref)
{
  home           = new Image ();
  junitx         = new Image ();
  xptools        = new Image ();
  jideal         = new Image ();
  misc           = new Image ();
  homesel        = new Image ();
  junitxsel      = new Image ();
  xptoolssel     = new Image ();
  jidealsel      = new Image ();
  miscsel        = new Image ();
 

  home.src       = pref + "/images/menu/menu-home.jpg";
  junitx.src     = pref + "/images/menu/menu-junitx.jpg";
  xptools.src    = pref + "/images/menu/menu-xptools.jpg";
  jideal.src     = pref + "/images/menu/menu-jideal.jpg";
  misc.src       = pref + "/images/menu/menu-misc.jpg";
  homesel.src    = pref + "/images/menu/menu-home-selected.jpg";
  junitxsel.src  = pref + "/images/menu/menu-junitx-selected.jpg";
  xptoolssel.src = pref + "/images/menu/menu-xptools-selected.jpg";
  jidealsel.src  = pref + "/images/menu/menu-jideal-selected.jpg";
  miscsel.src    = pref + "/images/menu/menu-misc-selected.jpg";
}


function initializeSubmenu(pref) 
{
  if (submenuloaded == 0 )
  {
    submenuloaded  = 1;
    baseurl        = top.window.frames[0].location.pathname;
    lastslash      = baseurl.lastIndexOf ('/');
    prefixurl      = baseurl.substring (0, lastslash) + '/' + pref + '/';

    submenus       = new Array ();
    submenus[1]    = prefixurl + "home/submenu.html";
    submenus[2]    = prefixurl + "junitx/submenu.html";
    submenus[3]    = prefixurl + "xptools/submenu.html";
    submenus[4]    = prefixurl + "jideal/submenu.html";
    submenus[5]    = prefixurl + "misc/submenu.html";

    selector       = new Image ();
    empty          = new Image ();
    selector.src   = pref + "/images/menu/submenu-selector.jpg"
    empty.src      = pref + "/images/menu/submenu-empty.jpg"
  }
}
  


function refreshMenu (option)
{
  menuoption    = option;
  oldmenuoption = menuoption;
  selectmenu (option);      
  
}


function unselectmenu ()
{
  top.frames[0].document.menu1.src = home.src;
  top.frames[0].document.menu2.src = junitx.src;
  top.frames[0].document.menu3.src = xptools.src;
  top.frames[0].document.menu4.src = jideal.src;
  top.frames[0].document.menu5.src = misc.src;
}


function selectmenu (option)
{
  unselectmenu ();
       
  if (option == 0)
    option = menuoption;
          
  if (option == 1)
     top.frames[0].document.menu1.src = homesel.src;          
  if (option == 2)
    top.frames[0].document.menu2.src = junitxsel.src;          
  if (option == 3)
    top.frames[0].document.menu3.src = xptoolssel.src;          
  if (option == 4)
    top.frames[0].document.menu4.src = jidealsel.src;          
  if (option == 5)
    top.frames[0].document.menu5.src = miscsel.src;          
}


function refreshSubmenu ()
{
  selectsubmenu (submenuoption);
}


function unselectsubmenu ()
{
  top.frames[1].document.option1.src  = empty.src;
  top.frames[1].document.option2.src  = empty.src;
  top.frames[1].document.option3.src  = empty.src;
  top.frames[1].document.option4.src  = empty.src;
  top.frames[1].document.option5.src  = empty.src;
  top.frames[1].document.option6.src  = empty.src;
  top.frames[1].document.option7.src  = empty.src;
  top.frames[1].document.option8.src  = empty.src;
  top.frames[1].document.option9.src  = empty.src;
  top.frames[1].document.option10.src = empty.src;
  top.frames[1].document.option11.src = empty.src;
  top.frames[1].document.option12.src = empty.src;
}


function selectsubmenu (option)
{
  unselectsubmenu ();

  if (option == 0)
    option = submenuoption;

  if (option == 1)
     top.frames[1].document.option1.src = selector.src;          
  if (option == 2)
     top.frames[1].document.option2.src = selector.src;          
  if (option == 3)
     top.frames[1].document.option3.src = selector.src;          
  if (option == 4)
     top.frames[1].document.option4.src = selector.src;          
  if (option == 5)
     top.frames[1].document.option5.src = selector.src;          
  if (option == 6)
     top.frames[1].document.option6.src = selector.src;          
  if (option == 7)
     top.frames[1].document.option7.src = selector.src;          
  if (option == 8)
     top.frames[1].document.option8.src = selector.src;          
  if (option == 9)
     top.frames[1].document.option9.src = selector.src;          
  if (option == 10)
     top.frames[1].document.option10.src = selector.src;          
  if (option == 11)
     top.frames[1].document.option11.src = selector.src;          
  if (option == 12)
     top.frames[1].document.option12.src = selector.src;          
}
