var now_hint_popupwindow = null;

function _hintpop_at_display(x)
{
  var win = window.open();
  for (var i in x) win.document.write(i+' = '+x[i]+'<br>');
}

// ----- Show Aux -----

function _hintpop_at_show_aux(p, c)
{
  c["at_parent"] = p.id;

  var d = document.getElementById('entry_hintpopup_window_data');

  var top  = p.offsetHeight + c["at_pos"];
  var left = 0;

  for (; p; p = p.offsetParent)
  {
    top  += p.offsetTop;
    left += p.offsetLeft;
  }

  c.style.position   = "absolute";
  c.style.top        = top +'px';
  c.style.left       = left+'px';
  c.style.display = "block";
						
}

// ----- Show -----

function _hintpop_at_show()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  clearTimeout(c["at_timeout"]);
					
  _hintpop_at_show_aux(p, c);
 
}

// ----- Hide -----

function _hintpop_at_hide()
{
  var child = document.getElementById(this["at_child" ]);
  
 if(child['at_showtype'] == "click")
 {
	clearTimeout(child["at_timeout"]);
	child["at_timeout"] = setTimeout("document.getElementById('"+child.id+"').style.display = 'none'", child["at_time"]);
 }
 else
 {
	//c.style.display = 'none';
	clearTimeout(child["at_timeout"]);
	child["at_timeout"] = setTimeout("document.getElementById('"+child.id+"').style.display = 'none'", child["at_time"]);

 }
}

// ----- Click -----

function _hintpop_at_click()
{ 
  if(now_hint_popupwindow != null)
	{
		now_hint_popupwindow.style.display = 'none';
	}

  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);
  var data = document.getElementById(p["at_datachild"]);

  clearTimeout(c["at_timeout"]);

  document.getElementById("entry_hintpopup_window_data").innerHTML = data.innerHTML;

  if (c.style.display != "block") _hintpop_at_show_aux(p, c);
  else c.style.display = "none";
  
  now_hint_popupwindow = c;

  return false;
}

// ----- Hover -----

function _hintpop_at_hover()
{
  if(now_hint_popupwindow != null)
	{
		now_hint_popupwindow.style.display = 'none';
	}

  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);
  var data = document.getElementById(p["at_datachild"]);

  clearTimeout(c["at_timeout"]);

  document.getElementById("entry_hintpopup_window_data").innerHTML = data.innerHTML;

  _hintpop_at_show_aux(p, c);

  now_hint_popupwindow = c;
  
}

// ----- Attach -----

function _hintpop_at_attach(parent, child, showtype, cursor , timeout , pos)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);
  var w = document.getElementById("_hint_popupwindow");

  p["at_parent"]     = p.id;
  w["at_parent"]     = p.id;
  p["at_child"]      = w.id;
  w["at_child"]      = w.id;

  p["at_datachild"]	 = c.id;

  w["at_showtype"]   = showtype;
  w["at_time"]		 = timeout;
  w["at_pos"]		 = pos;

  if (cursor != undefined) p.style.cursor = cursor;

  switch (showtype)
  {
    case "click":
      p.onclick     = _hintpop_at_click;
      p.onmouseout  = _hintpop_at_hide;
      break;
    case "hover":
      p.onmouseover = _hintpop_at_hover;
      p.onmouseout  = _hintpop_at_hide;
      break;
  }

  w.onmouseover = _hintpop_at_show;
  w.onmouseout  = _hintpop_at_hide;
}
