﻿/*
** SideMenu.js
*/
$(function() {
    // Current url offset.  Note, we need to rely on the directory name
    // to identify the active menu group, so we strip off the page name
    // from the url.
    var root = (this.location.protocol + "//" + this.location.host + "/").toLowerCase();
    var path = this.location.href.toLowerCase();
    path = path.substring(0, path.lastIndexOf("/") + 1);

    // Check each link to see if they match the current location
    var currentUrl = Jes.Uri.getBaseUrl().toLowerCase();
    $("#leftNav a").each(function() {
        var href = Jes.Uri.getBaseUrl(this.href).toLowerCase();
        if (currentUrl === href) {
            var $a = $(this).addClass("current");
            $a.parent().parents("li").each(function() {
                $(this).children("a").eq(0).addClass("current");
            });
        }
    });
    
	// Check each link in #topNav to see if first folders match
	$("#topNav a").each(function() {
		// get the first folder in the link href tag
		var navLinkPath = Jes.Uri.getBaseUrl(this.href).toLowerCase();
		navLinkPath = navLinkPath.substring(0, navLinkPath.lastIndexOf("/") + 1);
		// get the first folder in the current url
		currentUrl = currentUrl.substring(0, currentUrl.lastIndexOf("/") + 1);
		if (navLinkPath === currentUrl)
		{
			$(this).addClass("current");
		}
     });

    

});
