﻿var _blnBrowserIE = null
var _blnIE6 = null

if (navigator.userAgent.indexOf("MSIE") >= 0) {
    _blnBrowserIE = true;
    if (navigator.userAgent.indexOf("MSIE 6.0") >= 0) {
        _blnIE6 = true;
    }
    else {
        _blnIE6 = false;
    }
}
else {
    _blnBrowserIE = false;
}
// ----- Popup Control ----

function displaymenu(x) {

  var win = window.open();
  for (var i in x) win.document.write(i+' = '+x[i]+'<br>');
}

// ----- Show Aux -----

function showchild(parent, child)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);

  //var top  = (c["menu_position"] == "y") ? p.offsetHeight -1 : 0;
  var top = (c["menu_position"] == "y") ? p.offsetHeight : 0; //Overlap of 1px is not cool when doing transparency.
  var left = (c["menu_position"] == "x") ? p.offsetWidth + 2 : 0;
  var cposition = c["menu_changeposition"]
  for (; p; p = p.offsetParent)
  {
    top  += p.offsetTop;
    left += p.offsetLeft;
  }
  p = document.getElementById(parent);
  c.style.position   = "absolute";
  c.style.top        = top +'px';
  //c.style.left       = left+'px';
  //alert(p)
  if ((left + c.offsetWidth) > p.parentNode.parentNode.offsetWidth)
      c.style.left = ((left + cposition) - ((left + c.offsetWidth) - p.parentNode.parentNode.offsetWidth)) + 'px';
  else
    c.style.left = ((left + cposition)) + 'px';
  
  //alert(left + c.offsetWidth)
  //alert((left + c.offsetWidth) - p.parentNode.parentNode.offsetWidth)
  //c.style.left = ((left + cposition)) + 'px';
  c.style.visibility = "visible";
}

// ----- Show -----

function showmenu()
{
  var p = document.getElementById(this["menu_parent"]);
  var c = document.getElementById(this["menu_child"]);

  //p.style.backgroundImage = "url('assets/images/bkgMenu_ovr.gif')";

  p.className = p.className.replace('_off','_on')

  //p.style.backgroundRepeat = "repeat x"

  showchild(p.id, c.id);
  clearTimeout(c["at_timeout"]);
}

// ----- Hide -----

function hidemenu()
{
  var c = document.getElementById(this["menu_child"]);
  var p = document.getElementById(this["menu_parent"]);
  
  p.className = p.className.replace('_on', '_off')
  //document.getElementById(this["menu_parent"]).style.backgroundImage = ""
  //p.style.backgroundColor = ""
  c["at_timeout"] = setTimeout("document.getElementById('"+c.id+"').style.visibility = 'hidden'", 50);
}

// ----- Click -----

function menuclick()
{
  var p = document.getElementById(this["menu_parent"]);
  var c = document.getElementById(this["menu_child" ]);

  if (c.style.visibility != "visible")
       showchild(p.id, c.id);
  else c.style.visibility = "hidden";

  return false;
}

// ----- Attach -----

// PARAMETERS:
// parent   - id of visible html element
// child    - id of invisible html element that will be dropdowned
// showtype - "click" = you should click the parent to show/hide the child
//            "hover" = you should place the mouse over the parent to show
//                      the child
// position - "x" = the child is displayed to the right of the parent
//            "y" = the child is displayed below the parent
// cursor   - Omit to use default cursor or check any CSS manual for possible
//            values of this field

function drawmenu(parent, child, showtype, position, cursor, loc)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);
  var moveleft = 0
 
//  if(loc ==5){
//	if (window.ActiveXObject){
//		moveleft = -38
//	}
//	else{
//		moveleft = -44
//	}
//  }

  p["menu_parent"]     = p.id;
  c["menu_parent"]     = p.id;
  p["menu_child"]      = c.id;
  c["menu_child"]      = c.id;
  p["menu_position"]   = position;
  c["menu_position"]   = position;
  c["menu_changeposition"] = moveleft
  c["menu_children"] = c.getElementsByTagName("div")



  c.style.position   = "absolute";
  c.style.visibility = "hidden";

  //if (_blnIE6)
    //IE6PNGHelper(c)
 
   c.style.width = (c.offsetWidth)
  if (cursor != undefined) p.style.cursor = cursor;

  switch (showtype)
  {
      case "click":
          p.onclick = menuclick;
          p.onmouseout = hidemenu;
          c.onmouseover = showmenu;
          c.onmouseout = hidemenu;
          break;
      case "hover":
          p.onmouseover = showmenu;
          p.onmouseout = hidemenu;
          c.onmouseover = showmenu;
          c.onmouseout = hidemenu;
          for (i = 0; i <= c["menu_children"].length - 1; i++) {
              if (_blnBrowserIE) {
                  c["menu_children"][i].childNodes[0].style.width = c.style.width
                  c["menu_children"][i].style.width = c.style.width
                  c["menu_children"][i].style.height = '24px'
              }

              c["menu_children"][i].onmouseover = togglehover;
              c["menu_children"][i].onmouseout = togglehover;
          }

          break;
  }

  function togglehover() {
      //this.style.backgroundImage = ''
      //this.style.filter = ''
      if (this.className.indexOf('_on') > -1) {
          this.className = this.className.replace('_on', '_off');
          //this.className = 'background-image:url(/images/menu/bkgDropDownMenu.png)'

      }
      else {
          this.className = this.className.replace('_off', '_on');
          //this.className = 'background-image:url(/images/menu/bkgDropDownMenu_ovr.png)'
      }
      //if (_blnIE6)
      //  IE6PNGHelper(this)

  }

  function IE6PNGHelper(elm) {
      var mypng = supersleight;
      mypng.limitTo(elm.id);
      mypng.run();
  }


}

