﻿/**************************************************************************
* Usage:                                                                 *
* - the script will apply the .current class to the <a> and its parent   *
*   <li> that is contained in the element with id="primarynav" and points*
*   to the current URL                                                   *
* - works in IE6, Firefox and Opera                                      *
**************************************************************************/

function extractPageName(hrefString) {
    //alert(hrefString);
    var arr = hrefString.split('/');
    //alert (arr.length<2);
    return (arr.length < 2) ? hrefString : arr[arr.length - 2].toLowerCase() + arr[arr.length - 1].toLowerCase();

}

function setActiveMenu(arr, crtPage) {
    if (crtPage != 'lvfoodandwine') {
        //alert(crtPage);
        for (var i = 0; i < arr.length; i++) {
            //alert(i + ': ' + extractPageName(arr[i].href));
            if (extractPageName(arr[i].href) == crtPage) {
                if (arr[i].parentNode.tagName != "DIV") {
                    arr[i].className = "current";
                    arr[i].parentNode.className = "current";
                    //alert(arr[i].parentNode.classname);
                }
            }
        }
    } else {
        arr[1].className = "current";
        arr[1].parentNode.className = "current";
    }
}

function setPage() {
    hrefString = document.location.href ? document.location.href : document.location;
    //alert(hrefString);
    //alert(extractPageName(hrefString));
    if (document.getElementById("navlist") != null)
        setActiveMenu(document.getElementById("navlist").getElementsByTagName("a"), extractPageName(hrefString));
}