if(window.addEventListener)
{
  window.addEventListener("load",mladdevents,false);
}
else
if(window.attachEvent)
{
  window.attachEvent("onload",mladdevents);
}
else
{
  window.onload = mladdevents;
}


function mladdevents()
{
  if(!window.mlrunShim)
  {
    window.mlrunShim = false;
  }
  
  if(window.mlrunShim == true)
  {
    var Iframe = document.createElement("iframe");
    Iframe.setAttribute("src","about:blank");
    Iframe.setAttribute("scrolling","no");
    Iframe.setAttribute("frameBorder","0");
  }
  
  var effects_a = new Array();
  var divs = document.getElementsByTagName('div');
  
  for(var j=0;j<divs.length;j++)
  {
    if(divs[j].className.indexOf('mlmenu') != -1)
    {
      //divs[j].className = divs[j].className.replace('mlmenu','mlmenujs');
      divs[j].getElementsByTagName('ul')[0].className = divs[j].className;  //just for reference
      var lis = divs[j].getElementsByTagName('li');
      for(var i=0;i<lis.length;i++)
      {
        lis[i].onmouseover = mlover;
        lis[i].onmouseout = mloutSetTimeout;
        
        if(window.mlrunShim == true)
        {
          lis[i].appendChild(Iframe.cloneNode(false));
        }
        
        if(lis[i].parentNode.getElementsByTagName('li')[0] == lis[i])
        {
          lis[i].getElementsByTagName('a')[0].className += 'first';
          //if(lis[i].parentNode.className.indexOf('mlmenujs') != -1) {
          if(lis[i].parentNode.className.indexOf('mlmenu') != -1)
          {
            lis[i].className += 'pixelfix';
          }
        }
        
        if(lis[i] == findLast(lis[i].parentNode))
        {
          lis[i].className += 'last';
        }
        
        if(lis[i].getElementsByTagName('ul').length > 0)
        {
          lis[i].className += ' haschild';
          
          if(divs[j].className.indexOf('arrow') != -1)
          {
            if(divs[j].className.indexOf('vertical') != -1 || lis[i].parentNode.parentNode.nodeName != 'DIV')
            {
              lis[i].getElementsByTagName('a')[0].innerHTML += '<span class="vert">&rarr;</span>';
            }
            else
            {
              lis[i].getElementsByTagName('a')[0].innerHTML += '<span class="horiz">&darr;</span>';
            }
          }
          else
          if(divs[j].className.indexOf('plus') != -1)
          {
            lis[i].getElementsByTagName('a')[0].innerHTML += '<span class="plus">+</span>';
          }
        }
        else
        {
          if(divs[j].className.indexOf('arrow') != -1)
          {
            //This accounts for a wierd IE-specific bug in horizontal menus. CSS will set visibility: hidden;. This keeps the menu level(in IE)
            lis[i].getElementsByTagName('a')[0].innerHTML += '<span class="noshow">&darr;</span>';
          }
        }
        
        var uls = lis[i].getElementsByTagName('ul');
        
        for(var k=0;k<uls.length;k++)
        {
          var found = 'no';
          
          for(var z=0;z<effects_a.length;z++)
          {
            if(effects_a[z] == uls[k])
            {
              found = 'yes';
            }
          }
          
          if(found == 'no')
          {
            effects_a[effects_a.length] = uls[k];
            uls[k].style.zIndex = '100';
            mlEffectLoad(uls[k]);
          }
        }
      }
    }
  }
}


function mloutSetTimeout(e)
{
  if(!e)
  {
    var the_e = window.event;
  }
  else
  {
    var the_e = e;
  }
  
  var reltg = (the_e.relatedTarget) ? the_e.relatedTarget : the_e.toElement;
  
  if(reltg)
  {
    var under = ancestor(reltg,this);

    if(under === false && reltg != this)
    {
      window.mlLast = this;
      var parent = this.parentNode;

      //while(parent.parentNode && parent.className.indexOf('mlmenujs') == -1){
      while(parent.parentNode && parent.className.indexOf('mlmenu') == -1)
      {
        parent = parent.parentNode;
      }

      if(parent.className.indexOf('delay') != -1)
      {
        window.mlTimeout = setTimeout(function(){mlout()},1000);
      }
      else
      {
        mlout();
      }
    }
  }
}

/*
// PETER - USED for alternative functions
function xmloutSetTimeout(e)
{
  var a=!e?window.event:e;killBubble(a);
  var b=(a.relatedTarget)?a.relatedTarget:a.toElement;

  if(ancestor(b,this)==false)
  {
    window.mlLast=this;
    window.mlTimeout=setTimeout("hideAllMenus(document)",mlConfig.get(this.getElementsByTagName("ul")[0],"delay",0)*1000)
  }
}
// PETER - USED for alternative functions
function hideAllMenus(a)
{
  window.mlLast=null;

  if(!a||!a.getElementsByTagName)
  {
    return true
  }

  var b=a.getElementsByTagName("ul");
  var c=a.getElementsByTagName("a");

  for(var i=0;i<b.length;i++)
  {
    if(b[i].classname.indexof("submenu")!=-1)
    {
      b[i].style.display="none"
    }
  }

  for(var i=0;i<c.length;i++)
  {
    if(c[i].className.indexOf("hover")!=-1)
    {
      c[i].className=""
    }
  }

  return true
}
*/


function mlout()
{
  if(window.mlLast==null)
    return false;
    
  var links = window.mlLast.getElementsByTagName('a');
  
  for(var i = 0;i<links.length;i++)
  {
    links[i].className = links[i].className.replace('hover','');
  }
  
  var uls = window.mlLast.getElementsByTagName('ul');
  var sib;
  
  for(var i=0;i<uls.length;i++)
  {
    mlEffectOut(uls[i]);
    window.mlLast.className += ' hide';
    window.mlLast.className = window.mlLast.className.replace('hide hide','hide');
    if(window.mlrunShim == true)
    {
      sib = uls[i];              
      while(sib.nextSibling && sib.nodeName != 'IFRAME')
      {
        sib = sib.nextSibling
      }
      sib.style.display = 'none';
    }
  }
  
  window.lastover = null;
  return true;
}


function mlover(e)
{
  if(!e)
  {
    var the_e = window.event;
  }
  else
  {
    var the_e = e;
  }
  
  the_e.cancelBubble = true;
  
  if(the_e.stopPropagation)
  {
    the_e.stopPropagation();
  }

  clearTimeout(window.mlTimeout);
  if(window.mlLast && window.mlLast != this && ancestor(this,window.mlLast) === false)
  {
    mlout();
  }
  else
  {
    window.mlLast = null;
  }
  
  var reltg = (the_e.relatedTarget) ? the_e.relatedTarget : the_e.fromElement;
  var under = ancestor(reltg,this);
  
  if(under == false)
  {
    var hovered = byClass(this.parentNode,'hover','a');
    
    for(var i=0;i<hovered.length;i++)
    {
      if(ancestor(this,hovered[i].parentNode) == false)
      {
        window.mlLast = hovered[i].parentNode;
        mlout();
      }
    }
    
    var ob = this.getElementsByTagName('ul');
    var link = this.getElementsByTagName('a')[0];
    link.className += ' hover';
    
    if(ob[0])
    {
      if(window.lastover != ob[0])
      {
        if(window.mlrunShim == true)
        {
          var sib = ob[0];
          
          while(sib.nextSibling && sib.nodeName != 'IFRAME')
          {
            sib = sib.nextSibling
          }
/*
          ob[0].style.display = 'block';
          sib.style.top = ob[0].offsetTop+'px';
          sib.style.left = ob[0].offsetLeft-2+'px';
          sib.style.width = ob[0].offsetWidth+2+'px';
          sib.style.height = ob[0].offsetHeight-2+'px';
          sib.style.display = 'block';
*/

        }
        
        this.className = this.className.replace(/hide/g,'');
        mlEffectOver(ob[0],this);
        window.lastover = ob[0];
      }
    }
  }
}
/*
function mlover(e)
{
  var a=!e?window.event:e;killBubble(a);

  clearTimeout(window.mlTimeout);

  if(window.mlLast==this)
  {
    return false
  }


  if(ancestor(window.mlLast,this))
  {
    hideAllMenus(findHighestUncommon(window.mlLast,this))
  }


  if(window.mlLastOpened && ancestor(this,window.mlLastOpened)==false && this!=window.mlLastOpened)
  {
    hideAllMenus(findHighestUncommon(window.mlLastOpened,this))
  }

  var b=(a.relatedTarget)?a.relatedTarget:a.fromElement;

  if(ancestor(b,this)==false)
  {
    window.mlLastOpened=this;
    mlEffectOver(this.getElementsByTagName("ul")[0]);
    this.getElementsByTagName("a")[0].className="hover"
  }

  return false
}

function mlLinkOver(e)
{
  var a=!e?window.event:e;

  killBubble(a);

  clearTimeout(window.mlTimeout);

  if(ancestor(this,window.mlLastOpened)==true)
  {
    return true
  }
  else
  {
    hideAllMenus(findHighestUncommon(window.mlLastOpened,this))
  }

  return true
}


function killBubble(a)
{
  a.cancelBubble=true;


  if(a.stopPropagation)
  {
    a.stopPropagation()
  }
}


function findHighestUncommon(a,b)
{
  if(a==null||b==null)
  {
    return null
  }

  if(a.parentNode.parentNode==b)
  {
    return a
  }

  while(a.parentNode!=b.parentNode && a.parentNode.parentNode.nodeName=="LI")
  {
    a=a.parentNode.parentNode
  }

  return a
}


*/

function mlSetOpacity(ob,level)
{
  if(ob)
  {
    var standard = level/10;
    var ie = level*10;
    ob.style.opacity = standard;
    ob.style.filter = "alpha(opacity="+ie+")"
  }
}


function mlIncreaseOpacity(ob)
{
  var current = ob.style.opacity;
  current = current * 10;
  var upone = current + 1;
  mlSetOpacity(ob,upone);
}


function mlIncreaseHeight(ob)
{
  var current = parseInt(ob.style.height);

  if(!isNaN(current))
  {
    var newh = current + 1;
    ob.style.height = newh+'px';
  }
}


function mlIncreaseWidth(ob)
{
  var current = parseInt(ob.style.width);

  if(!isNaN(current))
  {
    var newh = current + 1;
    ob.style.width = newh+'px';
  }
}

function mlShake(ob)
{
  var newp = '5px';
  var old = '';

  if(ob.style.paddingLeft==old)
  {
    ob.style.paddingLeft=newp;
  }
  else
  {
    ob.style.paddingLeft=old;
  }
}


function mlShakeV(ob)
{
  var newp = '5px';
  var old = '';

  if(ob.style.paddingTop==old)
  {
    ob.style.paddingTop=newp;
  }
  else
  {
    ob.style.paddingTop=old;
  }
}

function findPosX(obj)
{
  var curleft = 0;

  if(obj.offsetParent)
    while(1)
    {
      curleft += obj.offsetLeft;
      if(!obj.offsetParent)
        break;
      obj = obj.offsetParent;
    }
  else
  if(obj.x)
    curleft += obj.x;
    
  return curleft;
}

function findPosY(obj)
{
  var curtop = 0;

  if(obj.offsetParent)
    while(1)
    {
      curtop += obj.offsetTop;
      if(!obj.offsetParent)
        break;
      obj = obj.offsetParent;
    }
  else
  if(obj.y)
    curtop += obj.y;

  return curtop;
}

/*
function getX(ob)
{
  var iReturnValue = 0;
  while(ob != null)
  {
    iReturnValue += ob.offsetLeft;
    ob = ob.offsetParent;
  }
  return iReturnValue;
}
function getY2(ob)
{
  var iReturnValue = 0;
  while(ob != null)
  {
    iReturnValue += ob.offsetTop;
    ob = ob.offsetParent;
  }
  return iReturnValue;
}
function getY(ob)
{
  var curleft = 0;
  if (obj.offsetParent)
  {
    do {
      curleft += obj.offsetLeft;
    } while (obj = obj.offsetParent);
  }
  return curleft;
}
function findPos(obj)
{
  var curleft = curtop = 0;
  if (obj.offsetParent)
  {
    do {
      curleft += obj.offsetLeft;
      curtop += obj.offsetTop;
    } while (obj = obj.offsetParent);
  }
  return [curleft, curtop];
}
*/

function mlShake2(ob)
{
  if (ob.style.offsetLeft < 50)
    ob.style.left =  ob.offsetLeft+1+'px';
  else
    ob.style.left =  ob.offsetLeft-1+'px';
}

function moveElement2(elementID, finalx, finaly, interval)
{
  if (!document.getElementById) return false;
  if (!document.getElementById(elementID)) return false;
  
  var elem = document.getElementById(elementID);
  var xpos = parseInt(elem.style.left);
  var ypos = parseInt(elem.style.top);
  
  if (xpos == finalx && ypos == finaly)
  {
    return true;
  }
  if (xpos < finalx) xpos++;
  if (xpos > finalx) xpos--;
  if (ypos < finaly) ypos++;
  if (ypos > finaly) ypos--;
  
  elem.style.left = xpos + "px";
  elem.style.top = ypos + "px";
}
function moveElement(ob, finalx, finaly, interval)
{
  if (!ob.style.offsetLeft)
    ob.style.offsetLeft = findPosX(ob);
  if (!ob.style.offsetTop)
    ob.style.offsetTop = findPosY(ob);

  var xpos = ob.style.offsetLeft;
  var ypos = ob.style.offsetTop;

  if (xpos == finalx && ypos == finaly)
  {
    return true;
  }
  if (xpos < finalx) xpos++;
  if (xpos > finalx) xpos--;
  if (ypos < finaly) ypos++;
  if (ypos > finaly) ypos--;

  ob.style.left = xpos + "px";
  ob.style.top = ypos + "px";
}


function mlIncreaseLeft(ob)
{
/*
  var current = parseInt(ob.style.offsetLeft);

  if(!isNaN(current))
  {
    var newh = current + 1;
    ob.style.left = newh+'px';
  }
*/
//  ob.style.left =  ob.offsetLeft+1+'px';
  ob.style.left = findPosX(ob) + 1 + 'px';
}


function mlEffectOver(ob,parent)
{
  switch(ob.className)
  {
    case 'fade':
      ob.style.display = 'block';
      for(var i = 1;i<=10;i++)
      {
        window.fadeTime = setTimeout(function(){mlIncreaseOpacity(ob)},i*50);
      }
      setTimeout(function(){ob.style.filter = ''},500);
      break;
      
    case 'shake':
      ob.style.display = 'block';
      var shake = setInterval(function(){mlShake(ob)},50);
      setTimeout(function(){clearInterval(shake)},510);
      break;

    case 'shakerx':
      ob.style.display = 'block';
      var shaker = setInterval(function(){mlShake2(ob)},50);
      setTimeout(function(){clearInterval(shaker)},500);
      break;

    case 'shakr':
      ob.style.display = 'block';
      
      //ob.style.position = 'relative';
/*
      //for(var i = 1;i<=10;i++)
      {
        ob.style.left = '-20px';
        ob.style.left = '0px';
        ob.style.left = '20px';
        ob.style.left = '0px';
      }
*/
      
      //ob.style.position = "relative";
      //ob.style.position = "static";
//      ob.style.position = "absolute";
      //ob.style.position = "fixed";
//      ob.style.left = '100px';

      if (ob.style.position != 'fixed' && ob.style.position != 'absolute')
        ob.style.position = "absolute";
        
      if (!ob.style.left)
        ob.style.left = findPosX(ob);

      //var shake = setInterval(function(){ if (findPosX(ob) > 600) return; ob.style.left = findPosX(ob) + 10 + 'px'    },10);
      //setTimeout(function(){clearInterval(shake)},510);
      var shake = setInterval(function(){ if (ob.style.left > 600) return; ob.style.left = parseInt(ob.style.left) + 10 + 'px'    },10);
      setTimeout(function(){clearInterval(shake)},510);
      
      setTimeout(function(){
        var shake = setInterval(function(){ if (ob.style.left < 100) return; ob.style.left = parseInt(ob.style.left) - 10 + 'px'    },10);
        setTimeout(function(){clearInterval(shake)},510);
      },1000);

      //var shakr = setInterval(function(){ if (findPosX(ob) < 100) return; ob.style.left = findPosX(ob) - 10 + 'px'    },10);
      //var shakr = setInterval(function(){ ob.style.left = findPosX(ob) - 10 + 'px'    },10);
      //setTimeout(function(){clearInterval(shakr)},510);

      //ob.style.left = '';
      //ob.style.display = 'none';

/*
      ob.style.left = '500px';
      setTimeout(function(){},1000);
      ob.style.left = '200px';
      setTimeout(function(){},1000);
      ob.style.left = '100px';
*/
/*
      for(var i = 1;i<=10;i++)
      {
        //window.shakr = setTimeout(function(){  moveElement(ob, ob.offsetLeft + 500, ob.offsetHeight, 10)   },i*50);
        window.shakr = setTimeout(function(){  moveElement(ob, ob.offsetLeft + 500, ob.offsetHeight, 10)   }, 10);
      }
      setTimeout(function(){clearInterval(shakr)},510);
*/
/*
      for(var i = 1;i<=10;i++)
      {
        window.shakr = setTimeout(function() { moveElement(ob, findPosX(ob) + 500, findPosY(ob), 50) }, 10);
      }
      setTimeout(function(){clearInterval(shakr)},510);
*/
/*
      var repeat = moveElement(ob, ob.offsetLeft + 500, ob.offsetHeight, 50);
      movement = setTimeout(repeat, 500);
      clearTimeout(movement);
*/
/*
      var repeat = moveElement(ob, ob.offsetLeft + 500, ob.offsetHeight + 500, 10);
      movement = setTimeout(repeat, 500);
      clearTimeout(movement);
*/
//      ob.style.display = 'none';
      break;

    case 'shakev':
      ob.style.display = 'block';
      var shakev = setInterval(function(){mlShakeV(ob)},50);
      setTimeout(function(){clearInterval(shakev)},510);
      break;

    case 'blindv':
      ob.style.display = 'block';
      if(ob.offsetHeight)
      {
        var height = ob.offsetHeight
        ob.style.height = '0px';
        ob.style.overflow = 'hidden';
        for(var i=0;i<height;i++)
        {
          setTimeout(function(){mlIncreaseHeight(ob)},i*3);
        }
        setTimeout(function(){ob.style.overflow='';ob.style.height='auto'},(height-1)*3)//-1 for IE
      }
      break;

    case 'blindh':
      ob.style.display = 'block';
      if(ob.offsetWidth)
      {
        var width = ob.offsetWidth;
        ob.style.width = '0px';
        ob.style.overflow = 'hidden';
        for(var i=0;i<width;i++)
        {
          setTimeout(function(){mlIncreaseWidth(ob)},i*3);
        }
        setTimeout(function(){ob.style.overflow='visible';},width*3)
      }
      break;

    default:
      ob.style.display = 'block';
      break;
  }
}


function mlEffectOut(ob)
{
  switch(ob.className)
  {
    case 'fade':
      clearTimeout(window.fadeTime);
      mlSetOpacity(ob,0);
      ob.style.display = 'none';
      break;

    case 'shake':
      ob.style.paddingLeft = '';
      ob.style.display = 'none';
      break;

    case 'shakev':
      ob.style.paddingTop = '';
      ob.style.display = 'none';
      break;

    default:
      ob.style.display = 'none';
      break;
  }
}


function mlEffectLoad(ob)
{
  var parent = ob.parentNode;
  
  while(parent.parentNode && parent.className.indexOf('mlmenu') == -1)
  {
    parent = parent.parentNode;
  }
  
  if(parent.className.indexOf('fade') != -1)
  {
    ob.style.display = 'none';
    ob.className = 'fade';
    mlSetOpacity(ob,0);
  }
  else
  if(parent.className.indexOf('shake') != -1)
  {
    ob.className = 'shake';
  }
  else
  if(parent.className.indexOf('shakr') != -1)
  {
    ob.className = 'shakr';
  }
  else
  if(parent.className.indexOf('shakev') != -1)
  {
    ob.className = 'shakev';
  }
  else
  if(parent.className.indexOf('blindv') != -1)
  {
    ob.className = 'blindv';
  }
  else
  if(parent.className.indexOf('blindh') != -1)
  {
    ob.className = 'blindh';
  }
  else
  if(parent.className.indexOf('box') != -1)
  {
    ob.className = 'box';
  }
  
  ob.style.display = 'none';
}


function ancestor(child, parent)
{
  try
  {
    if(child==null)
      return false;  //Saves checking elsewhere
      
    for(; child.parentNode; child = child.parentNode)
    {
      if(child.parentNode === parent)
        return true;
    }
    
    return false;
  }
  catch(error)
  {
    //Mozilla bug, it must be a text control which can not be in the menu so we will foolishly assume false
    return false;
  }
}
/*
function ancestor(child, parent)
{
  if(child==null||parent==null)
  {
    return false
  }

  try
  {
    for(;child.parentNode;child = child.parentNode)
    {
      if(child.parentNode === parent)
      {
        return true
      }
    }

    return false
  }
  catch(error)
  {
    //Mozilla bug, it must be a text control which can not be in the menu so we will foolishly assume false
    return false
  }
}
*/



function byClass(parent,c,tag)
{
  var all = parent.getElementsByTagName(tag);
  var returna = new Array();
  
  for(var i=0;i<all.length;i++)
  {
    if(all[i].className.indexOf(c) != -1)
    {
      returna[returna.length] = all[i]
    }
  }
  
  return returna;
}


function findLast(ob)
{
  if(ob.lastChild.nodeType == 1)
  {
    return ob.lastChild
  }

  return ob.lastChild.previousSibling;
}