
// ***** Popup Control *********************************************************

// ***** at_show_aux *****

function at_show_aux(parent, child)
{
    var p = document.getElementById(parent);
    var c = document.getElementById(child );

    c.style.position   = "absolute";
    c.style.visibility = "visible";

    var top  = (c["at_position"] == "y") ? p.offsetHeight : 0;
    var left = (c["at_position"] == "x") ? p.offsetWidth - 10 : 0;

    var XY = Sys.UI.DomElement.getLocation(p);
    Sys.UI.DomElement.setLocation(c, XY.x, XY.y);
    var XY2 = Sys.UI.DomElement.getLocation(c);
    Sys.UI.DomElement.setLocation(c, XY.x - (XY2.x - XY.x) + left, XY.y - (XY2.y - XY.y) + top);
}

// ***** at_show *****

function at_show()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  clearTimeout(document["at_timeout"]);
  at_hide_aux(c["at_nivel"]);
  document["atual"] = c.id;
  at_show_aux(p.id, c.id); 
  if (p.className == 'MenuET_sub') {
    p.className = 'MenuET_sub_hover';
  }
}

function at_hide_aux(nivel)
{
    var cont;
    for (cont = 0; cont < document["itens"].length; cont++) {
       
        if (document["itens"][cont]["at_nivel"] >= nivel && 
            document["itens"][cont].id != document["atual"]) {
            
            document["itens"][cont].style.visibility = 'hidden';
            
            var pai = document.getElementById(document["itens"][cont]["at_parent"]);
            
            if (pai.className == 'MenuET_sub_hover') { // && document["itens"][cont]["at_nivel"] > 0) {
                pai.className = 'MenuET_sub';
            }
        }
    }
}

// ***** at_hide *****

function at_hide()
{
  document["atual"] = '';
  document["at_timeout"] = setTimeout("at_hide_aux(-1);", 333);
}

// ***** at_click *****

function at_click()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  if (c.style.visibility != "visible") at_show_aux(p.id, c.id); else c.style.visibility = "hidden";
  return false;
}

// ***** at_attach *****

// PARAMETERS:
// parent   - id of the parent html element
// child    - id of the child  html element that should be droped down
// showtype - "click" = drop down child html element on mouse click
//            "hover" = drop down child html element on mouse over
// position - "x" = display the child html element to the right
//            "y" = display the child html element below
// cursor   - omit to use default cursor or specify CSS cursor name

function at_attach(parent, child, showtype, position, cursor, nivel)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);

  p["at_parent"]     = p.id;
  c["at_parent"]     = p.id;
  p["at_child"]      = c.id;
  c["at_child"]      = c.id;
  p["at_position"]   = position;
  c["at_position"]   = position;
  c["at_nivel"]      = nivel;

  c.style.position   = "absolute";
  c.style.visibility = "hidden";

  if (cursor != undefined) p.style.cursor = cursor;

  switch (showtype)
  {
    case "click":
      p.onclick     = at_click;
      //p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
    case "hover":
      p.onmouseover = at_show;
      p.onmouseout  = function() { document["atual"] = "" };
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
  }
  
    if (document["itens"] == undefined) {
        document["itens"] = new Array;
    }
    document["itens"].push(c);
}
