
var isDOM = (document.getElementById ? true : false); 
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);
function getRef(id) {
if (isDOM) return document.getElementById(id);
if (isIE4) return document.all[id];
if (isNS4) return document.layers[id];
}
function getSty(id) {
return (isNS4 ? getRef(id) : getRef(id).style);
} 
// Hide timeout.
var popTimer = 0;
// Array showing highlighted menu items.
var litNow = new Array();
function popOver(menuNum, itemNum) {
clearTimeout(popTimer);
hideAllBut(menuNum);
litNow = getTree(menuNum, itemNum);
changeCol(litNow, 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 = parseInt(thisX + menu[targetNum][0].x);
top = parseInt(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 getTree(menuNum, itemNum) {

// Array index is the menu number. The contents are null (if that menu is not a parent)
// or the item number in that menu that is an ancestor (to light it up).
itemArray = new Array(menu.length);

while(1) {
itemArray[menuNum] = itemNum;
// If we've reached the top of the hierarchy, return.
if (menuNum == 0) return itemArray;
itemNum = menu[menuNum][0].parentItem;
menuNum = menu[menuNum][0].parentMenu;
   }
}

// Pass an array and a boolean to specify color change, true = over color.
function changeCol(changeArray, isOver) {
for (menuCount = 0; menuCount < changeArray.length; menuCount++) {
if (changeArray[menuCount]) {
newCol = isOver ? menu[menuCount][0].overCol : menu[menuCount][0].backCol;
// Change the colours of the div/layer background.
with (menu[menuCount][changeArray[menuCount]].ref) {
if (isNS4) bgColor = newCol;
else backgroundColor = newCol;
         }
      }
   }
}
function hideAllBut(menuNum) {
var keepMenus = getTree(menuNum, 1);
for (count = 0; count < menu.length; count++)
if (!keepMenus[count])
menu[count][0].ref.visibility = 'hidden';
changeCol(litNow, false);
}

// *** MENU CONSTRUCTION FUNCTIONS ***

function Menu(isVert, popInd, x, y, width, overCol, backCol, borderClass, textClass) {
// True or false - a vertical menu?
this.isVert = isVert;
// The popout indicator used (if any) for this menu.
this.popInd = popInd
// Position and size settings.
this.x = x;
this.y = y;
this.width = width;
// Colors of menu and items.
this.overCol = overCol;
this.backCol = backCol;
// The stylesheet class used for item borders and the text within items.
this.borderClass = borderClass;
this.textClass = textClass;
// Parent menu and item numbers, indexed later.
this.parentMenu = null;
this.parentItem = null;
// Reference to the object's style properties (set later).
this.ref = null;
}

function Item(text, href, frame, length, spacing, target) {
this.text = text;
this.href = href;
this.frame = frame;
this.length = length;
this.spacing = spacing;
this.target = target;
// Reference to the object's style properties (set later).
this.ref = null;
}

function writeMenus() {
if (!isDOM && !isIE4 && !isNS4) return;

for (currMenu = 0; currMenu < menu.length; currMenu++) with (menu[currMenu][0]) {
// Variable for holding HTML for items and positions of next item.
var str = '', itemX = 0, itemY = 0;

// Items start from 1 in the array (0 is menu object itself, above).
// Also use properties of each item nested in the other with() for construction.
for (currItem = 1; currItem < menu[currMenu].length; currItem++) with (menu[currMenu][currItem]) {
var itemID = 'menu' + currMenu + 'item' + currItem;

// The width and height of the menu item - dependent on orientation!
var w = (isVert ? width : length);
var h = (isVert ? length : width);

// Create a div or layer text string with appropriate styles/properties.
// Thanks to Paul Maden (www.paulmaden.com) for helping debug this in IE4, apparently
// the width must be a miniumum of 3 for it to work in that browser.
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 + '" ';

// Add mouseover handlers and finish div/layer.
str += 'onMouseOver="popOver(' + currMenu + ',' + currItem + ')" onMouseOut="popOut(' + currMenu + ',' + currItem + ')">';

// Add contents of item (default: table with link inside).
// In IE/NS6+, add padding if there's a border to emulate NS4's layer padding.
// If a target frame is specified, also add that to the <a> tag.

str += '<table width="' + (w - 8) + '" border="0" cellspacing="0" cellpadding="' + (!isNS4 && borderClass ? 3 : 0) + '"><tr><td align="left" height="' + (h - 7) + '">' + '<a class="' + textClass + '" href="' + href + '"' + (frame ? ' target="' + frame + '">' : '>') + text + '</a></td>';
if (target > 0) {

// Set target's parents to this menu item.
menu[target][0].parentMenu = currMenu;
menu[target][0].parentItem = currItem;

// Add a popout indicator.
if (popInd) str += '<td class="' + textClass + '" align="right">' + popInd + '</td>';
}
str += '</tr></table>' + (isNS4 ? '</layer>' : '</div>');
if (isVert) itemY += length + spacing;
else itemX += length + spacing;
}
if (isDOM) {
var newDiv = document.createElement('div');
document.getElementsByTagName('body').item(0).appendChild(newDiv);
newDiv.innerHTML = str;
ref = newDiv.style;
ref.position = 'absolute';
ref.visibility = 'hidden';
}

// Insert a div tag to the end of the BODY with menu HTML in place for IE4.
if (isIE4) {
document.body.insertAdjacentHTML('beforeEnd', '<div id="menu' + currMenu + 'div" ' + 'style="position: absolute; visibility: hidden">' + str + '</div>');
ref = getSty('menu' + currMenu + 'div');
}

// In NS4, create a reference to a new layer and write the items to it.
if (isNS4) {
ref = new Layer(0);
ref.document.write(str);
ref.document.close();
}

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(menu[0][0]) {
ref.left = x;
ref.top = y;
ref.visibility = 'visible';
   }
}

// Syntaxes: *** START EDITING HERE, READ THIS SECTION CAREFULLY! ***
//
// menu[menuNumber][0] = new Menu(Vertical menu? (true/false), 'popout indicator', left, top,
// width, 'mouseover colour', 'background colour', 'border stylesheet', 'text stylesheet');
//
// Left and Top are measured on-the-fly relative to the top-left corner of its trigger, or
// for the root menu, the top-left corner of the page.
//
// menu[menuNumber][itemNumber] = new Item('Text', 'URL', 'target frame', length of menu item,
//  additional spacing to next menu item, number of target menu to popout);
//
// If no target menu (popout) is desired, set it to 0. Likewise, if your site does not use
// frames, pass an empty string as a frame target.
//
// Vertical Menu setup. You can see most menus below
// are 'true', that is they are vertical, except for the first root menu. The 'length' and
// 'width' of an item depends on its orientation -- length is how long the item runs for in
// the direction of the menu, and width is the lateral dimension of the menu. Just look at
// the examples and tweak the numbers, they'll make sense eventually :).

var menu = new Array();

// Default colors passed to most menu constructors (just passed to functions, not
// a global variable - makes things easier to change later in bulk).
var defOver = '#C8D3C8', defBack = '#f4f4f4';

// Default 'length' of menu items - item height if menu is vertical, width if horizontal.
var defLength = 22;

// Menu 0 is the special, 'root' menu from which everything else arises.
menu[0] = new Array();
// A non-vertical menu with a few different colors and no popout indicator, as an example.
// *** MOVE ROOT MENU AROUND HERE ***  it's positioned at (5, 0) and is 17px high now.
//  accross down hight in px
menu[0][0] = new Menu(false, '',230, 168, 17, '#dbdbc8', '#f4f4f4', 'crazyBorder',  'crazyText');
// Targets are all set to nonzero values...
// The 'length' of each of this item is 80, and there is spacing of 3 to the next item.
// Most of the links are set to '#' hashes, Change them to actual files. Last Number is Menu #.

menu[0][1] = new Item('Home', 'Readme.asp', '', 35, 3, 0);
menu[0][2] = new Item('Blog', 'vLife.asp', '', 30, 3, 0);
menu[0][3] = new Item('Village Concept', '#', '', 90, 3, 14);
menu[0][4] = new Item('Why', '#', '', 30, 3, 17);
menu[0][5] = new Item('Status', '#', '', 40, 3, 4);
menu[0][6] = new Item('Reviews', '#', '', 50, 3, 13);
menu[0][7] = new Item('Book', '#', '', 32, 3, 7);
menu[0][8] = new Item('Apply', '#', '', 37, 3, 12);
menu[0][9] = new Item('Suburbia', '#', '', 50, 3, 18);
menu[0][10] = new Item('Who Are We', '#', '', 72, 3, 15);
menu[0][11] = new Item('Compare', '#', '', 50, 3, 19);
menu[0][12] = new Item('Links', '#', '', 30, 3, 8);


//  Blog
menu[1] = new Array();
menu[1][0] = new Menu(true, '*', 0, 35, 135, defOver, defBack, 'crazyBorder', 'crazyText');
menu[1][1] = new Item('Village Life / Economics', 'vlife.asp', '', defLength, 0, 0);
menu[1][2] = new Item('B.C.', 'vBC.asp', '', defLength, 0, 0);

// Buildings & Infrastructure
menu[2] = new Array();
menu[2][0] = new Menu(true, '*', 110, 0, 145, defOver, defBack, 'crazyBorder', 'crazyText');
menu[2][1] = new Item('Village Layout Design', 'villagelayout.asp', '', defLength, 0, 0);
menu[2][2] = new Item('Residential Bldgs', 'vResidential.asp', '', defLength, 0, 0);
menu[2][3] = new Item('Multi-Use Bldgs', 'vmultiusebldg.asp', '', defLength, 0, 0);


// Financial
menu[3] = new Array();
menu[3][0] = new Menu(true, '*', 110, 0, 145, defOver, defBack, 'crazyBorder', 'crazyText');
// Non-zero target means this will trigger a popout -- menu[6] which is the 'Reopen' menu.
menu[3][1] = new Item('Guarantee', 'vGuarantee.asp', '', defLength, 0, 0);
menu[3][2] = new Item('Cost to Each Resident', 'vResidentCost.asp', '', defLength, 0, 0);
menu[3][3] = new Item('Investor Information', 'vInvestor.asp', '', defLength, 0, 0);
menu[3][4] = new Item('Business Plan', 'vBusinessPlan.asp', '', defLength, 0, 0);
menu[3][5] = new Item('Legal Entities', '', '', defLength, 0, 9);
menu[3][6] = new Item('Legal Documents', '', '', defLength, 0, 10);


// Status of Projects
menu[4] = new Array();
menu[4][0] = new Menu(true, '*', 0, 35, 125, defOver, defBack, 'crazyBorder', 'crazyText');
menu[4][1] = new Item('First Village',   'vStatus.asp', '', defLength, 0, 0);
menu[4][2] = new Item('10,000 Villages', 'vStatus10000.asp', '', defLength, 0, 0);
menu[4][3] = new Item('2 Cores Completed', 'vCore.asp', '', defLength, 0, 0);

//  Governance
menu[5] = new Array();
// Leftwards popout with a negative x and y relative to its trigger.
// Leftwards!<br>And up!
menu[5][0] = new Menu(true, '*', 110, 0, 145, defOver, defBack, 'crazyBorder', 'crazyText');
menu[5][1] = new Item('Governance Overview', 'vFocusOverview.asp', '', defLength, 0, 0);
menu[5][2] = new Item('In a Nutshell', 'vFocus_Area3.asp', '', defLength, 0, 0);
menu[5][3] = new Item('Work Groups Diagram', 'vFocus_Work2.htm', '', defLength, 0, 0);
menu[5][4] = new Item('Focus Groups - Long', 'vFocusMain.asp', '', defLength, 0, 0);
menu[5][5] = new Item('Consensus Phase-In', 'vFocusPhaseIn.asp', '', defLength, 0, 0);
menu[5][6] = new Item('Group Policies', 'vGroupPolicy1.asp', '', defLength, 0, 0);


// Human Element
menu[6] = new Array();
menu[6][0] = new Menu(true, '*', 110, 0, 145, defOver, defBack, 'crazyBorder', 'crazyText');
menu[6][1] = new Item('Calm Residents Down', 'vCalm.asp', '', defLength, 0, 0);
menu[6][2] = new Item('Live Together', 'vLiveTogether.asp', '', defLength, 0, 0);
menu[6][3] = new Item('Reach Consensus', 'vWaldo2.asp', '', defLength, 0, 0);
menu[6][4] = new Item('Spirituality', 'vSpirituality2.asp', '', defLength, 0, 0);

// Book Offer
menu[7] = new Array();
menu[7][0] = new Menu(true, '*', 0, 35, 90, defOver, defBack, 'crazyBorder', 'crazyText');
menu[7][1] = new Item('Free Book', 'vBook_Offer.asp', '', defLength, 0, 0);
menu[7][2] = new Item('Press Room', 'vPressRoom2.asp', '', defLength, 0, 0);

// Links
menu[8] = new Array();
menu[8][0] = new Menu(true, '*', 0, 35, 140, defOver, defBack, 'crazyBorder', 'crazyText');
menu[8][1] = new Item('Jack Reed', 'vjackreed.asp "', '', defLength, 0, 0);
menu[8][2] = new Item('Intentional Communities', 'http://www.ic.org/ " target="_blank', '', defLength, 0, 0);
menu[8][3] = new Item('ArkBuilder.org', 'http://www.just-stop.org " target="_blank', '', defLength, 0, 0);
menu[8][4] = new Item('Wake-Up Videos', 'vWakeUp.asp "', '', defLength, 0, 0);
menu[8][5] = new Item('Surviving Peak Oil', 'vSuburbiaLinks.asp " target="_blank', '', defLength, 0, 0);

// Legal Entities
menu[9] = new Array();
menu[9][0] = new Menu(true, '*',140, 0, 130, defOver, defBack, 'crazyBorder', 'crazyText');
menu[9][1] = new Item('Legal Organizations', 'vLegalOrgs.asp', '', defLength, 0, 0);
menu[9][2] = new Item('Community Land Trust', 'vCLT.asp', '', defLength, 0, 0);

// Legal Documents
menu[10] = new Array();
menu[10][0] = new Menu(true, '*',140, 0, 140, defOver, defBack, 'crazyBorder', 'crazyText');
menu[10][1] = new Item('Shareholders Agreement', 'vShareholder.asp', '', defLength, 0, 0);
menu[10][2] = new Item('By-Laws', 'vBy-Laws.asp', '', defLength, 0, 0);



// Focus Groups (Unused at this time)
menu[11] = new Array();
// This is across but not down... a horizontal popout (with crazy stylesheets :)...
menu[11][0] = new Menu(true, '*', 0, 35, 160, defOver, defBack,'crazyBorder', 'crazyText');
// These items are lengthier than normal, and have extra spacing due to the fancy borders.
menu[11][1] = new Item('Beautify Environment', 'http://www.co-opvillagefoundation.org/readme.asp', '', defLength, 0, 0);
menu[11][2] = new Item('Bring Forth Inner Wisdom', 'http://www.co-opvillagefoundation.org/readme.asp', '', defLength, 0, 0);
menu[11][3] = new Item('Communicate', 'http://www.co-opvillagefoundation.org/readme.asp', '', defLength, 0, 0);
menu[11][4] = new Item('Coordinate what we love to do', 'http://www.co-opvillagefoundation.org/readme.asp', '', defLength, 0, 0);
menu[11][5] = new Item('Enjoy Ourselves', 'http://www.co-opvillagefoundation.org/readme.asp', '', defLength, 0, 0);
menu[11][6] = new Item('Enrich Ourselves', 'http://www.co-opvillagefoundation.org/readme.asp', '', defLength, 0, 0);
menu[11][7] = new Item('Expand Our Community', 'http://www.co-opvillagefoundation.org/readme.asp', '', defLength, 0, 0);
menu[11][8] = new Item('Interact with Environment', 'http://www.co-opvillagefoundation.org/readme.asp', '', defLength, 0, 0);
menu[11][9] = new Item('Nourish Ourselves', 'http://www.co-opvillagefoundation.org/readme.asp', '', defLength, 0, 0);
menu[11][10] = new Item('Reach Consensus', 'http://www.co-opvillagefoundation.org/readme.asp', '', defLength, 0, 0);
menu[11][11] = new Item('Share Our Abundance', 'http://www.co-opvillagefoundation.org/readme.asp', '', defLength, 0, 0);
menu[11][12] = new Item('Vitalize Ourselves', 'http://www.co-opvillagefoundation.org/readme.asp', '', defLength, 0, 0);

// Apply Offer
menu[12] = new Array();
menu[12][0] = new Menu(true, '*', 0, 35, 140, defOver, defBack, 'crazyBorder', 'crazyText');
menu[12][1] = new Item('Application Process', 'vResidence.asp', '', defLength, 0, 0);
menu[12][2] = new Item('Apply Early', 'vApplyEarly.asp', '', defLength, 0, 0);
menu[12][3] = new Item('Admittance Flow Chart', 'vAdmittance.asp', '', defLength, 0, 0);
menu[12][4] = new Item('Eviction Flow Chart', 'vEviction.asp', '', defLength, 0, 0);

  //  Endorsements
menu[13] = new Array();
menu[13][0] = new Menu(true, '*', 0, 35, 140, defOver, defBack, 'crazyBorder', 'crazyText');
menu[13][1] = new Item('Holy Grail', 'vholygrail.asp', '', defLength, 0, 0);
menu[13][2] = new Item('Peer Reviews', 'vPeer.asp', '', defLength, 0, 0);
menu[13][3] = new Item('Reader Reviews', 'vReaderReview.asp', '', defLength, 0, 0);

// Apply Offer
menu[14] = new Array();
menu[14][0] = new Menu(true, '*', 0, 35, 110, defOver, defBack, 'crazyBorder', 'crazyText');
menu[14][1] = new Item('Prospectus / Plan', 'vprospectus.asp', '', defLength, 0, 0);
menu[14][2] = new Item('Buildings', '#', '', 30, 3, 2);
menu[14][3] = new Item('Infrastructure', '#', '', 30, 3, 16);
menu[14][4] = new Item('Financial', '#', '', 30, 3, 3);
menu[14][5] = new Item('Governance', '#', '', 30, 3, 5);
menu[14][6] = new Item('Human Element', '#', '', 30, 3, 6);

// Profiles
menu[15] = new Array();
menu[15][0] = new Menu(true, '*', 0, 35, 140, defOver, defBack, 'crazyBorder', 'crazyText');
menu[15][1] = new Item('About Us', 'vaboutUs.asp', '', defLength, 0, 0);
menu[15][2] = new Item('Bios', 'vauthorbios.asp', '', defLength, 0, 0);
menu[15][3] = new Item('Contact Us', 'vContact.asp', '', defLength, 0, 0);

//  Infrastructure
menu[16] = new Array();
menu[16][0] = new Menu(true, '*', 110, 0, 145, defOver, defBack, 'crazyBorder', 'crazyText');
menu[16][1] = new Item('Physical', 'vPhysicalInfra.asp', '', defLength, 0, 0);
menu[16][2] = new Item('Non-Physical', 'vinfrastructure.asp', '', defLength, 0, 0);

//  Why
menu[17] = new Array();
menu[17][0] = new Menu(true, '*', 0, 35, 175, defOver, defBack, 'crazyBorder', 'crazyText');
menu[17][1] = new Item('. . Download Entire Module', 'vModWhy.mht', '', defLength, 0, 0);
menu[17][2] = new Item('B. Kennedy & M. L. King', 'vBKennedy.asp', '', defLength, 0, 0);
menu[17][3] = new Item('GLOBAL SOLUTION', 'vGlobalSolution.asp', '', defLength, 0, 0);
menu[17][4] = new Item('Power of Minus One', 'vMinusOne.asp', '', defLength, 0, 0);
menu[17][5] = new Item('B.C.', 'vBC.asp', '', defLength, 0, 0);

//  Suburbia
menu[18] = new Array();
menu[18][0] = new Menu(true, '*', 0, 35, 175, defOver, defBack, 'crazyBorder', 'crazyText');
menu[18][1] = new Item('Converting Current Home', 'vSuburbia.asp', '', defLength, 0, 0);
menu[18][2] = new Item('Retrofitting A Neighborhood', 'vSuburbiaHood.asp', '', defLength, 0, 0);
menu[18][3] = new Item('Recap: Humanmanure Handbook', 'vHumanmanure.asp', '', defLength, 0, 0);
menu[18][4] = new Item('Links - Surviving Peak Oil', 'vSuburbiaLinks.asp', '', defLength, 0, 0);
menu[18][5] = new Item('Final End or New Beginning?', 'vBeginningOrEnd.asp', '', defLength, 0, 0);

//  Compare
menu[19] = new Array();
menu[19][0] = new Menu(true, '*', 0, 35, 155, defOver, defBack, 'crazyBorder', 'crazyText');
menu[19][1] = new Item('Begin', 'vCompareA.asp', '', defLength, 0, 0);
menu[19][2] = new Item('Comparison Chart', 'Docs/CompareChart.pdf', '', defLength, 0, 0);
menu[19][3] = new Item('Compare - Narrative', 'vCompareN.asp', '', defLength, 0, 0);

// *** OPTIONAL CODE FROM HERE DOWN ***

// These two lines handle the window resize bug in NS4. See <body onResize="...">.
// I recommend you leave this here as otherwise when you resize NS4's width menus are hidden.

var popOldWidth = window.innerWidth;
nsResizeHandler = new Function('if (popOldWidth != window.innerWidth) location.reload()');


// This is a quick snippet that captures all clicks on the document and hides the menus
// every time you click. Use if you want.

if (isNS4) document.captureEvents(Event.CLICK);
document.onclick = clickHandle;

function clickHandle(evt)
{
 if (isNS4) document.routeEvent(evt);
 hideAllBut(0);
}


// <!-- *** IMPORTANT STYLESHEET SECTION - Change the border classes and text colors *** -->
// <!--  Can be added to html doc as needed

// .itemBorder { border: 1px solid black }
// .itemText { text-decoration: none; color: #000000; font: 12px Arial, Helvetica }

// .crazyBorder { border: 2px outset #663399 }
// .crazyText { text-decoration: none; color: #FFCC99; font: Bold 12px Arial, Helvetica }
// .footer {  font-family: Arial, Helvetica, sans-serif; font-size: small; font-style: normal; color: #000000}

// -->