var subnavtimer = false;
var showTimer = false;

function showDropper() {
  $("div#dropnav").slideDown("fast");
  $("li.nav-dropper").addClass("dropped");
}    

function hideDropper() {
  $("div#dropnav").slideUp("fast");
  setTimeout(function(){ $("li.nav-dropper").removeClass("dropped");}, 250);
}

function clearTimer(){
  if (subnavtimer) { 
    clearTimeout(subnavtimer); 
  }
  subnavtimer = false;
}

function resetTimer(){
  clearTimer();
  subnavtimer = setTimeout(function(){ hideDropper(); }, 100);
}

$(document).ready(function(){

  $("li.nav-dropper > a, div#dropnav").mouseover(function(){ 
    if ($("li.nav-dropper").hasClass("dropped")) { 
      clearTimer(); 
    } else {
      showTimer = setTimeout(function(){ showDropper(); clearTimer(); }, 100);
    }
  });
  
  $("li.nav-dropper > a, div#dropnav").mouseout(function(){ 
    if ($("li.nav-dropper").hasClass("dropped")) { 
      resetTimer(); 
    } else {
      clearTimeout(showTimer);
    }
  });

  $("li.nav-dropper > a").click(function(){
    this.blur();
    if ($("li.nav-dropper").hasClass("dropped")) {
      hideDropper();
    } else {
      clearTimer();
      clearTimeout(showTimer);
      showDropper();
    }
    return false;
  });
});