//#############################################
// Title            custom nav for TNT 2.0
// Date             27/Feb/2003
// Author           Mehdi Nejad
// Description      Generic content managable dropdown navigation, goes down, then across (once)

// Altered by Inigo Surguy 06 June 2003 - there was an error in IE that
// where the menus would go, even if not visible, they were intercepting
// mouse events that should have gone to buttons underneath them.
// Fix was to add "display: none" alongside all the calls to "visibility: hidden"
// Search for 06Jun2003

// Altered by Inigo 11Aug2003 to make entire menu item active when
// mouseovered and clicked, not just text

// Bluewave comments I have marked with "BW" - Inigo

/******* OBJECT DEFINITIONS *******/

function Navigation () {
    this.instanceName = "";
    this.top = 0;
    this.left = 0;
    this.spacing = 0;
    this.childLevelItemWidth = 100;
    this.xSpacing = 0;
    this.ySpacing = 0;
    this.topLevelNavItemHeight = 0;
    this.topLevelBackgroundColour = "";
    this.topLevelLinkClass = "";
    this.childLevelLinkClass = "";
    this.childLevelBackgroundColour = "";
    this.childGroupParagraph = "";
    this.letterspacing = 2;
    this.lineHeight = 2;
    this.padding = 2;
    this.childLevelBorder = "";
    this.childLevelBorderColour = "";
    this.childLevelBorderWidth = 1;
    this.childShadowBodyColour = "";
    this.childShadowLineColour = "";
    this.childShadowDeltaX = 0;
    this.childShadowDeltaY = 0;
    this.centeringOffset = 0;
    this.topLevelNavItems = new Array();
    this.nextButtonCode = "";
    this.cellMouseOverColour = "";
    this.cellMouseOutColour = "";
    this.tableBorderColour = "#0000ff";
    this.leftSpacerImage = "";

}
Navigation.prototype.addTopLevelNavItem = fn_addTopLevelNavItem;
Navigation.prototype.addNavItem = fn_addNavItem;
Navigation.prototype.getTopLevelLength = fn_getTopLevelLength;
Navigation.prototype.close = fn_close;
Navigation.prototype.draw = fn_draw;
Navigation.prototype.drawOldBrowserVersion = fn_drawOldBrowserVersion;
Navigation.prototype.drawPlainTextVersion = fn_drawPlainTextVersion;
Navigation.prototype.positionNav = fn_positionNav;
Navigation.prototype.showLayer = fn_showLayer;
Navigation.prototype.destroy = fn_destroy;
Navigation.prototype.addNextButton = fn_addNextButton;
Navigation.prototype.getTopLevelXPosition = fn_getTopLevelXPosition;
Navigation.prototype.getNonTopLevelNavItem = fn_getNonTopLevelNavItem;
Navigation.prototype.drawLowerLevels = fn_drawLowerLevels;
Navigation.prototype.getLeftOfTopLevelPredecessors = fn_getLeftOfTopLevelPredecessors;
Navigation.prototype.closeThirdLevelNavItems = fn_closeThirdLevelNavItems;
Navigation.prototype.drawLowerLevelsOldVersion = fn_drawLowerLevelsOldVersion;
Navigation.prototype.changeParentElementBgColour = fn_changeParentElementBgColour;



function TopLevelNavItem (id, description, url, width) {
    this.id = id;
    this.description = description;
    this.url = url;
    this.width = width;
    this.navItems = new Array();
}
TopLevelNavItem.prototype.getNavItemLength = fn_getNavItemLength;
TopLevelNavItem.prototype.addChild = fn_addChild;

function NavigationItem (description, url) {
    this.id = 0; // unused - BW
    this.description = description;
    this.url = url;
    this.hasChild=false;
    this.navItems = new Array();
}

NavigationItem.prototype.addChild = fn_addChild2;

/******* OBJECT METHODS *******/

function fn_changeParentElementBgColour (childElement, colour) {
	if (childElement.parentNode.parentNode) {
		childElement.parentNode.parentNode.style.backgroundColor = colour;
	}
}

function fn_addChild2 (desc, url) {
	this.hasChild = true;
	this.navItems[this.navItems.length] = new NavigationItem(desc, url);
}

function fn_getNonTopLevelNavItem (id) {
    for (var i =0; i<this.getTopLevelLength(); i++) {
        topLevelObject = this.topLevelNavItems[i];
        for (var j=0; j<topLevelObject.getNavItemLength(); j++) {
            if (topLevelObject.navItems[j].description == id) {
				return topLevelObject.navItems[j];
            }
        }
    }
}

function fn_addNextButton (targetLevel) {
    for (var i =0; i<this.getTopLevelLength(); i++) {
        topLevelObject = this.topLevelNavItems[i];
        for (var j=0; j<topLevelObject.getNavItemLength(); j++) {
            if (topLevelObject.navItems[j].description == targetLevel) {
				topLevelObject.navItems[j].description += this.nextButtonCode;
            }
        }
        document.write ("<p>");
    }
}

function fn_destroy () {

    var objToDelete;

    for (var i=0; i<this.getTopLevelLength(); i++) {

        var parentObjName = this.topLevelNavItems[i].id; // a top Level nav item object - BW
        parentObjName;
		if (getObject (parentObjName)) {
            objToDelete = getObject (parentObjName);
            objToDelete = null;
        }

        if (getObject (parentObjName+"_child")) {
            objToDelete = getObject (parentObjName+"_child");
            objToDelete = null;
        }

        if (getObject (parentObjName+"_child_shadow")) {
            objToDelete = getObject (parentObjName+"_child_shadow");
            objToDelete = null;
        }
    }
}

function fn_showLayer (layerName) {
    if (getObject(layerName)) {
        showLayer (layerName);
    }
}
function fn_close () {

    for (var i=0; i<Nav.getTopLevelLength(); i++) {
        // in case there is child - 
        // need another loop in here to close other levels.. -BW
        if (getObject(Nav.topLevelNavItems[i].id + "_child")) {
            hideLayer(Nav.topLevelNavItems[i].id + "_child");

            // in case there is no shadow... -BW
            if (getObject(Nav.topLevelNavItems[i].id + "_child_shadow")) {
                hideLayer(Nav.topLevelNavItems[i].id + "_child_shadow");
            }
        }
       	this.closeThirdLevelNavItems();
    }

}

function fn_closeThirdLevelNavItems () { // name should change to "thirdLevel" -BW

	for (var i=0; i<this.getTopLevelLength(); i++) {
		topObj = this.topLevelNavItems[i]; // ok - got top level obj.  Loop through children -BW
		for (var j=0; j<topObj.navItems.length; j++) {
			var l2NavObj = topObj.navItems[j];
			if (l2NavObj.hasChild) {
				if (getObject (l2NavObj.description + "_child_shadow")) {
					hideLayer (l2NavObj.description + "_child_shadow");
				}
				if (getObject (l2NavObj.description + "_child")) {
					hideLayer (l2NavObj.description + "_child");
				}

			}
		}
	}
}

function fn_addChild (description, url) {
    this.navItems[this.navItems.length] = new NavigationItem (description, url);
}
function fn_getNavItemLength() {
    return this.navItems.length;
}
function fn_getTopLevelLength () {
    return this.topLevelNavItems.length;
}
function fn_addTopLevelNavItem(id, description, url, width) {
    this.topLevelNavItems[this.topLevelNavItems.length] = new TopLevelNavItem(id, description, url, width);
}
function fn_addNavItem (parentId, description, url) {
    for (var i =0; i<Nav.getTopLevelLength(); i++) {
        if (Nav.topLevelNavItems[i].id == parentId) {
            Nav.topLevelNavItems[i].addChild (description, url);
            return;
        }
    }
}
function fn_draw() {

    // Addition 11Aug2003
    var re = new RegExp("'", "gi");


    currentLeft = Nav.left;
    groupYPosition = this.top + this.topLevelNavItemHeight + this.ySpacing + this.padding;
    var objParent;
    var objChild;
    var tmp;
    for (var i =0; i<this.getTopLevelLength(); i++) {
        topLevelObject = this.topLevelNavItems[i];
        objParent = getObject (createLayer(topLevelObject.id));
        objParent.style.left = currentLeft +"px";
        objParent.style.top = this.top +"px";
        objParent.style.width = this.topLevelNavItems[i].width +"px";
        objParent.style.height = this.topLevelNavItemHeight +"px";
        objParent.style.visibility = "visible";
	// CHANGE BY INIGO 06Jun2003
        objParent.style.display = "block";
        objParent.style.backgroundColor = this.topLevelBackgroundColour;
        objParent.style.letterSpacing = this.letterSpacing +"px";
        objParent.style.zIndex = 1;
        objParent.innerHTML = "<a tabindex=\"2\" class=\"" + this.topLevelLinkClass + "\" href=\"" + topLevelObject.url + "\" onMouseOver=\"" + this.instanceName + ".close();"+this.instanceName+".showLayer('"+ topLevelObject.id +"_child');"+this.instanceName+".showLayer('"+ topLevelObject.id +"_child_shadow')\">" + topLevelObject.description + "</a>"

        if (topLevelObject.getNavItemLength() > 0) {

                objChild = getObject (createLayer(topLevelObject.id + "_child"));
                objChild.style.left = currentLeft +"px";
                objChild.style.top = groupYPosition + this.padding + "px";
                objChild.style.backgroundColor = this.childLevelBackgroundColour;
                objChild.style.width = Nav.childLevelItemWidth +"px";
                objChild.style.visibility = "visible";
	// CHANGE BY INIGO 06Jun2003
                objChild.style.display = "block";
                objChild.style.zIndex = 5;
                objChild.style.height = "auto";
                objChild.style.borderColor = this.childLevelBorderColour;
                objChild.style.borderStyle = this.childLevelBorder;
                objChild.style.borderWidth = this.childLevelBorderWidth +"px";

                var innerItemString = "<table width=\""+this.childLevelItemWidth+"\" cellpadding=\""+this.padding+"\" cellspacing=\"0\" class=\"tableouterline\">\n";
                var innerItemString_shadow = "<table cellpadding=\"0\" cellspacing=\"0\" class=\"tableouterlineshadow\">";



                for (var j=0; j<topLevelObject.getNavItemLength(); j++) {
                    navObject = topLevelObject.navItems[j];

					var myClass = "hastopline";
					if (j==0) {
						myClass = "notopline";
					}
					var colspanVar = "";
					var mouseOver = "";
					if (!navObject.hasChild) {
						mouseOver = "onMouseOver=\"" +this.instanceName+ ".closeThirdLevelNavItems(); this.style.background='"+this.cellMouseOverColour+"'\" onMouseOut=\"this.style.background='"+this.cellMouseOutColour+"';\"";
					} else {
						mouseOver = "onMouseOver=\"this.style.background='"+this.cellMouseOverColour+"';" +this.instanceName+ ".closeThirdLevelNavItems();" + this.instanceName + ".showLayer('"+navObject.description+"_child');showLayer('"+navObject.description+"_child_shadow');\" onMouseOut=\"this.style.background='"+this.cellMouseOutColour+"'\"";
					}

		    // style, onClick, and mouseOver added to support menu working even when not over text 11Aug2003
		var escapedURL = navObject.url.replace(re, "\\'");
                   innerItemString += "<tr style=\"cursor:hand\" onClick=\"window.location.href='"+escapedURL+"'\" "+mouseOver+">\n";
					innerItemString_shadow += "<tr>";


					if (navObject.hasChild) {
                    	innerItemString += "<td  class=\""+myClass+"\""+colspanVar+" width=\""+this.childLevelItemWidth+"\" height=\""+this.lineHeight+"\">"+this.leftSpacerImage+"<a class=\""+this.childLevelLinkClass+"\"href=\"" + navObject.url + "\" "+">" + this.nextButtonCode + navObject.description + "</a></td>\n";
					} else {
						innerItemString += "<td class=\""+myClass+"\" "+colspanVar+" height=\""+this.lineHeight+"\">"+this.leftSpacerImage+"<a class=\""+this.childLevelLinkClass+"\"href=\"" + navObject.url + "\" "+">" + navObject.description + "</a></td>\n";
					}
                    innerItemString_shadow += "<td class=\""+myClass+"_shadow\"height=\""+this.lineHeight+"\" width=\"" + this.childLevelItemWidth+ "\">&nbsp;</td>";
                    innerItemString += "</tr>";
                    innerItemString_shadow += "</tr>\n\n";

                }
                innerItemString += "</table>\n";


                innerItemString_shadow += "</table>";
				objChild.innerHTML = innerItemString;

               	objChildShadow = getObject (createLayer(topLevelObject.id + "_child_shadow"));
                objChildShadow.style.visibility = "hidden";
	// CHANGE BY INIGO 06Jun2003
                objChildShadow.style.display = "none";

                objChildShadow.style.left = currentLeft - this.childShadowDeltaX +"px";
                objChildShadow.style.top = groupYPosition + this.childShadowDeltaY + this.padding +"px";
                objChildShadow.style.width = Nav.childLevelItemWidth +"px";
                objChildShadow.style.zIndex = 4;
                objChildShadow.style.height = "auto";
                objChildShadow.style.borderWidth = 1 +"px";
                objChildShadow.style.letterSpacing = this.letterSpacing +"px";
                objChildShadow.style.borderColor = this.childShadowLineColour ;
                objChildShadow.style.borderStyle = "solid";
                objChildShadow.style.backgroundColor = this.childShadowBodyColour;
                objChildShadow.innerHTML = innerItemString_shadow;

        }


      currentLeft += this.topLevelNavItems[i].width + this.xSpacing;
    }

    this.drawLowerLevels();

    // a fix for ie 5 on Mac (last div drawn wrongly)
    objDummy = getObject (createLayer("IE5MacDiv"));
    objDummy.style.visibility = "hidden";
	// CHANGE BY INIGO 06Jun2003
    objDummy.style.display = "none";
    objDummy.style.height = "0px";
    objDummy.style.height = "0px";

}

function fn_getTopLevelXPosition (id) {
	alert ("am getting " + id);
}

function fn_getLeftOfTopLevelPredecessors (id) {
	// actually get the complete left, including specified border ! -BW
	var retVal = this.left;

	for (var i =0; i<this.getTopLevelLength(); i++) {
		topLevelObject = this.topLevelNavItems[i];
		if (topLevelObject.id == id) {
			retVal += this.childLevelItemWidth + this.childLevelBorderWidth;
			return retVal;
		}
		retVal += topLevelObject.width;
	}
	alert ("error could not complete function successfully");
}

function fn_drawLowerLevels() { // preferably recursive to draw all horizontal levels. -BW
	// Addition 11Aug2003
	var re = new RegExp("'", "gi");


	for (var i =0; i<this.getTopLevelLength(); i++) {
		topLevelObject = this.topLevelNavItems[i];
		if (topLevelObject.getNavItemLength() > 0) {
			for (var j=0; j<topLevelObject.getNavItemLength(); j++) {
				navObject = topLevelObject.navItems[j];
				if (topLevelObject.navItems[j].hasChild) {

					var oneWithChild = topLevelObject.navItems[j];
					currentLeft = this.getLeftOfTopLevelPredecessors (topLevelObject.id) + (this.xSpacing * i) + (this.padding * 2);
					var lowLevelNavElement = getObject (createLayer(oneWithChild.description + "_child"));

					lowLevelNavElement.style.left = currentLeft + "px";

					var cellBorderOffset = 0;

					if (navigator.appVersion.indexOf ("MSIE") != -1) {
						cellBorderOffset = j;
					}

					// Addition 11Aug2003
					var ie5offset = (msieversion()==5) ? j-1 : 0;

					var currentTop = this.childLevelBorderWidth + this.topLevelNavItemHeight + this.ySpacing + this.top + (this.lineHeight * j) + this.padding - this.childLevelBorderWidth + cellBorderOffset - ie5offset;




					lowLevelNavElement.style.top = currentTop + this.padding + "px"
					lowLevelNavElement.style.backgroundColor = this.childLevelBackgroundColour;
					lowLevelNavElement.style.width = Nav.childLevelItemWidth +"px";
					lowLevelNavElement.style.visibility = "visible";
	// CHANGE BY INIGO 06Jun2003
					lowLevelNavElement.style.display = "block";
					lowLevelNavElement.style.zIndex = 5;
					lowLevelNavElement.style.height = "auto";
					lowLevelNavElement.style.borderColor = this.childLevelBorderColour;
					lowLevelNavElement.style.borderStyle = this.childLevelBorder;
					lowLevelNavElement.style.borderWidth = this.childLevelBorderWidth +"px";

					var innerItemString = "<table cols=\"2\" cellpadding=\"0\" cellspacing=\"0\" class=\"tableouterline\">\n\n";
					var innerItemShaddow = "<table cols=\"2\" cellpadding=\"0\" cellspacing=\"0\" class=\"tableouterlineshadow\">\n\n";;

					for (var k=0; k<oneWithChild.navItems.length; k++) {

						var myClass = "hastopline";
						if (k==0) {
							myClass = "notopline";
						}
						var tmpLevel = oneWithChild.navItems[k];
						// mouseOver, mouseOut, and onClick added to support menu working even when not hovering over text 11Aug2003
						var escapedURL = tmpLevel.url.replace(re, "\\'");
						innerItemString  += "<tr onClick=\"window.location.href='"+escapedURL+"'\" style=\"cursor:hand\" onMouseOver=\"this.style.background='"+this.cellMouseOverColour+"'\" onMouseOut=\"this.style.background='"+this.cellMouseOutColour+"'\"><td class=\""+myClass+"\"height=\""+this.lineHeight+"\" width=\"" + this.childLevelItemWidth+"\" >"+this.leftSpacerImage+"\n<a class=\""+this.childLevelLinkClass+"\" href=\"" + tmpLevel.url + "\" onMouseOver=\""+this.instanceName+".changeParentElementBgColour(this, '"+this.cellMouseOverColour+"');\" onMouseOut=\""+this.instanceName+".changeParentElementBgColour(this, '"+this.cellMouseOutColour+"')\">" + tmpLevel.description+"</a></td></tr>";
						innerItemShaddow += "<tr><td class=\""+myClass+"shadow\" height=\""+this.lineHeight+"\" width=\"" + this.childLevelItemWidth+"\" >"+"<a class=\""+this.childLevelLinkClass+"\"href=\"" + tmpLevel.url + "\"></a></td></tr>";
					}

					innerItemString += "</table>\n\n";
					lowLevelNavElement.innerHTML = innerItemString;

					// make its shaddow -BW

					objChildShadow = getObject (createLayer(oneWithChild.description + "_child_shadow"));
                	objChildShadow.style.visibility = "hidden";
	// CHANGE BY INIGO 06Jun2003
                	objChildShadow.style.display = "none";

	               	objChildShadow.style.left = currentLeft - this.childShadowDeltaX +"px";
                	objChildShadow.style.top = (currentTop + this.childShadowDeltaY) + this.padding +"px";
                	objChildShadow.style.width = Nav.childLevelItemWidth +"px";
                	objChildShadow.style.zIndex = 4;
                	objChildShadow.style.height = "auto";
                	objChildShadow.style.borderWidth = 1 +"px";
                	objChildShadow.style.letterSpacing = this.letterSpacing +"px";
                	objChildShadow.style.borderColor = this.childShadowLineColour ;
                	objChildShadow.style.borderStyle = "solid";
                	objChildShadow.style.backgroundColor = this.childShadowBodyColour;
                	objChildShadow.innerHTML = innerItemShaddow; // ?
				}
			}
		}
	}
}

function fn_drawLowerLevelsOldVersion () {

	for (var i =0; i<this.getTopLevelLength(); i++) {
		str = "";
		topLevelObject = this.topLevelNavItems[i];
		if (topLevelObject.getNavItemLength() > 0) {
			for (var j=0; j<topLevelObject.getNavItemLength(); j++) {
				navObject = topLevelObject.navItems[j];
				if (topLevelObject.navItems[j].hasChild) {
					var oneWithChild = topLevelObject.navItems[j];
					if (navigator.appName.indexOf("Netscape") == 0) {

						var currentTop = this.topLevelNavItemHeight + this.top + (this.lineHeight * j) - (1 * j);
						currentLeft = this.getLeftOfTopLevelPredecessors (topLevelObject.id) - this.childLevelBorderWidth;
						str = '<layer name="'+ oneWithChild.description +'_child" left="'+currentLeft+'"top="' + currentTop + '" width="' + this.childLevelItemWidth + '" height="' +this.lineHeight+ '">\n';
						str += ("<table width=\""+this.childLevelItemWidth+"\" border=\"0\" cellpadding=0 cellspacing=0>\n\n");
						for (var k=0; k<oneWithChild.navItems.length; k++) {
							var tmpLevel = oneWithChild.navItems[k];
							str += "<tr>\n<td width=\""+this.childLevelItemWidth+"\" height=\""+this.lineHeight+"\">\n<a href=\"" +tmpLevel.url+ "\" class=\""+this.childLevelLinkClass+"\">" + tmpLevel.description + "</a>\n</td>\n</tr>\n";
						}
						str += '</table>\n</layer>\n';
						document.write (str);
						getObject(oneWithChild.description + "_child").bgColor=this.childLevelBackgroundColour;

					} else {
						var currentTop = this.topLevelNavItemHeight + this.top + (this.lineHeight * j) + (1 * j) + 1; // again.. like ns theres a weird relationship that this puts right.  I have *no* idea why, somethign to do with table spacings ! - BW
						currentLeft = this.getLeftOfTopLevelPredecessors (topLevelObject.id) - this.childLevelBorderWidth;
						str=("<div id=\"" + oneWithChild.description + "_child\" style=\"left:" + currentLeft + ";position:absolute;z-index=1;top:"+currentTop+";width:"+this.childLevelItemWidth+";height:"+this.lineHeight+"\">");
						str += ("<table width=\""+this.childLevelItemWidth+"\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n\n");

						for (var k=0; k<oneWithChild.navItems.length; k++) {
							var tmpLevel = oneWithChild.navItems[k];
							str += "<tr>\n<td width=\""+this.childLevelItemWidth+"\" height=\""+this.lineHeight+"\">\n<a href=\"" +tmpLevel.url+ "\">" + tmpLevel.description + "</a>\n</td>\n</tr>\n";
						}
						str += '</table>\n</div>\n';
						document.write (str);
						getObject(oneWithChild.description + "_child").style.backgroundColor=this.childLevelBackgroundColour;

					}
				}
			}
		}
	}
}

function fn_drawOldBrowserVersion () {
    var currentLeft = Nav.left;
    var groupYPosition = this.top + this.topLevelNavItemHeight + this.ySpacing;
    var objParent;
    var objChild;
    var tmp;

    if (navigator.appName.indexOf("Netscape") == 0) {
        for (var i =0; i<this.getTopLevelLength(); i++) {
            var topLevelObject = this.topLevelNavItems[i];
            document.write ('<LAYER NAME="' + topLevelObject.id + '" top="'+this.top+'" left="' + currentLeft +'" onMouseOver="' + this.instanceName + '.close();showLayer(' + topLevelObject.id + '_child)" clip="0, 0, ' + topLevelObject.width + ', ' + this.topLevelNavItemHeight + '">');
            document.write ('&nbsp;&nbsp;<a class="' + this.childLevelLinkClass + '" href="' + topLevelObject.url + '">' + topLevelObject.description + '</a>');
            document.write ('</LAYER>');
            document.write ('<LAYER NAME="' + topLevelObject.id + '_child" top="'+groupYPosition+'" left="' + currentLeft +'" width="'+this.childLevelItemWidth+'">');
            document.write ("<table width=\""+this.childLevelItemWidth+"\" border=\"0\">\n\n");

            for (var j=0; j<topLevelObject.getNavItemLength(); j++) {
                if (topLevelObject.navItems[j].description != "_imgNavItemSeperator") {
                    navObject = topLevelObject.navItems[j];
                    var mouseOver = "";
                    if (!navObject.hasChild) {
						mouseOver = "onMouseOver=\"" +this.instanceName+ ".closeThirdLevelNavItems();\"";
					} else {
						mouseOver = "onMouseOver=\"" +this.instanceName+ ".closeThirdLevelNavItems();showLayer('"+navObject.description+"_child');\"";
					}
                    document.write ("<tr>");
                    document.write ('<td><layer width="'+this.childLevelItemWidth +'" height="'+this.lineHeight+'" top="'+this.lineHeight * j+'"' +mouseOver+ '><a class="' + this.childLevelLinkClass + '" href="' + navObject.url + '">' +  navObject.description + '</a>' + '</layer></td>');
                    document.write ("</tr>");
                }
            }

            document.write ("</table>");

            document.write ('</LAYER>');

            if (this.topLevelBackgroundColour) {
            	getObject(topLevelObject.id).bgColor=this.topLevelBackgroundColour;
            }

            getObject(topLevelObject.id + "_child").bgColor=this.childLevelBackgroundColour;

            currentLeft += this.topLevelNavItems[i].width + this.xSpacing;
        }
    } else {

        for (var i =0; i<this.getTopLevelLength(); i++) {
            topLevelObject = this.topLevelNavItems[i];
            document.write ("<div id=\"" + topLevelObject.id + "\" style=\"left:" + currentLeft + ";position:absolute;z-index=1;top:"+this.top+";width:"+topLevelObject.width+";height:"+this.topLevelNavItemHeight+"\" onMouseOver=\"" + this.instanceName + ".close();"+this.instanceName+".showLayer('" + topLevelObject.id + "_child') \">");
            document.write ("<a class=\"" + this.topLevelLinkClass + "\" href=\""+topLevelObject.url+"\">" + topLevelObject.description + "</a>");
            document.write ('</div>');
            getObject(topLevelObject.id).style.backgroundColor=this.topLevelBackgroundColour;
            getObject(topLevelObject.id).style.padding=this.padding;

			if (topLevelObject.getNavItemLength() > 0) {
				document.write ("<div id=\"" + topLevelObject.id + "_child\" style=\"left:" + currentLeft + ";top:"+groupYPosition+";position:absolute;z-index=2;width:"+ this.childLevelItemWidth +";\">");
				document.write ("<table width=\""+this.childLevelItemWidth+"\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n\n");
				for (var j=0; j<topLevelObject.getNavItemLength(); j++) {
					if (topLevelObject.navItems[j].description != "_imgNavItemSeperator") {
						navObject = topLevelObject.navItems[j];

						var mouseOver = "";
						if (!navObject.hasChild) {
							mouseOver = "onMouseOver=\"" +this.instanceName+ ".closeThirdLevelNavItems();\"";
						} else {
							mouseOver = "onMouseOver=\"" +this.instanceName+ ".closeThirdLevelNavItems();showLayer('"+navObject.description+"_child');\"";
						}
						document.write ("<tr "+mouseOver+">");
						document.write ("<td width=\""+this.childLevelItemWidth+"\" height=\""+this.lineHeight+"\">");
						document.write ("<a class = \"" + this.childLevelLinkClass + "\" href=\""+navObject.url+"\" "+">" + navObject.description + "</a></td>");
						document.write ("<tr>");
					}
				}
				document.write ("</table></div>");
				getObject(topLevelObject.id + "_child").style.backgroundColor=this.childLevelBackgroundColour;
			}

            currentLeft += this.topLevelNavItems[i].width + this.xSpacing;
        }
    }

    this.drawLowerLevelsOldVersion();
}

function fn_drawPlainTextVersion () {
    for (var i =0; i<this.getTopLevelLength(); i++) {
        topLevelObject = this.topLevelNavItems[i];
        document.write ("<p><a href=\"" + topLevelObject.url + "\">" + topLevelObject.description + "</a>");
        for (var j=0; j<topLevelObject.getNavItemLength(); j++) {
            if (topLevelObject.navItems[j].description.indexOf("_") != 0) {
                document.write ("<br />...<a href=\"" + topLevelObject.navItems[j].url + "\">" + topLevelObject.navItems[j].description + "</a>");
            }
        }
        document.write ("<p>");
    }
}

function fn_positionNav () {
    var pageWidth;
    var totalTopLevelWidth = 0;
    if (navigator.appName.indexOf("Netscape") == 0) {
      if (document.getElementById) {
          pageWidth = document.width;
      } else {
        pageWidth = innerWidth
      }
    } else {
      pageWidth = document.body.clientWidth;
    }
    for (var i =0; i<this.getTopLevelLength(); i++) {
        this.topLevelNavItems[i].width *= 1;
        totalTopLevelWidth += this.topLevelNavItems[i].width;
    }
    var navWidth = (totalTopLevelWidth) + (this.xSpacing * (this.getTopLevelLength()));
    var newNavLeft = (pageWidth - navWidth) / 2;
    var currentLeft = newNavLeft - this.centeringOffset;
    for (var i =0; i<this.getTopLevelLength(); i++) {
        var topLevelObject = this.topLevelNavItems[i];
        setLayerLeft(topLevelObject.id, currentLeft);
        if (getObject(topLevelObject.id +"_child", currentLeft)) {
            setLayerLeft(topLevelObject.id +"_child", currentLeft);
        }
        if (getObject (topLevelObject.id +"_child_shadow")) {
            setLayerLeft(topLevelObject.id +"_child_shadow", currentLeft - this.childShadowDeltaX);
        }
        currentLeft += this.topLevelNavItems[i].width + this.xSpacing;
    }
}
/* nav specific code ends */

/* page / navigation events */
document.onclick = closeNavEvent;
//window.onresize = onResizeEvent;  /*for fixed position menu comment this -BW */
function doNavDraw () {
    // Addition by Inigo 17Jun2003 to make Javascript initialized from
    // body onLoad call rather than when script loaded - reduces JavaScript
    // errors from asynchronous loading and makes Hebrew/Arabic ticker fix possible
    initJavaScriptItems(); // Defined in the cq_navigation.js file
    if (document.getElementById) {
        Nav.draw();
    } else {

        Nav.drawOldBrowserVersion();
    }
}
/* general code for re-loading netscape -BW */
MM_reloadPage(true);
function MM_reloadPage(init) {
  if (init==true) with (navigator) {
    if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
        document.MM_pgW=innerWidth;
        document.MM_pgH=innerHeight;
        onresize=MM_reloadPage;
    }
  } else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
function closeNavEvent () {
    Nav.close();
}
function onResizeEvent () {
    Nav.positionNav();
}
// Addition 11Aug2003
 function msieversion() {
      var ua = window.navigator.userAgent
      var msie = ua.indexOf ( "MSIE " )

      if ( msie > 0 )      // If Internet Explorer, return version number
         return parseInt (ua.substring (msie+5, ua.indexOf (".", msie )))
      else                 // If another browser, return 0
         return 0
   }
