var isDOM = (document.getElementById ? true : false); 
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);
var isDyn = (isDOM || isIE4 || isNS4);


function getRef(id)
{
 return (isDOM ? document.getElementById(id) :
  (isIE4 ? document.all[id] : document.layers[id]));
}

function getSty(id)
{
 return (isNS4 ? getRef(id) : getRef(id).style);
} 





var popTimer = 0;

var litNow = new Array();

function popOver(menuNum, itemNum)
{
 clearTimeout(popTimer);


 hideAllBut(menuNum);

 
 litNow = getTree(menuNum, itemNum);
 changeCol(true);

 
 targetNum = menu[menuNum][itemNum].target;
 if (targetNum > 0)
 {
  
  thisX = parseInt(menu[menuNum][0].ref.left) + parseInt(menu[menuNum][itemNum].ref.left);
  thisY = parseInt(menu[menuNum][0].ref.top) + parseInt(menu[menuNum][itemNum].ref.top);

  
  with (menu[targetNum][0].ref)
  {
   left = thisX + menu[targetNum][0].x;
   top = thisY + menu[targetNum][0].y;
   visibility = 'visible';
  }
 }
}

function popOut(menuNum, itemNum)
{
 
 
 if ((menuNum == 0) && !menu[menuNum][itemNum].target) hideAllBut(0);
 else popTimer = setTimeout('hideAllBut(0)', 500);
}

function popClick(menuNum, itemNum)
{
 with (menu[menuNum][itemNum])
 {
  switch (type)
  {
   
   case 'js:': { eval(href); break }
   
   case '': type = 'window';
   default: if (href) eval(type + '.location.href = "' + href + '"');
  }
 }

 
 hideAllBut(0);
}


function getTree(menuNum, itemNum)
{
 
 
 itemArray = new Array(menu.length);

 while(1)
 {
  itemArray[menuNum] = itemNum;
  
  if (menuNum == 0) break;
  itemNum = menu[menuNum][0].parentItem;
  menuNum = menu[menuNum][0].parentMenu;
 }
 return itemArray;
}



function changeCol(isOver)
{
 
 for (count = 0; count < litNow.length; count++)
 {
  
  if (litNow[count])
  {
   
   with (menu[count][0]) with (menu[count][litNow[count]])
   {
    newCol = isOver ? overCol : backCol;

    
    if (isNS4) ref.bgColor = newCol;
    else ref.backgroundColor = newCol;
   }
  }
 }
}

function hideAllBut(menuNum)
{
 
 var keepMenus = getTree(menuNum, 1);

 
 for (count = 0; count < menu.length; count++)
  if (!keepMenus[count] && menu[count]) menu[count][0].ref.visibility = 'hidden';

 
 changeCol(false);
}



function addProps(obj, data, names, addNull)
{
 for (i = 0; i < names.length; i++)
  if(i < data.length || addNull) obj[names[i]] = data[i];
}


function Menu()
{
 var names = ['isVert', 'popInd', 'x','y', 'width', 'pad', 'overCol', 'backCol',
  'borderClass', 'textClass',      'parentMenu', 'parentItem', 'ref'];
 addProps(this, arguments, names, true);
}

function Item()
{
 var names = ['text', 'href', 'type', 'length', 'spacing', 'target',    'ref'];
 addProps(this, arguments, names, true);
}




function createMenus()
{
 if (!isDyn) return;

 
 for (currMenu = 0; currMenu < menu.length; currMenu++)
 if (menu[currMenu]) with (menu[currMenu][0])
 {
  
  var str = '', itemX = 0, itemY = 0;

  
  if (isNS4) pad++;

  
  for (currItem = 1; currItem < menu[currMenu].length; currItem++) with (menu[currMenu][currItem])
  {
   var itemID = 'menu' + currMenu + 'item' + currItem;

   
   var shrink = (borderClass && isDOM && !document.all ? 2 : 0)
   var w = (isVert ? width : length) - shrink;
   var h = (isVert ? length : width) - shrink;

   
   if (isDOM || isIE4)
   {
    str += '<div id="' + itemID + '" style="position: absolute; left: ' + itemX +
     '; top: ' + itemY + '; width: ' + w + '; height: ' + h + '; visibility: inherit; ';
    if (backCol) str += 'background: ' + backCol;
    str += '" ';
   }
   if (isNS4)
   {
    str += '<layer id="' + itemID + '" left="' + itemX + '" top="' + itemY + '" width="' + 
     w + '" height="' + h + '" visibility="inherit" ';
    if (backCol) str += 'bgcolor="' + backCol + '" ';
   }
   if (borderClass) str += 'class="' + borderClass + '" ';
   
   
   str += 'onMouseOver="popOver(' + currMenu + ',' + currItem + ')" onMouseOut="popOut(' +
     currMenu + ',' + currItem + ')" onClick="popClick(' + currMenu + ',' + currItem + ')">';



   

   if (target > 0)
   {
    // Set target's parents to this menu item.
    menu[target][0].parentMenu = currMenu;
    menu[target][0].parentItem = currItem;

    
    if (popInd)
    {
     if (isNS4) str += '<layer class="' + textClass + '" left="'+ (w - 15) + '" top="' +
      pad + '">' + popInd + '</layer>';
     else str += '<div class="' + textClass + '" style="position: absolute; left: ' + (w - 15) +
      '; top: ' + pad + '">' + popInd + '</div>';
    }
   }

   
   if (isNS4) str += (borderClass ? '<spacer type="block" width="' + (w - 8) + '" height="' +
    (h - 8) + '">' : '') +
    '<layer left="' + pad + '" top="' + pad + '" width="' + (w - (2 * pad)) + '" height="' +
    (h - (2 * pad)) + '"><a class="' + textClass + '" href="#" ' +
    'onClick="popClick(' + currMenu + ',' + currItem + '); return false" ' +
    'onMouseOver="status=\'\'; return true;">' + text + '</a></layer>';

   
   else str += '<div class="' + textClass + '" style="position: absolute; left: ' + pad +
    '; top: ' + pad + '; width: ' + (w - (2 * pad)) + '; height: ' + (h - (2 * pad)) +
    '">' + text + '</div>';

   
   str += (isNS4 ? '</layer>' : '</div>');

   
   if (isVert) itemY += length + spacing - 1;
   else itemX += length + spacing - 1;

  
  }



  
  if (document.all)
  {
   
   document.body.insertAdjacentHTML('beforeEnd', '<div id="menu' + currMenu + 'div" ' +
    'style="position: absolute; width: 3; height: 3; visibility: hidden; z-index: 1000">' +
     str + '</div>');
   ref = getSty('menu' + currMenu + 'div');
  }
  
  else if (isDOM)
  {
   var newDiv = document.createElement('div');
   document.body.appendChild(newDiv);
   newDiv.innerHTML = str;
   ref = newDiv.style;
    
   ref.position = 'absolute';
   ref.visibility = 'hidden';
  }
  
  else if (isNS4)
  {
   ref = new Layer(0);
   ref.document.write(str);
   ref.document.close();
  }

  
  ref.left = x;
  ref.top = y;
  
  if (!isNS4) ref.cursor = (document.all ? 'hand' : 'pointer');
  
  if (!document.all) ref.zIndex = 1000;

  
  for (currItem = 1; currItem < menu[currMenu].length; currItem++)
  {
   itemName = 'menu' + currMenu + 'item' + currItem;
   if (isDOM || isIE4) menu[currMenu][currItem].ref = getSty(itemName);
   if (isNS4)
   {
    menu[currMenu][currItem].ref = ref.document[itemName];
    
    with (ref.document[itemName])
    {
     document.captureEvents(Event.CLICK);
     document.onclick = new Function('popClick(' + currMenu + ', ' + currItem + ')');
    }
   }
  }

 
 }

 
 positionMenu()

 
 menu[0][0].ref.visibility = 'visible';
}



var menu = new Array();


var defOver = '#17308D', defBack = '#032953';


var defLen = 22;



menu[0] = new Array();

menu[0][0] = new Menu(false, '', 15, 120, 17, 0, '#17308D', '#032953', '', 'itemText');

menu[0][1] = new Item('&nbsp; Home', '../eng/default.asp', '', 90, 1, 0);
menu[0][2] = new Item('&nbsp; The Islands', '', 'nolink', 120, 1, 1);
menu[0][3] = new Item('&nbsp; Literature', '', 'nolink', 120, 1, 2);
menu[0][4] = new Item('&nbsp; Archives','', 'nolink', 120, 1, 3);
menu[0][5] = new Item('&nbsp; Finding Aids','', 'nolink', 145, 1, 4);
// menu[0][6] = new Item('&nbsp; Search','', 'nolink', 70, 1, 5);
// menu[0][7] = new Item('&nbsp; About','', 'nolink',110, 1, 6);
menu[0][6] = new Item('&nbsp; About','', 'nolink',110, 1, 6);

// The Islands
menu[1] = new Array();
menu[1][0] = new Menu(true, '&gt;', 0, 17, 200, 3, defOver, defBack, 'itemBorder', 'itemText');
menu[1][1] = new Item('History', '../eng/vi_hist.asp', '', defLen, 0, 0);
menu[1][2] = new Item('Highlights from the Archives', '../eng/high.asp', '', defLen, 0, 0);


// Litterature
menu[2] = new Array();
menu[2][0] = new Menu(true, '&gt;', 0, 17, 400, 3, defOver, defBack, 'itemBorder', 'itemText');
menu[2][1] = new Item('Introduction', '../eng/l_intro.asp', '', defLen, 0, 0);
menu[2][2] = new Item('Broad Treatments of Danish History', '../eng/l_dkhist.asp', '', defLen, 0, 0);
menu[2][3] = new Item('Broad Treatments of Danish West Indian History', '../eng/l_wihist.asp', '', defLen, 0, 0);
menu[2][4] = new Item('Newspapers', '../eng/l_news.asp', '', defLen, 0, 0);
menu[2][5] = new Item('Statistics', '../eng/l_stat.asp', '', defLen, 0, 0);
menu[2][6] = new Item('Bibliographies on Danish History', '../eng/l_biodk.asp', '', defLen, 0, 0);
menu[2][7] = new Item('Bibliographies on Danish West Indian History', '../eng/l_biowi.asp', '', defLen, 0, 0);
menu[2][8] = new Item('Guides to Danish Archives', '../eng/l_dkar.asp', '', defLen, 0, 0);
menu[2][9] = new Item('Guides to Danish Administrative History', '../eng/l_dkadm.asp', '', defLen, 0, 0);
menu[2][10] = new Item('Guides to The Administrative History of the Danish West Indies', '../eng/l_wiadm.asp', '', defLen, 0, 0);
menu[2][11] = new Item('Danish Terminology, Language, and Script', '../eng/l_dklan.asp', '', defLen, 0, 0);
menu[2][12] = new Item('Specific Aspects of Danish West Indian History', '../eng/l', 'nolink', defLen, 0, 11);




//Archives menu[3][2] = new Item('The Central Government', '/sa/omarkiverne/english/famhist/start.htm', 'nolink', defLen, 0, 12);

menu[3] = new Array();
menu[3][0] = new Menu(true, '&gt;', 0, 17, 170, 3, defOver, defBack, 'itemBorder', 'itemText');
menu[3][1] = new Item('Introduction', '../eng/a_intro.asp', '', defLen, 0, 0);
menu[3][2] = new Item('The central Government', '/sa/omarkiverne/english/famhist/writing.htm', 'nolink', defLen, 0, 12);
menu[3][3] = new Item('Topics of Interest', '/sa/omarkiverne/english/famhist/writing.htm', 'nolink', defLen, 0, 13);
menu[3][4] = new Item('West Indian Local Archives', '../eng/a_wila.asp', '', 20, 0, 0);



// Finding Aids
menu[4] = new Array();
menu[4][0] = new Menu(true, '&lt;', 0, 17, 145, 3, defOver, defBack, 'itemBorder', 'itemText');
menu[4][1] = new Item('Introduktion', '../eng/f_intro.asp', '', defLen, 0, 0);
menu[4][2] = new Item('Browse', '../eng/akt.asp', '', defLen, 0, 0);
// menu[4][3] = new Item('Search', '../eng/find.asp', '', defLen, 0, 0);


// Search
menu[5] = new Array();
menu[5][0] = new Menu(true, '&lt;', 0, 17, 110, 3, defOver, defBack, 'itemBorder', 'itemText');
menu[5][1] = new Item('Search', '/sa/omarkiverne/english/sweb.htm', '', defLen, 0, 0);
menu[5][2] = new Item('Advanced Search', '/sa/omarkiverne/english/sancestors.htm', '', defLen, 0, 0);
// menu[5][3] = new Item('DanPa', '/sa/omarkiverne/english/sdanpa.htm', '', defLen, 0, 0);

// About
menu[6] = new Array();
menu[6][0] = new Menu(true, '&lt;', 0, 17, 110, 3, defOver, defBack, 'itemBorder', 'itemText');
menu[6][1] = new Item('About', '../eng/about.asp', '', defLen, 0, 0);
// menu[6][2] = new Item('Site map', '/sa/omarkiverne/english/sancestors.htm', '', defLen, 0, 0);
// menu[6][3] = new Item('Contact', '/sa/omarkiverne/english/sdanpa.htm', '', defLen, 0, 0);
// menu[6][4] = new Item('Links', '../eng/links.asp', '', defLen, 0, 0);
menu[6][2] = new Item('Links', '../eng/links.asp', '', defLen, 0, 0);


// Undermenu Current Activity
// Leftwards popout with a negative x and y relative to its trigger.
menu[11] = new Array();
menu[11][0] = new Menu(true, '&gt;', 400, 2, 200, 3, defOver, defBack, 'itemBorder', 'itemText');
menu[11][1] = new Item('Religion and Education', '../eng/l_reledu.asp', '', 20, 0, 0);
menu[11][2] = new Item('Trade and Shipping', '../eng/l_trade.asp', '', 20, 0, 0);
menu[11][3] = new Item('Sugar Production and Economy', '../eng/l_sugar.asp', '', 20, 0, 0);
menu[11][4] = new Item('Slavery and the Slave Trade', '../eng/l_slave.asp', '', 20, 0, 0);
menu[11][5] = new Item('Emancipation', '../eng/l_eman.asp', '', 20, 0, 0);
menu[11][6] = new Item('Social and Cultural Conditions', '../eng/l_soc.asp', '', 20, 0, 0);
menu[11][7] = new Item('Language', '../eng/l_lang.asp', '', 20, 0, 0);
menu[11][8] = new Item('Art', '../eng/l_art.asp', '', 20, 0, 0);
menu[11][9] = new Item('Architecture', '../eng/l_arch.asp', '', 20, 0, 0);
menu[11][10] = new Item('Cartography and Landsurveying', '../eng/l_cart.asp', '', 20, 0, 0);
menu[11][11] = new Item('Legislation and Law Enforcement', '../eng/l_law.asp', '', 20, 0, 0);
menu[11][12] = new Item('Monetary System', '../eng/l_money.asp', '', 20, 0, 0);
menu[11][13] = new Item('Military Matters', '../eng/L_mil.asp', '', 20, 0, 0);
menu[11][14] = new Item('Biography', '../eng/l_bio.asp', '', 20, 0, 0);
menu[11][15] = new Item('The Sale of the Islands', '../eng/l_sale.asp', '', 20, 0, 0);
menu[11][16] = new Item('Source Editions', '../eng/l_source.asp', '', 20, 0, 0);

// Undermenu Archives - Central Government
// Leftwards popout with a negative x and y relative to its trigger.
menu[12] = new Array();
menu[12][0] = new Menu(true, '&gt;', 170, 0, 250, 3, defOver, defBack, 'itemBorder', 'itemText');
menu[12][1] = new Item('Introduction', '../eng/a_govern.asp', '', 20, 0, 0);
menu[12][2] = new Item('The West India and Guinea Company', '../eng/a_wicomp.asp', '', 20, 0, 0);
menu[12][3] = new Item('The Chamber of Revenue', '../eng/a_reven.asp', '', 20, 0, 0);
menu[12][4] = new Item('The Chamber of Customs', '../eng/a_cust.asp', '', 20, 0, 0);
menu[12][5] = new Item('The Central Directorate for the Colonies', '../eng/a_cent.asp', '', 20, 0, 0);

// Undermenu Archives - Topics of interest
// Leftwards popout with a negative x and y relative to its trigger.
menu[13] = new Array();
menu[13][0] = new Menu(true, '&gt;', 170, 0, 220, 3, defOver, defBack, 'itemBorder', 'itemText');
menu[13][1] = new Item('The Government', '../eng/a_cphgov.asp', '', 20, 0, 0);
menu[13][2] = new Item('Ecclesiastical and Educational Affairs', '../eng/a_eccedu.asp', '', 20, 0, 0);
menu[13][3] = new Item('The Legal System', '../eng/a_law.asp', '', 20, 0, 0);
menu[13][4] = new Item('The Military Administration', '../eng/a_mil.asp', '', 20, 0, 0);
menu[13][5] = new Item('Finance', '../eng/a_fin.asp', '', 20, 0, 0);
menu[13][6] = new Item('Trade and Industry', '../eng/a_trade.asp', '', 20, 0, 0);
menu[13][7] = new Item('Accounting and Auditing', '../eng/a_audit.asp', '', 20, 0, 0);
menu[13][8] = new Item('Statistics', '../eng/a_stat.asp', '', 20, 0, 0);
menu[13][9] = new Item('Social Conditions and Public Health', '../eng/a_soc.asp', '', 20, 0, 0);
menu[13][10] = new Item('Foreign Affairs', '../eng/a_fore.asp', '', 20, 0, 0);
menu[13][11] = new Item('Private Individuals', '../eng/a_privat.asp', '', 20, 0, 0);
menu[13][12] = new Item('Private Institutions', '../eng/a_inst.asp', '', 20, 0, 0);
menu[13][13] = new Item('The Manuscript Collection', '../eng/a_manus.asp', '', 20, 0, 0);
menu[13][14] = new Item('The Seals Collection', '../eng/a_seals.asp', '', 20, 0, 0);
menu[13][15] = new Item('The Maps and Drawings Collection', '../eng/a_maps.asp', '', 20, 0, 0);
menu[13][16] = new Item('Danica', '../eng/a_danica.asp', '', 20, 0, 0);
menu[13][17] = new Item('Other Repositories', 'a_other.asp', '', 20, 0, 0);


window.onload = createMenus;
window.onresize = resizeHandler;








var popOldWidth = window.innerWidth;
function resizeHandler()
{

 if (!menu[0][0].ref) return;
 
 if (isNS4 && popOldWidth != window.innerWidth) location.reload()

 positionMenu();
}

function positionMenu()
{
 

 //var winWidth = (document.all ? document.body.clientWidth : window.innerWidth)
 //menu[0][0].ref.left = (winWidth / 2) - 120;
 
 
}



function colItem()
{
 
 var names = ['text', 'href', 'type', 'length', 'spacing', 'overCol', 'backCol', 'target',
  'ref'];
 addProps(this, arguments, names, true);
}




moveRoot = new Function('with(menu[0][0].ref) left = ((parseInt(left) < 100) ? 100 : 5);');
