$(document).ready(function(){
// get the url
    var $path = location.pathname;
    // initialise variables
    var $currentPage, $WhichList;
    // Get the text of the last item in the first breadcrumb list
    var $breadcrumbLast = $('.Breadcrumb ul:first-child li:last').text();
    // Get the text of the penultimate item in the first breadcrumb list
    var $breadcrumbPenultimate = $('.Breadcrumb ul:first-child li:nth-last-child(2)').text();
   
    // uncomment the line below to test what you're actually getting
    // alert("Penultimate Item = " + $breadcrumbPenultimate + "Last Item=" + $breadcrumbPenultimate);
   
    // products always contain /products/ in the url string so look for it
    if ($path.match('/products/')) {
        // we have a match, get the *penultimate* list item from the first list
        // this will give you the brand or category name
        $currentPage = $breadcrumbPenultimate;
        $WhichList = '#SideCategoryList';
    }
    else if ($path.match('/categories/')){
        // if it's category page, get the last breadcrumb item
        $currentPage = $breadcrumbLast;
        // target the category list
        $WhichList = '#SideCategoryList';
    }
    else if ($path.match('/brands/')){
        // if it's brand page, get the last breadcrumb item
        $currentPage = $breadcrumbLast;
        // target the shopbybrand list
        $WhichList = '#SideShopByBrand';
    } else {
        $currentPage = $breadcrumbLast;
        $WhichList = '#Menu';        
    }                  

    // go through every item in the chosen list
    $($WhichList+' ul li').each(function() {
        // get the text for the list item
        text = $(this).text();        
        if ($currentPage!='' && text.match($currentPage) ) {
            // Add a class to the list item if you find a text match and return
            return $(this).addClass('ActivePage');
        }
    });
    
    $("#SideCategoryList ul li").each(function() {
        // get the text for the list item
        text = $(this).text();        
        if ($currentPage!='' && text.match($currentPage) ) {
            // Add a class to the list item if you find a text match and return
            return $(this).addClass('ActivePage');
        }
    });
    
    /*
    $("#ResourcesPanel ul li").each(function() {
        // get the text for the list item
        text = $(this).text();        
        if ($currentPage!='' && text.match($currentPage) ) {
            // Add a class to the list item if you find a text match and return
            return $(this).addClass('ActivePage');
        }
    });
    */   
                    
});
