$(document).ready(
  function()
  {
    var homeTimeout = 0;
    var businessTimeout = 0;
    var hoverDelay = 500;

    $("div.navHome, div.navBusiness").css("display", "none");

    $("div.forHome").hover(
      function()
      {
        if (homeTimeout != 0)
        {
          clearTimeout(homeTimeout);
        }
        navControl("open","Home");
      },
      function()
      {
        homeTimeout = setTimeout(
          function()
          {
            navControl("close","Home");
          },
          hoverDelay
        );
      }
    );

    $("div.navHome").hover(
      function()
      {
        clearTimeout(homeTimeout);
      },
      function()
      {
        homeTimeout = setTimeout(
          function()
          {
            navControl("close","Home");
          },
          hoverDelay
        );
      }
    );

    $("div.forBusiness").hover(
      function()
      {
        if (businessTimeout != 0)
        {
          clearTimeout(businessTimeout);
        }
        navControl("open","Business");
      },
      function()
      {
        businessTimeout = setTimeout(
          function()
          {
            navControl("close","Business");
          },
          hoverDelay
        );
      }
    );

    $("div.navBusiness").hover(
      function()
      {
        clearTimeout(businessTimeout);
      },
      function()
      {
        businessTimeout = setTimeout(
          function()
          {
            navControl("close","Business");
          },
          hoverDelay
        );
      }
    );
  }
);

var navControl = function(action, segment)
{
  if (action == "open")
  {
    $("div.nav" + segment).slideDown("fast");
    $("div.for" + segment).find("span.arrowRight")
                          .removeClass("arrowRight")
                          .addClass("arrowDown");
  }
  else if (action == "close")
  {
    $("div.nav" + segment).slideUp("fast");
    $("div.for" + segment).find("span.arrowDown")
                          .removeClass("arrowDown")
                          .addClass("arrowRight");
  }
};

