var wait = true;
var lastClass = '';
var lastId = '';
function initMenu() {
  //current url
  var url = window.location.href;
  
  // get all main level a tags and att
  //$("#nav_small a").bind("mouseenter", toggleMenu);
  //$("#nav_small ul li ul li a").unbind("mouseenter", toggleMenu);
  
  //activate current link
  //alert(url);
  url =url.replace("http://www.3plcentral.com",'');
  url =url.replace("http://3plcentral.com",'');

  $("href='"+url+"'").addClass("active");
  $("#nav_small a").each(function() {
    if($(this).attr('href') == url) {
      if($(this).attr('id') != '') {
        toggleMenu(this);
      } 
        $(this).addClass("active");
    }
  });
  
  $(".active").each(function(){
    $(this).parents().each(function(){
      
      if(this.tagName == "UL") {
        $(this).show();
        if($(this).hasClass("subnav")) {
          //get previous sibling a tag
          var $link = $(this).prev();
          $("#nav_small ul").addClass($link.attr('id'));
          lastClass = $link.attr('id');
        }
      }
    })
  });
}
$(document).ready(initMenu);


function toggleMenu(item) {
  
  if($(this).attr('id') == lastId)
    return
  
  //hide all
  if(wait){
    lastId = $(item).attr('id');
    $("#nav_small ul").removeClass(lastClass);
    $("#nav_small ul").addClass($(item).attr('id'));
    lastClass = $(item).attr('id');
    wait = false;
    $("#nav_small ul li ul").hide();    
    //show children
    $(item).next().slideDown("slow");
    setTimeout("wait = true",1000);
  }
}
