$(function(){
  var path = location.pathname.substring(1);
  if ( path )
    $('#sub-navigation a[href$="' + path + '"]').attr('class', 'selected');
});

$(document).ready(function() {
  $("*").find("a[href='"+window.location.href+"']").each(function(){
  $(this).addClass("selected")
  //add your own logic here if needed
  })
  
  $('#choose-designer-link').click(function() {
    if (!$("#designer-menu").is(':hidden')) {
      $('#choose-designer-link').text('Choose Another Designer');
    }
    else {
      $('#choose-designer-link').text('Hide Designers Menu');
    }
    $('#designer-menu').slideToggle('slow', function() {
      // Animation complete
    });
    
    $('#choose-designer-link').toggleClass("menu-open");
  });
  
});

function markActiveLink() {

    //Look through all the links in the sidebar
   $("div#sub-navigation a").filter(function() {

      //Take the current URL and split it into chunks at each slash
      var currentURL = window.location.toString().split("/");

      //return true if the bit after the last slash is the current page name
      return $(this).attr("href") == currentURL[currentURL.length-1];

    //when the filter function is done, you're left with the links that match.
    }).addClass("active");

   //Afterwards, look back through the links. If none of them were marked,
   //mark your default one.
   if($("div#sidebar a").hasClass("active") == false) {
      $("div#sidebar h2:nth-child(2) a").addClass("active");
    }
 }

markActiveLink();
