
function rollOver(item)
{
	if(document.images)
		eval(item.id+'.src='+item.id+'_active.src');
}

function rollOut(item)
{
	if(document.images)
		eval(item.id+'.src='+item.id+'_passive.src');
}

// ==============================================
// ?????????? ??????????
// ==============================================
var browser = new Browser();
var activeButton = null;

// ==============================================
// ??????? ?????????? ???????
// ==============================================
function Browser()
{
  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

// ========================================================
// ??????? ??? ???? node ?????????? ????????? ????????????
// ??????? ? ?????? tagName ? ??????? className
// ========================================================
function getContainerWith(node, tagName, className)
{
  // ??????? ? ???? node, ???? ????????? ???????????? ???????
  // ? ?????? tagName ? ??????? className
  while (node != null)
  {
    if (node.tagName != null && node.tagName == tagName &&
        hasClassName(node, className))
      return node;
    node = node.parentNode;
  }
  return node;
}

// ============================================================================
// ??????? ?????????? true, ???? ? ???????? el ??? ?????? ????? name
// ??????, ?????????? ???????, ??? ??????? ????? ???????????? ? ??????????
// ??????? ???????????? (???????? ??????? ??????????? ?????????)
// ============================================================================
function hasClassName(el, name)
{
  var i, list;

  list = el.className.split(" ");
  for (i = 0; i < list.length; i++)
    if (list[i] == name)
      return true;

  return false;
}

// ==============================================
// ??????? ??????? ? ???????? el ??????????????
// ? ?????? name
// ==============================================
function removeClassName(el, name)
{
  var i, curList, newList;

  if (el.className == null) return;

  newList = new Array();
  curList = el.className.split(" ");
  j = 0;
  for (i = 0; i < curList.length; i++)
     if (curList[i] != name) newList[j++] = curList[i];
  el.className = newList.join(" ");
}

// ==============================================
// ??????? ?????????? ?????????????? ?????????
// ?????????? ???????? ???????????? ????????
// ==============================================
function getPageOffsetLeft(el)
{
  var x;

  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);

  return x;
}

// ==============================================
// ??????? ?????????? ???????????? ?????????
// ?????????? ???????? ???????????? ????????
// ==============================================
function getPageOffsetTop(el)
{
  var y;

  y = el.offsetTop;
  if (el.offsetParent != null)
  	y += getPageOffsetTop(el.offsetParent);

  return y;
}

// ==============================================
// ????????? ?????? ???? ?? ?????? ????
// ==============================================
function buttonClick(event, menuId)
{
  var button;

  // ??????? ???????? ???????
  if (browser.isIE)
    button = window.event.srcElement;
  else
    button = event.currentTarget;

  if(button.tagName == 'IMG') button = button.parentNode;
  /*
  if(button.tagName == 'SPAN')
  {
    	button = button.parentNode;
		button.blur();
		return false;
  };
  */
  if(button.tagName == 'A')
  {
  	button.blur();
  	button = button.parentNode;
  };
  button = document.getElementById(button.id);

  // ????????? ?????? ??????????? ????
  // ??? ?? ?????? ???? ?????? ?????? ??????
  buttonWidth = button.offsetWidth;
  buttonMenu = document.getElementById(menuId);
  if(buttonMenu.offsetWidth < buttonWidth)
		buttonMenu.style.width = buttonWidth;

  if (button.menu == null)
  {
  	// ? ?????? ??????? ???????? menu, ?????????
	// ? ??? ?????? ?? ???????? ? ? ?????? ?????????????
	// ?????????????? ????
    button.menu = document.getElementById(menuId);
    if(button.menu.isInitialized == null) menuInit(button.menu);
  }

  // ????????????? ?????????? ??????? mouseout ?? ??????
  if (button.onmouseout == null)
		button.onmouseout = buttonOrMenuMouseout;

  // ???? ?????? ?????? ??? ???????? ? ???????
  if (button == activeButton) return false;

  // ???? ??? ???? ???????? ?????? - ?????? ? ??????????
  if (activeButton != null) resetButton(activeButton);

  // ???? ?????? ?????????? ?????? - ?????? ? ????????
  // ? ?????????? ????????? ? ??? ????,
  // ? ????????? ?????? ???????????? ??
  if (button != activeButton)
  {
    depressButton(button);
    activeButton = button;
  }
  else activeButton = null;

  return false;
}

// ==============================================
// ????????? ?????? ????:
// 1. ????????? ??????
// 2. ????????? ????????????
// 3. ?????????? ??????? ??????????? ????
// 4. ??????????? ??????????? ????
// ==============================================
function depressButton(button)
{
  var x, y;

  // ???????? ????? ??????? ??????
  button.className += " menuButtonHighlight";
  //button.className += " menuButtonActive";
  button.style.backgroundColor = "rgb(102, 102, 102)";

  // ????????????? ?????????? ??????? ???????? ????????? ????
	// ??? ?????? ? ??? ??????????? ????, ???? ??? ?? ???????????
  if (button.onmouseout == null)
    button.onmouseout = buttonOrMenuMouseOut;
  if (button.menu.onmouseout == null)
    button.menu.onmouseout = buttonOrMenuMouseOut;

  // ????????? ??????? ??????????? ???? (??? ??????? ???????)
  x = getPageOffsetLeft(button);
  y = getPageOffsetTop(button) + button.offsetHeight;

	// ???????????? ????????? ???? ????? ???????,
	// ????? ??? ?? ???????? ?? ??????? ?????? ??????? ????
	mt = document.getElementById("menuTable");
	rightPadding = mt.offsetWidth - (x + button.menu.offsetWidth + 1);
	if(rightPadding < 0) x += rightPadding;

	// ????????????? ? ?????????? ?????????? ????
  button.menu.style.left = x + "px";
  button.menu.style.top  = y + "px";
  button.menu.style.visibility = "visible";
}

// ==============================================
// ?????????????? ??????????????? (???????????)
// ????????? ?????? ????
// ==============================================
function resetButton(button)
{
  // ??????????????? ????? ??????
  removeClassName(button, "menuButtonHighlight");
  //removeClassName(button, "menuButtonActive");
  button.style.backgroundColor = "transparent";

  // ???????? ???? ??????, ???????? ?????????????? ??? ???????
  if (button.menu != null)
  {
    closeSubMenu(button.menu);
    button.menu.style.visibility = "hidden";
  }
}

// ==============================================
// ????????????? ??????????? ????:
// 1. ????????????? ??????????? ??????? (IE)
// 2. ???????????? ??????? ?? ??????? ????
// 3. ?????????? ???????? ? ?????????? (IE)
// ==============================================
function menuInit(menu)
{
  var itemList, spanList;
  var textEl, arrowEl;
  var itemWidth;
  var w, dw;
  var i, j;

  // ??????? ? ???? SPAN-????????? ??? IE
	// ???????? ?????? ???????, ???? ?? ????
  if (browser.isIE)
  {
    //menu.style.lineHeight = "2.5ex";
    spanList = menu.getElementsByTagName("SPAN");
    for (i = 0; i < spanList.length; i++)
      if (hasClassName(spanList[i], "menuItemArrow"))
		  {
        spanList[i].style.fontFamily = "Webdings";
        spanList[i].firstChild.nodeValue = "4";
      }
  }

  // ?????????? ?????? ???????? ????
  itemList = menu.getElementsByTagName("A");
  if (itemList.length > 0) itemWidth = itemList[0].offsetWidth;
  else return;

  // ? ????????? ???? ?? ????????? ????????? ??????,
  // ????? ??????? ????????????? ?? ??????? ????
  for (i = 0; i < itemList.length; i++)
  {
    spanList = itemList[i].getElementsByTagName("SPAN");
    textEl  = null;
    arrowEl = null;
    for (j = 0; j < spanList.length; j++)
	{
      if (hasClassName(spanList[j], "menuItemText"))
        textEl = spanList[j];
      if (hasClassName(spanList[j], "menuItemArrow"))
        arrowEl = spanList[j];
    }
    if (textEl != null && arrowEl != null)
      textEl.style.paddingRight = (itemWidth
        - (textEl.offsetWidth + arrowEl.offsetWidth)) + "px";
  }

	// ????????? ? IE ???????? ?????????,
	// ????? ????? ????????? ??????
	// ??? ??????? ???????? ????
  if ((browser.isIE)&&(itemList.length > 0))
  {
    w = itemList[0].offsetWidth;
    itemList[0].style.width = w + "px";
    dw = itemList[0].offsetWidth - w;
    w -= dw;
    itemList[0].style.width = w + "px";
  }

  // ???????? ???? ??? ?????????????????????
  menu.isInitialized = true;
}

// ==============================================
// ????????? ????????? ????????? ?? ??????
// ???????? ????
// ==============================================
function buttonMouseOver(event, menuId)
{
  var button;

  // ???? ?? ???? ?????? ?? ??????? - ?????????? ??????
  if (activeButton == null)
  {
    buttonClick(event, menuId);
    return;
  }

  // ??????? ?????? ?? ??????
  if (browser.isIE)
    button = window.event.srcElement;
  else
    button = event.currentTarget;

  if(button.tagName == 'IMG') button = button.parentNode;
  if(button.tagName == 'A') button = button.parentNode;
  button = document.getElementById(button);

  // ???? ? ?????? ?????? ??????? ?????? ??????,
  // ?? ?????? ???????? ??????? ??????
  if (activeButton != null && activeButton != button)
    buttonClick(event, menuId);
}

// ==============================================
//
function menuItemMouseOver(event, menuId)
{
  var item, menu, x, y;

	// ??????? ??????? ????, ?? ??????? ????????? ???????
	// ? ??? ????????
  if (browser.isIE)
    item = getContainerWith(window.event.srcElement, "A", "menuItem");
  else
    item = event.currentTarget;

  menu = getContainerWith(item, "DIV", "menu");

  // ????????? ??? ???????? ??????? ? ?????? ???????? ??????? ????
  if (menu.activeItem != null) closeSubMenu(menu);
  menu.activeItem = item;

	// ???????????? ??????? ????
  item.className += " menuItemHighlight";

  // ?????????????? ???????, ???? ??? ??? ?? ???????
  if (item.subMenu == null)
{
    item.subMenu = document.getElementById(menuId);
    if (item.subMenu.isInitialized == null)
      menuInit(item.subMenu);
  }

  // ????????????? ?????????? ??????? mouseout ??? ???????,
  // ???? ??? ?? ??????????
  if (item.subMenu.onmouseout == null)
    item.subMenu.onmouseout = buttonOrMenuMouseOut;

  // ????????????? ??????? ??????? ?? ?????? ?????? ????
  x = getPageOffsetLeft(item) + item.offsetWidth;
  y = getPageOffsetTop(item);

  // ????????? ??????? ????? ???????, ?????
  // ???? ???? ? ??????? ?????????
  var maxX, maxY;

  if (browser.isNS)
	{
    maxX = window.scrollX + window.innerWidth;
    maxY = window.scrollY + window.innerHeight;
  }
  if (browser.isIE)
	{
    maxX = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) +
      (document.documentElement.clientWidth != 0 ? document.documentElement.clientWidth : document.body.clientWidth);
    maxY = Math.max(document.documentElement.scrollTop, document.body.scrollTop) +
      (document.documentElement.clientHeight != 0 ? document.documentElement.clientHeight : document.body.clientHeight);
  }
  maxX -= item.subMenu.offsetWidth;
  maxY -= item.subMenu.offsetHeight;

  if (x > maxX)
    x = Math.max(0, x - item.offsetWidth - item.subMenu.offsetWidth
      + (menu.offsetWidth - item.offsetWidth));
  y = Math.max(0, Math.min(y, maxY));

  // ????????????? ? ?????????? ???????
  item.subMenu.style.left = x + "px";
  item.subMenu.style.top  = y + "px";
  item.subMenu.style.visibility = "visible";

  // Stop the event from bubbling.
  // ????????????? ???????????? ???????
  if (browser.isIE)
    window.event.cancelBubble = true;
  else
    event.stopPropagation();
}

// ==============================================
//
function buttonOrMenuMouseOut(event)
{
  var el;

  // ???? ??? ???????? ?????? ? ???????
  if (activeButton == null) return;

  // ??????? ???????, ?? ??????? ????????? ???????
  if (browser.isIE)
    el = window.event.toElement;
  else if (event.relatedTarget != null)
    el = (event.relatedTarget.tagName ? event.relatedTarget : event.relatedTarget.parentNode);

  // ???? ??????? ?? ???????? ?????? ????, ?????????? ???????? ??????
  if (getContainerWith(el, "DIV", "menu") == null)
  {
    resetButton(activeButton);
    activeButton = null;
  }
}

// ==============================================
// ??????????? ???????? ??????????? ???? ? ????
// ???????? ???????? ????
// ==============================================
function closeSubMenu(menu)
{
  if (menu == null || menu.activeItem == null) return;

  // ?????????? ????????? ??? ???????
  if (menu.activeItem.subMenu != null)
  {
    closeSubMenu(menu.activeItem.subMenu);
    menu.activeItem.subMenu.style.visibility = "hidden";
    menu.activeItem.subMenu = null;
  }
  removeClassName(menu.activeItem, "menuItemHighlight");
  menu.activeItem = null;
}

// ==============================================
//
function menuMouseOver(event)
{
  var menu;

	removeClassName(activeButton, "menuButtonHighlight");
	activeButton.className += " menuButtonActive";

  // ??????? ???????, ?? ??????? ????????? ???????
  if (browser.isIE)
    menu = getContainerWith(window.event.srcElement, "DIV", "menu");
  else
    menu = event.currentTarget;

  // ????????? ??? ???????? ???????
  if (menu.activeItem != null) closeSubMenu(menu);
}

// ==============================================
//??????? ?? ????????? ??????
// ==============================================
function gopage(pagelink)
{
	window.location.href = pagelink;
}
