Javascript to highlight current nav and sub directories
<p>I am using this script to highlight the current navigation link :</p>

<pre><code>function extractPageName(hrefString)
{
    var arr = hrefString.split('/');
    return  (arr.length &lt; 2) ? hrefString : arr[arr.length-2].toLowerCase() + arr[arr.length-1].toLowerCase();
}

function setActiveMenu(arr, crtPage)
{
    for (var i=0; i &lt; arr.length; i++)
    {
        if(extractPageName(arr[i].href) == crtPage)
        {
            if (arr[i].parentNode.tagName != "DIV")
            {
                arr[i].className = "active";
                arr[i].parentNode.className = "active";
            }
        }
    }
}

function setPage()
{
    hrefString = document.location.href ? document.location.href : document.location;
    if (document.getElementById("topNav") !=null )
    setActiveMenu(document.getElementById("topNav").getElementsByTagName("a"), extractPageName(hrefString));
}

window.onload=function()
{
    setPage();
}
</code></pre>

<p>This works fine if I am at www.site.com/contact/  the contact link will have the active class.  My question is how could I modify this so that also if I am in a subdirectory it continues to highlight that link?  So if I am in contact/stuff/index.html  then it would still have the active class on contact.</p>
