﻿$(document).ready(function() {
    var menu = $("#navlist");
    menu.addClass("sf-menu");
    menu.addClass("sf-vertical");
    
    
    $.get("menu.htm", function(data) {
       setupMenu(data);
    });
    
});

function setupMenu(items)
{
    var jItems = $(items);
    var topLevel = jItems.children();
    var subNavItems = $("#navlist").children();
    var domain = window.location.protocol + "//" + window.location.hostname + "/";
    
    $.each(subNavItems, function() {
       var current = $(this);
       var href = current.find("a:first").attr("href").replace(domain,"");
       var newItems;
       var currentHref = window.location.pathname;
       currentHref= currentHref.substring(1,currentHref.length);
      
       $.each(topLevel, function() {
           var topHref =  $(this).find("a:first").attr("href").replace(domain,"");
           if (topHref==href)
           {
              newItems = $(this).find("ul:first");
              return true;
           }
       });
       if (newItems != null && newItems.length > 0)
       {
           current.append(newItems);
       }
       
       if (href==currentHref)
           current.addClass("selected");
       else {
         // check the children
         if (current.find("a[href=" + currentHref + "]").length > 0)
           current.addClass("selected");  
       } 
    });
    
    var menu = $("#navlist");
    menu.superfish({
	    autoArrows: false,
	    dropShadows: false,
	    delay: 200
	});
}
