function at_display(x)
{
  var win = window.open();
  for (var i in x) win.document.write(i+' = '+x[i]+'<br>');
} 
var at_timeout = 1; 
function at_show_aux(parent, child)
{
  var p = $(parent);
  var c = $(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  : 0;
  var left2 = (c["at_position"] == "x") ? -c.offsetWidth  : 0;
  var left3 = (c["at_position"] == "x") ?  p.offsetWidth  : 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+4)+'px';
  
  //$(cMenu).className="aNormal"; 
 // cMenu=parent.toString(); 
  //$(cMenu).className="aHover"; 
} 

function at_hide_aux(parent, child)
{
  $(parent).className        = "parent";
  $(child ).style.visibility = "hidden";
  $(child ).style.display    = "block";
  //$(cMenu).className="aHover"; 
}
 
function at_show(e)
{
  var p = $(this["at_parent"]);
  var c = $(this["at_child" ]);
  at_show_aux(p.id, c.id);
  clearTimeout(c["at_timeout"]);
  hideSelect(0);
	
} 
function at_hide()
{
  var c = $(this["at_child"]);
  c["at_timeout"] = setTimeout("at_hide_aux('"+this["at_parent"]+"', '"+this["at_child" ]+"')", at_timeout); 
  hideSelect(1);
  if($("searchtype")){$("searchtype").style.visibility='visible';}
}

function at_attach(parent, child, position)
{
  p = $(parent);
  c = $(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;
  p.onclick 	= at_hide;
  c.onmouseover = at_show;
  c.onmouseout  = at_hide;
  c.onclick  	= at_hide;
}

function cutstr(str){
	if (str.length>35){
		//str=str.substr(0,30)+"...";
		var sarr=str.split(" ");
		var str1="";
		for (var i=0;i<sarr.length-2;i++){
			str1+=sarr[i]+" ";
		} 
		str1+=sarr[sarr.length-2];
		str=cutstr2(str1)+" ...";
	}
	return str;
}
function cutstr2(str2){
	if (str2.length>30){
		//str=str.substr(0,30)+"...";
		var sarr=str2.split(" ");
		var str1="";
		for (var i=0;i<sarr.length-1;i++){
			str1+=sarr[i]+" ";
		} 
		str2=str1;
	}
	return str2;
}

function dhtmlmenu_build_aux(parent, child, position)
{
  $(parent).className = "parent";
  document.write('<div  id="'+parent+'_child" style="width:auto;height:auto; display:none;">')
  document.write ('<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"MenuTbl\" id="'+parent+'_mgt"  id="bTbl"><tr class=\"MenuTblT\"><td></td></tr><tr class=\"MenuTblM\"><td style=\"padding-left:5px;\">');
  var n = 0;
  for (var i in child)
  {
    if (i == '-')
    {
      $(parent).href = child[i];
      continue;
    }

    if (typeof child[i] == "object")
    {
      document.write('<a class="parent1" id="'+parent+'_'+n+'" style=\"background:url(/jwx/Images/Arrow.gif) no-repeat right center !important;background:url(/jwx/Images/Arrow.gif) no-repeat right 4px;\">'+i+'</a>');
      dhtmlmenu_build_aux(parent+'_'+n, child[i], "x");
    }
    else{ 
		if(child[i]=="http://222.209.223.127:84/"){
			document.write('<div class="greyArrow1"><a id="'+parent+'_'+n+'" href="'+child[i]+'" target="_blank" >'+i+'</a></div>');
		}else{
			document.write('<div class="greyArrow1"><a id="'+parent+'_'+n+'" href="'+child[i]+'"  title=\"'+i+'\">'+cutstr(i)+'</a></div>');
		}
	}
    n++;
  }
  document.write('</td></tr><tr class=\"MenuTblB\"><td class=\"col9\"></td></tr></table><div style="clear:both;"></div></div>');  
  	at_attach(parent, parent+"_child", position);  
	
}

function dhtmlmenu_build(menu)
{
  for (var i in menu) dhtmlmenu_build_aux(i, menu[i], "y");
}

