﻿$(document).ready(function() {
  
  // Escondo los submenus por defecto
  $("div#subNav").css('visibility', 'visible') ; //Evita que cuando carga la pagina aparezcan todos los submenus
  $("ul.subNav").hide() ;

  // Asigno al menu lo subNavs
  $("div#nav ul li").hover(
    function() {
      $("div#subNav ul").hide();
      var idMenuActual = $(this).attr("id");
      $("div#subNav ul#sub" + idMenuActual).show();
    },
    function() {
      var idMenuActual = $(this).attr("id");
      $.doTimeout('timerMenu', 3000, function() {
        if (idMenuActual != $("div#nav ul li.current").attr("id")) {
          $("div#subNav ul").fadeOut("slow");
          $("div#subNav ul#sub" + $("div#nav ul li.current").attr("id")).fadeIn("slow");
        }
      });
    }
  )

  // Cuando se esté sobre un submenu que no se desaparezca
  $("div#subNav ul li").mouseover(
    function() {
      var idMenuActual = $(this).parent().attr("id");
      $.doTimeout('timerMenu', 3000, function() {
        if (idMenuActual != "sub" + $("div#nav ul li.current").attr("id")) {
          $("div#subNav ul").fadeOut("slow");
          $("div#subNav ul#sub" + $("div#nav ul li.current").attr("id")).fadeIn("slow");
        }
      });
    }
  )

});


function mostrarSubMenu () {
  // Muestra el Submenu del Menu que está seleccionado
  var idMenu = $("div#nav ul li.current").attr("id") ;
  $("div#subNav ul#sub" + idMenu).show() ;
}


/*
* jQuery doTimeout: Like setTimeout, but better! - v0.4 - 7/15/2009
* http://benalman.com/projects/jquery-dotimeout-plugin/
* 
* Copyright (c) 2009 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function($) { var a = {}, c = "doTimeout", d = Array.prototype.slice; $[c] = function() { return b.apply(window, [0].concat(d.call(arguments))) }; $.fn[c] = function() { var f = d.call(arguments), e = b.apply(this, [c + f[0]].concat(f)); return typeof f[0] === "number" || typeof f[1] === "number" ? this : e }; function b(k) { var l = this, g, i = {}, m = arguments, h = 4, f = m[1], j = m[2], o = m[3]; if (typeof f !== "string") { h--; f = k = 0; j = m[1]; o = m[2] } if (k) { g = l.eq(0); g.data(k, i = g.data(k) || {}) } else { if (f) { i = a[f] || (a[f] = {}) } } i.id && clearTimeout(i.id); delete i.id; function e() { if (k) { g.removeData(k) } else { if (f) { delete a[f] } } } function n() { i.id = setTimeout(function() { i.fn() }, j) } if (o) { i.fn = function(p) { o.apply(l, d.call(m, h)) && !p ? n() : e() }; n() } else { if (i.fn) { j === undefined ? e() : i.fn(j === false); return true } else { e() } } } })(jQuery);

