// <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 at_display(x)
{
  var win = window.open();
  for (var i in x) win.document.write(i+' = '+x[i]+'<br>');
}

// ----- DropDown Control ------------------------------------------------------

var at_timeout = 50;

// ----- Show Aux -----

function at_show_aux(parent, child)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);

  p.className        = "active";

  if (c.offsetWidth <= 0)
  {
    c.style.position   = "absolute";
    c.style.visibility = "visible";
    c.style.display    = "block";
  }

  var direction = undefined;
  if (p.parentNode && p.parentNode["at_position"] == "x")
    direction = p.parentNode["at_direction"];

  var top   = (c["at_position"] == "y") ?  p.offsetHeight : 0;
  var left1 = (c["at_position"] == "x") ?  p.offsetWidth +2 : 0;
  var left2 = (c["at_position"] == "x") ? -c.offsetWidth -2 : 0;
  var left3 = (c["at_position"] == "x") ?  p.offsetWidth +2 : 0;

  for (; p; p = p.offsetParent)
  {
    if (p.style.position != 'absolute')
    {
      left1 += p.offsetLeft;
      left2 += p.offsetLeft;
      top   += p.offsetTop;
    }
    left3 += p.offsetLeft;
  }

  if (direction)
  {
    left = (direction == 'right') ? left1 : left2;
    c['at_direction'] = direction;
  }
  else
  {
    left = (left3+c.offsetWidth < document.body.offsetWidth) ? left1 : left2;
    c['at_direction'] = (left3+c.offsetWidth < document.body.offsetWidth) ? 'right' : 'left';
  }

  c.style.position   = "absolute";
  c.style.visibility = "visible";
  c.style.display    = "block";
  c.style.top        = top +'px';
  c.style.left       = left+'px';
}

// ----- Hide Aux -----

function at_hide_aux(parent, child)
{
	//MM_swapImgRestore();
	
//alert(parent);
//alert(document.getElementById(parent).id)
	//alert( document.getElementById(parent).id.substr(2)    );
	var parentNav = eval(document.getElementById(parent).id.substr(2));
	//alert(parentNav.name)
	//alert(parentNavClicked)
	/*if (parentNav == parentNavClicked) {
		var nid = 3;
	} else {
		var nid = 1;
	}*/var nid = 1;
	parentNav.src = baseUrl+"images/"+parentNav.name+"_"+nid+langSuffix+".jpg";
  document.getElementById(parent).className        = "parent";
  document.getElementById(child).style.visibility = "hidden";
  document.getElementById(child).style.display    = "block";
}

// ----- Show -----

function at_show(e)
{
	//var parentNav = document.getElementById(document.getElementById(parent).id.slice(2));
	//alert(parentNav.name);
	//parentNav.src = baseUrl+"images/"+parentNav.name+"_2.jpg";
	//MM_swapImage(parentNav.name,'',baseUrl+'images/'+parentNav.name+'_2.jpg',1)
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);
  clearTimeout(c["at_timeout"]);

  at_show_aux(p.id, c.id);
  var parentNav = eval(p.id.slice(2));
  //parentNavClicked = parentNav;
	//alert(parentNav.name);
parentNav.src = baseUrl+"images/"+parentNav.name+"_2.jpg";
MM_swapImage(parentNav.name,'',baseUrl+'images/'+parentNav.name+'_2'+langSuffix+'.jpg',1)

}

// ----- Hide -----

function at_hide()
{
  var c = document.getElementById(this["at_child"]);
  c["at_timeout"] = setTimeout("at_hide_aux('"+this["at_parent"]+"', '"+this["at_child"]+"')", at_timeout);
}

// ----- Attach -----

function at_attach(parent, child, position)
{
  p = document.getElementById(parent);
  c = document.getElementById(child );

  p["at_child"]    = c.id;
  c["at_child"]    = c.id;
  p["at_parent"]   = p.id;
  c["at_parent"]   = p.id;
  c["at_position"] = position;

  p.onmouseover = at_show;
  p.onmouseout  = at_hide;
  c.onmouseover = at_show;
  c.onmouseout  = at_hide;
}

// ----- DropDown Menu ---------------------------------------------------------


function getURL (u) {
	alert(u)
}
// ----- Build Aux -----

var windowWidth = 800;
var windowHeight = 400;
function popup (file) {
	var myleft=(screen.width)?(screen.width-windowWidth)/2:100;
	var mytop=(screen.height)?(screen.height-windowHeight)/2:100;
	window.open(file,'mywindow',"menubar=0,resizable=1,location=0,directories=0,width="+windowWidth+",height="+windowHeight+",top="+mytop+",left="+myleft);
}

function dhtmlmenu_build_aux(parent, child, position)
{
  document.getElementById(parent).className = "parent";
	var subnavWidth = eval(parent+"_width");
	//alert(subnavWidth);
  document.write('<div class="vert_menu" id="'+parent+'_child" style="width:'+subnavWidth+';">');
  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], "x");
    }
	
    else {
		var useCustomJsFunc = child[i].indexOf("js:") > -1;		//check for javascript function to execute
		if (useCustomJsFunc) {			
			var jsurl = child[i].replace(/js:/g,"");
			var arrJsFunc = jsurl.split(",");
			var funcToExecute = arrJsFunc[0];
			var funcArgument = arrJsFunc[1];
			var catchPage = arrJsFunc[2];				// only run if on this page
			//alert(funcToExecute+":::::"+funcArgument);
			var url = "javascript:"+funcToExecute+"('"+funcArgument+"','"+catchPage+"');";
			//arrCustomFunctionIds.push(newI);
		} else if (child[i].indexOf("openWin:") > -1) {
			var funcArgument = child[i].split(":")[1];
			var url = "javascript:popup('"+funcArgument+"')";
		} else {
			//var url = "top.location.href='"+baseUrl+child[i]+"'";
			if (child[i].indexOf("http://")>-1) {
				var url = "top.location.href='"+child[i]+"'";
			} else {
				var url = "top.location.href='"+baseUrl+child[i]+"'";
			}
		}
		/*document.write('<div style="border-bottom: 1px solid #b8b8b8; padding: 5px 4px 5px 6px; width:100%; background-color:#8f8f8f; cursor:pointer;" onmouseover="this.style.backgroundColor=\'#6c6c6c\'" onmouseout="this.style.backgroundColor=\'#8f8f8f\'" id="'+parent+'_'+n+'" onclick="'+url+'"><a>'+i+'</a></div>');*/
		document.write('<table border="0" cellpadding="0" cellspacing="0" style="margin-top: 4px; height: 21px; width: 100%;cursor:pointer;" id="'+parent+'_'+n+'" onclick="'+url+'"><tr><td style="background:url('+baseUrl+'images/subnav_left.png);width:11px;"><img src="'+baseUrl+'images/blank_pixel.gif" width="11"/></td><td style="background:url('+baseUrl+'images/subnav_middle.jpg);width:'+subnavWidth+';"><a onmouseover="this.style.color=\'#8653A7\'" onmouseout="this.style.color=\'#521F73\'">'+i+'</a></td></td><td style="background:url('+baseUrl+'images/subnav_right.png);width:11px;"><img src="'+baseUrl+'images/blank_pixel.gif" width="11"/></td></tr></table>');
	}
    n++;
  }

  document.write('</div>');

  at_attach(parent, parent+"_child", position);
}

// ----- Build -----

function dhtmlmenu_build(menu)
{
  for (var i in menu) dhtmlmenu_build_aux(i, menu[i], "y");
}
