var lang_to = null;
var lang_active = false;
function lang_expand() {
  if (lang_to != null)
    clearTimeout(lang_to);
  lang_to = null;
  $("#langs", document).slideDown(100);
  return false;
}
function lang_chk() {
  lang_to = null;
  if (!lang_active)
    $("#langs").hide();
}

function menu_expand(idx) {
  var m = $("#menu > div:eq(" + idx + ")");
  $("#menu > div").each(function(i) {
      if (i != idx)
        menu_chk(i);
    });
  if (m.data("to") != null) {
    clearTimeout(m.data("to"));
    m.removeData("to");
  }
  if (m.hasClass("active-e"))
    return;
  m.addClass("active-e");
  $("ul", m).slideDown(150);
}
function menu_chk(i) {
  var m = $("#menu > div:eq(" + i + ")");
  if (m.data("to") != null) {
    clearTimeout(m.data("to"));
    m.removeData("to");
  }
  $("ul", m).stop();
  $("ul", m).css("height", "auto");
  $("ul", m).hide();
  m.removeClass("active-e");
}

$(document).ready(function(){
    if ($("#langs").length > 0) {
      //$("#langs").css("left", $("#lang img").offset().left - 6 + 207 - $("#header").offset().left + "px");
      $("#lang").add("#langs")
	.mouseover(function() {
	    lang_active = true;
	    if (lang_to != null) {
	      clearTimeout(lang_to);
	      lang_to = null;
	    }
	})
	.mouseout(function() {
	    lang_active = false;
	    lang_to = setTimeout(lang_chk,1000);
	  });
    }
    
    $("#menu ul").each(function() {
	var w = $(this).parent().width() - ($("#langs").length > 0 ? 35 : 17);
	if (w < 100) {
	  w = 90 + ($("#langs").length > 0 ? 35 : 17);
	  $(this).css("padding-left", "10px");
	}
	$(this).css("width", w + "px");
      });
    $("#menu div > h1").each(function(i) {
	$("a", this).click(function(){return false;});
      });
    $("#menu div").each(function(i) {
	$(this)
	  .mouseover(function() {
	      menu_expand(i);
	    })
	  .mouseout(function() {
	      if ($(this).data("to") == null)
		$(this).data("to", setTimeout("menu_chk(" + i + ")", 100));
	    });
	});
    $("#nlEmail")
      .focus(function() {
	  if ($(this).val() == "inscrivez votre email")
	    $(this).val("");
	})
      .blur(function() {
	  if($.trim($(this).val()).length == 0)
	    $(this).val("inscrivez votre email");
	});
  });
