if (document.observe) {
  document.observe("dom:loaded", function() {
    SidebarHighlight.init();
  });
}
var SidebarHighlight = {
  init: function() {
    // this check is for when the user in an article or a category
    // it checks for the name of the category within the breadcrumbs
    var breadcrumb = $$('#cms #main-content p#breadcrumbs')[0];
    if (breadcrumb) {
      var child = breadcrumb.getElementsByTagName("*")[1];
      if(child) {
        var childText = child.innerHTML.toLowerCase();
        SidebarHighlight.getSidebarText(childText);
      }
    }

    // this check is for the martha stewart and notes on a party categories
    // it checks for the name of the category within the url
    var currentPage = document.location.pathname;
    var pattern = /\/+/;
    result = currentPage.split(pattern);
    // this is for IE
    if (document.all) {
      var currentPageMatch = result[1];
    }
    // this is for normal browsers
    else {
      var currentPageMatch = result[2];
    }
    if (currentPageMatch && currentPageMatch == "notes-on-a-party") {
      var partyText = "notesonaparty.com";
      SidebarHighlight.getSidebarText(partyText);
    }
    else if (currentPageMatch && currentPageMatch == "martha-stewart") {
      var marthaText = "marthastewart.com";
      SidebarHighlight.getSidebarText(marthaText);
    }
  },

  getSidebarText: function(category) {
    $$('#sidebar a').each( function(el) {
      if( category == el.innerHTML.toLowerCase() ) {
        el.addClassName('current');
      }
    } );
  }

}
