function subMenu(){}; 
subMenu.menuTimer;

// Метод вызывается при наведении на любой из пунктов основного меню
subMenu.menuHover = function (objMenu, menuName) {
//  if (isset(objMenu.children[0]) && objMenu.children[0].className == 'button') document.getElementById(menuName).className = 'subMenu selected';
  subMenu.closeSubMenus(menuName);
  var position = getPosForTrain(objMenu);
//  var position = getPos(objMenu);
  document.getElementById(menuName).style.left = '' + position.left + 'px';
  document.getElementById(menuName).style.marginLeft = 0;
  document.getElementById(menuName).style.display = 'block';
  document.getElementById(menuName).style.width = '' + position.width + 'px';
  $("#"+menuName).find(".subMenuString").css("padding-left", position.paddingLeft); // выравниваем текст в подменю как и в самом меню
  clearTimeout(subMenu.menuTimer);
  
}

// Метод закрывает все ненужные подменю
subMenu.closeSubMenus = function (currentMenuName) { 
  currentMenuName = currentMenuName || '';
  subMenu.hideMenuifNotCurrent(currentMenuName, 'subMenuTicketsGuide');
};

// Метод закрывает подменю, если оно не является текущим
subMenu.hideMenuifNotCurrent = function (currentMenuName, menuName) {
  if ( menuName != currentMenuName ) document.getElementById(menuName).style.display = 'none';
};

// Метод вызывается при убирании курсора с любого из меню
subMenu.menuOut = function () {
  subMenu.menuTimer = setTimeout(subMenu.closeSubMenus, 500);
};

 // Метод вызывается при наведении на любое из подменю
subMenu.subMenuHover = function () {
  clearTimeout(subMenu.menuTimer);
  
};

// Метод вызывается при убирании курсора с любого из меню
subMenu.subMenuOut = function () {
  subMenu.menuTimer = setTimeout(subMenu.closeSubMenus, 200);
}


// Метод получает позицию элемента
function getPos (obj) {
  var output = new Object();
  var mytop=0, myleft=0;
  while( obj) {
    mytop+= obj.offsetTop;
    myleft+= obj.offsetLeft;
    obj= obj.offsetParent;
  }
  output.left = myleft;
  output.top = mytop;
  return output;
}

// метод получает координаты (+ width) базового элемента меню ( div ) а не самой ссылки
function getPosForTrain(obj){
	var parentDiv = $(obj).parent().parent(); // a -> p -> div
	var parentObj = new Object();
	var output = new Object();
	parentObj = $(parentDiv).get(0);
	var offset = $(parentDiv).offset();
	output.left = offset.left;
	output.top = offset.top;
	output.width = parentObj.offsetWidth;
	output.paddingLeft = $(parentDiv).css("padding-left");
	return output;
}

$().ready(function() {
  $('.menuPunkt').each(function (i) {
    if (!$(this).is(".selected")) {
      $(this).mouseover(function(){
        $(this).css('background', 'url(' + W_IMAGES + '/background/main_menu/sel_center.gif) repeat-x');
        if ($(this).is('.first')) $(this).prev().css('background', 'url(' + W_IMAGES + '/background/main_menu/sel_ferst_left.gif)');
        else $(this).prev().css('background', 'url(' + W_IMAGES + '/background/main_menu/sel_separator.gif)');
        $(this).next().css('background', 'url(' + W_IMAGES + '/background/main_menu/sel_separator.gif)');
      });
      $(this).mouseout(function(){
        $(this).css('background', 'none');
        if ($(this).is('.first')) $(this).prev().css('background', 'none');
        else {
          if (!$(this).prev().prev().is(".selected")) {
            $(this).prev().css('background', 'url(' + W_IMAGES + '/background/main_menu/bg_separator.gif)');
          }
        }
        if (!$(this).next().next().is(".selected")) {
          $(this).next().css('background', 'url(' + W_IMAGES + '/background/main_menu/bg_separator.gif)');
        }
      });
    }
  });
});
