$(function() {
  window.menu = new Menu();

  MainMenu();

  $("#body").css({paddingBottom: $("#foot").outerHeight() + 30});

  $(".main-menu .item").hover(function() {
    $('.submenu',this).show();
  }, function() {
    $('.submenu',this).hide();
  });
});

/* Всплывающие меню */
function MainMenu(){

    var $body = $(document.body);
    var hideDelay = 50;

    function createOuterCont(link){

        var hideDelayTimer = null;
        var beingShown = false;
        var shown = false;

        var parent = link.parentNode;
        var hd = $(parent).find(".submenu");
        if(hd.length>0){
            var bubble = $(document.createElement("div"))
                            .addClass("popup")
                            .html(hd.html())
                            .appendTo($body);

           $([ link, bubble.get(0)]).mouseover(function () {
                  if (hideDelayTimer) clearTimeout(hideDelayTimer);
                  if (beingShown || shown) {
                        return false;
                  } else {
                        beingShown = false;
                        shown = true;
                        var position = $(link).offset();
                        position.top+=link.offsetHeight;
                        bubble.css({top: Math.round(position.top)+'px',
                                    left: Math.round(position.left)+'px',
                                    display: "block"});
                  }
                  return false;
            }).mouseout(function () {
                  if (hideDelayTimer) clearTimeout(hideDelayTimer);
                  hideDelayTimer = setTimeout(function () {
                        hideDelayTimer = null;
                        bubble.css('display', 'none');
                        shown = false;
                  },hideDelay);
                  return false;
            });
            $(link).click(function(){ return false; });
        }
    }


    $("#center-part .main-menu1 .item .ma").each(function(){
      createOuterCont(this);
    })

}
