/* 
============================================================================
HAIRY DOG DIGITAL, INC.
www.hairydogdigital.com // info@hairydogdigital.com
----------------------------------------------------------------------------
project: 16507
 client: Arete Asset Management
  title: web site
   date: May 2008
----------------------------------------------------------------------------
Except where explicitly stated otherwise, all source code for this project,
including, but not limited to source code  written in HTML, XHTML, XML, CSS,
JavaScript, Java, ActionScript (Flash), PHP, MySQL, and Lingo (Director) 
is the property of and copyright (C) 2004-2008 by Hairy Dog Digital, Inc. 
All rights reserved. You are not permitted to use, reverse engineer, or 
otherwise adapt or modify this code for other projects and purposes without 
the expression written consent of Hairy Dog Digital, Inc. 
============================================================================
*/

var debug = false;

var navbarAnchorIds = new Array();
var navbarAnchorHrefs = new Array();

window.onload = function() {
	if (debug) alert("document.URL = " + document.URL);
	populateNavbarArrays();
	hiliteNavbarSelection();
}

function populateNavbarArrays() {
	theNavBarDiv = document.getElementById('body-navbar');
	if (!theNavBarDiv) return false;
	goThroughDOMStart('body-navbar');
}

function goThroughDOMStart(objId) {
	var obj = document.getElementById(objId);
	var lvl = 0;
	goThroughDOM(obj, lvl);
}

function goThroughDOM(obj, lvl) {
	for (var i=0; i<obj.childNodes.length; i++) {
		var childObj = obj.childNodes[i];
		if (childObj.nodeType == 1 && childObj.nodeName == 'A') {
			navbarAnchorIds.push(childObj.id);
			navbarAnchorHrefs.push(childObj.href);
		}
		goThroughDOM(childObj, lvl + 1);
	}
}

function hiliteNavbarSelection() {
	var targetAnchor = new Object();
	var targetDivId = new String();
	
	for (i=0; i<navbarAnchorHrefs.length; i++) {
		if (navbarAnchorHrefs[i] == window.location.href) {
			targetAnchor = document.getElementById(navbarAnchorIds[i]);
			
			if (debug) alert("found matching anchor href: " + navbarAnchorHrefs[i]);
			
			if (targetAnchor.className == "hiliteParentLink") {
				newTargetAnchorId = targetAnchor.id.substring(0,targetAnchor.id.length-2);
				if (debug) alert("new target anchor ID = " + newTargetAnchorId);
				targetAnchor = document.getElementById(newTargetAnchorId);
			}
			targetAnchor.setAttribute("class","hilited");
			targetAnchor.setAttribute("className","hilited");
			if (debug) alert(typeof targetAnchor.id);
			if (targetAnchor.id.length >= 9) {  // length of top level navbar <a> element IDs
				targetDivId = "navdiv" + targetAnchor.id.substr(7,2);
				if (debug) alert("targetDivId = " + targetDivId);
				if (document.getElementById(targetDivId)) document.getElementById(targetDivId).style.display = "block";
	
			}
			break;
		}
	}
}


