// global timer variable
var close_timer;

function open_submenu()
{
  // cancel the close timer
  clearTimeout(close_timer);
  
  // get the length as stored in name
  menu_height = $("div#cat-drop-down").attr("name");

  // make submenu visible
  $("div#cat-drop-down").css({display:"block"});

  $("div#cat-drop-down").bind("mouseenter", function()
  {
    // cancel the close timer
    clearTimeout(close_timer);

    $("div#cat-drop-down").bind("mouseleave", function()
    {
      // cancel the close timer
      clearTimeout(close_timer);
      
      close_timer = setTimeout("close_submenu()", 500);
    });
  });

  // animate menu
  $("div#cat-drop-down").animate({height: menu_height}, 200);
}

function close_submenu()
{
  if($("div#cat-drop-down").css("display").toUpperCase() == "BLOCK")
  {
    $("div#cat-drop-down").animate({height: 0}, 200, function()
    {
      $(this).css({display:"none"});
    });
  }
}

// main menu rollovers
$("document").ready(function()
{
  // add rollover functinoality to menu buttons
  $("#prod-button").bind("mouseenter", function()
  {
    // is a submenu alrady open
    if($("div#cat-drop-down").css("display").toUpperCase() == "NONE") open_submenu();
  });

  $("#prod-button").bind("mouseleave", function()
  {
    // cancel the close timer
    clearTimeout(close_timer);
    
    close_timer = setTimeout("close_submenu()", 500);
  });
});