﻿/*
** 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 in sideMenu to see if they match the current location for side menu
    var currentUrl = Jes.Uri.getBaseUrl().toLowerCase();
    $("ul.sideMenu a").each(function() {
        var href = Jes.Uri.getBaseUrl(this.href).toLowerCase();
        if (currentUrl === href) {
			// Show children ul's
            $(this).parent().children("ul").addClass("open").show();
            // Add class to parent ul
            $(this).parent().parent().addClass("open").show();
			var $a = $(this).addClass("current");
            $a.parent().parents("li").each(function() {
                $(this).children("a").eq(0).addClass("current");
            });
        }
    });


	// Check each link in #nav to see if first folders match
	$("#nav ul li 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");
		}
     });



    
});
