// <script>
// Copyright (C) 2005 Ilya S. Lyubinskiy. All rights reserved.
// Technical support: http://www.php-development.ru/
//
// YOU MAY NOT
// (1) Remove or modify this copyright notice.
// (2) Distribute this code, any part or any modified version of it.
//     Instead, you can link to the homepage of this code:
//     http://www.php-development.ru/javascripts/menu.php.
//
// YOU MAY
// (1) Use this code on your website.
// (2) Use this code as a part of another product provided that
//     its main use is not creating javascript menus.
//
// NO WARRANTY
// This code is provided "as is" without warranty of any kind, either
// expressed or implied, including, but not limited to, the implied warranties
// of merchantability and fitness for a particular purpose. You expressly
// acknowledge and agree that use of this code is at your own risk.
function ats_display(x1) {
  var win = window.open();
  for (var i in x1) win.document.write(i+' = '+x1[i]+'<br>');
}
// ----- DropDown Control ------------------------------------------------------
var ats_timeout = 50;
// ----- Show Aux -----
function ats_show_aux(parent, child) {
  var p1 = document.getElementById(parent);
  var c1 = document.getElementById(child);
  p1.className        = "active";
  if (c1.offsetWidth <= 0) {
	c1.style.position   = "absolute";
	c1.style.visibility = "visible";
	c1.style.display    = "block";
  }
  var direction = undefined;
  if (p1.parentNode && p1.parentNode["at_position"] == "x1")
    direction = p.parentNode["at_direction"];
  var top   = (c1["ats_position"] == "y1") ?  p1.offsetHeight-23 : 0;
  var left1 = (c1["ats_position"] == "x1") ?  p1.offsetWidth +0 : +182;
  var left2 = (c1["ats_position"] == "x1") ? -c1.offsetWidth -2 : 0;
  var left3 = (c1["ats_position"] == "x1") ?  p1.offsetWidth +2 : 0;
  for (; p1; p1 = p1.offsetParent) {
	if (p1.style.position != 'absolute') {
	  left1 += p1.offsetLeft;
	  left2 += p1.offsetLeft;
	  top   += p1.offsetTop;
	}
	left3 += p1.offsetLeft;
  }
  if (direction) {
	left = (direction == 'right') ? left1 : left2;
	c1['ats_direction'] = direction;
  }
  else {
	left = (left3+c1.offsetWidth < document.body.offsetWidth) ? left1 : left2;
	c1['ats_direction'] = (left3+c1.offsetWidth < document.body.offsetWidth) ? 'right' : 'left';
  }
  c1.style.position   = "absolute";
  c1.style.visibility = "visible";
  c1.style.display    = "block";
  c1.style.top        = top +'px';
  c1.style.left       = left+'px';
}
// ----- Hide Aux -----
function ats_hide_aux(parent, child) {
  document.getElementById(parent).className        = "parent";
  document.getElementById(child ).style.visibility = "hidden";
  document.getElementById(child ).style.display    = "block";
}
// ----- Show -----
function ats_show(e) {
  var p1 = document.getElementById(this["ats_parent"]);
  var c1 = document.getElementById(this["ats_child" ]);
  ats_show_aux(p1.id, c1.id);
  clearTimeout(c1["ats_timeout"]);
}
// ----- Hide -----
function ats_hide() {
  var c1 = document.getElementById(this["ats_child"]);
  c1["ats_timeout"] = setTimeout("ats_hide_aux('"+this["ats_parent"]+"', '"+this["ats_child" ]+"')", ats_timeout);
}
// ----- Attach -----
function ats_attach(parent, child, position) {
  p1 = document.getElementById(parent);
  c1 = document.getElementById(child );
  p1["ats_child"]    = c1.id;
  c1["ats_child"]    = c1.id;
  p1["ats_parent"]   = p1.id;
  c1["ats_parent"]   = p1.id;
  c1["ats_position"] = position;
  p1.onmouseover = ats_show;
  p1.onmouseout  = ats_hide;
  c1.onmouseover = ats_show;
  c1.onmouseout  = ats_hide;
}
// ----- DropDown Menu ---------------------------------------------------------
// ----- Build Aux -----
function dhtmlmenu_build_aux(parent, child, position) {
  document.getElementById(parent).className = "parent";
  document.write('<div class="vert_menus" id="'+parent+'_child">');
  var n = 0;
  for (var i in child) {
	if (i == '-') {
	  document.getElementById(parent).href = child[i];
	  continue;
	}
	if (typeof child[i] == "object") {
	  document.write('<a class="parent" id="'+parent+'_'+n+'">'+i+'</a>');
	  dhtmlmenu_build_aux(parent+'_'+n, child[i], "x1");
	}
	else document.write('<a id="'+parent+'_'+n+'" href="'+child[i]+'">'+i+'</a>');
	n++;
  }
  document.write('</div>');
  ats_attach(parent, parent+"_child", position);
}
// ----- Build -----
function dhtmlmenu_build(menus) {
  for (var i in menus) dhtmlmenu_build_aux(i, menus[i], "y1");
}

