﻿function addLoadEvent(func) { 
	var oldonload = window.onload; 
	if (typeof window.onload != 'function') { 
	window.onload = func; 
	} else { 
	    window.onload = function() { 
	    oldonload(); 
	    func(); 
	   } 
	} 
} 

function insertAfter(newElement,targetElement)	{
	var parent = targetElement.parentNode;
	if (parent.lastChild == targetElement)	{
		parent.appendChild(newElement);
	}	else	{
		parent.insertBefore(newElement,targetElement.nextSibling);
	}
}	

function addClass(element,value)	{
	if (!element.className)	{
		element.className = value;
	}	else	{
		newClassName = element.className;
		newClassName+= " ";
		newClassName+= value;
		element.className = newClassName;
	}
}

/*
function highlightPage()	{
	setTimeout("highlightPagepart2()",4000);
}
*/

function highlightPage()	{
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("sideBarNav")) return false; //sideBarNav CSS id for Sidebar style
	var nav = document.getElementById("sideBarNav");
	var links = nav.getElementsByTagName("a");
	for (var i=0; i<links.length; i++)	{
		var linkurl = links[i].getAttribute("href");
		var currenturl = document.location.href;
		if (currenturl.indexOf(linkurl) !=-1)	{
			links[i].className = "hereSN"; //CSS Selector for Current Page URL
			var linktext = links[i].lastChild.nodeValue.toLowerCase();
			document.body.setAttrubute("id",linktext);
		}
	}
}
addLoadEvent(highlightPage);

// Navigation Trail Library (trail.js)
// by Danny Goodman (http://dannyg.com)
// From "DHTML Cookbook" (O'Reilly) by Danny Goodman
// Copyright 2003 Danny Goodman.  All Rights Reserved.


var trailMenu = new Object();
trailMenu["approach"] = "Approach & Methodologies";
trailMenu["rotation"] = "Sector Rotation";
trailMenu["navigator"] = "Market Navigator Platform";
trailMenu["help"] = "Navigator Help";

function makeTrailMenu() {
    var parseStart, volDelim, parseEnd;
    var output = "<span style='font-family:Arial, Helvetica, sans-serif'>";
    var linkStyle = "color:#999999";
    var path = location.pathname;
    var separator = "&nbsp;&raquo;&nbsp;";
    var re = /\\/g;
    path = path.replace(re, "/");
    var trail = location.protocol + "//" + location.hostname;
    var leaves = path.split("/");
    if (location.protocol.indexOf("file") != -1) {
        parseStart = 1;
        volDelim = "/";
    } else {
        parseStart = 0;
        volDelim = "";
    }
    if (leaves[leaves.length-1] == "" || leaves[leaves.length-1] == "index.html" || leaves[leaves.length-1] == "default.html") {
        parseEnd = leaves.length -1;
    } else {
        parseEnd = leaves.length;
    }
    for (var i = parseStart; i < parseEnd; i++) {
        if (i == parseStart) {
            trail += "/" + leaves[i] + volDelim;
            output += "<a href='" + trail + "' style='" + linkStyle + "'>";
            output += "Home";
        } else if (i == parseEnd - 1) {
            output += document.title;
            separator = "";
        } else {
            trail += leaves[i] + "/";
            output += "<a href='" + trail + "' style='" + linkStyle + "'>";
            output += trailMenu[leaves[i]];
        }
        output += "</a>" + separator;
    }
    output += "</span>";
    return output;
}

addLoadEvent(makeTrailMenu);

