var qm_si, qm_li, qm_lo, qm_tt, qm_hide_timer;

function qm_create( menu_id, is_vertical_flag, show_timer, hide_timer, on_click_flag, rl, sh, fl, nf, l ) {
  var w = "onmouseover";
  if( on_click_flag ) {
    w = "onclick";
    hide_timer = 0;
    show_timer = 0;
  }

  if( !l ) {
    l = 1;
    qm_hide_timer  = hide_timer;
    menu_id        = document.getElementById("qm" + menu_id);
    menu_id[w]     = function(e) {
                       qm_kille(e)
                     };

    document[w]        = qm_bo;
    menu_id.style.zoom = 1;

    if( sh ) {
      update_class("qmsh", menu_id, 1);
    }

    if( !is_vertical_flag ) {
      menu_id.ch = 1;
    }
  }
  else  if(sh)menu_id.ch=1;

  if( sh ) menu_id.sh = 1;
  if( fl ) menu_id.fl = 1;
  if( rl ) menu_id.rl = 1;

  menu_id.style.zIndex = l + "" + 1;

  var lsp;
  var sp = menu_id.childNodes;

  for( var i=0; i < sp.length; i++ ) {
    var b = sp[i];
    if( b.tagName == "A" ) {
      lsp = b;
      b[w] = qm_oo;
      b.qmts = show_timer;

      if( l == 1 && is_vertical_flag ) {
        b.style.styleFloat = "none";
        b.style.cssFloat   = "none";
      }
    }

    if( b.tagName == "DIV" ) {
      if( window.showHelp && !window.XMLHttpRequest ) sp[i].insertAdjacentHTML("afterBegin","<span class='qmclear'>&nbsp;</span>");
      update_class("qmparent",lsp,1);
      lsp.cdiv = b;
      b.idiv = lsp;
      if( ( navigator.userAgent.indexOf("Netscape") + 1 ) && parseFloat(navigator.vendorSub) < 8 && !b.style.width ) b.style.width = b.offsetWidth + "px";
      new qm_create( b, null, show_timer, hide_timer, on_click_flag, rl, sh, fl, nf, l+1 );
    }
  }
}

function qm_bo(e) {
  clearTimeout(qm_tt);
  qm_tt = null;
  if( qm_li && !qm_tt ) {
    qm_tt = setTimeout("x0()", qm_hide_timer);
  }
}

function x0() {
  var a;

  if( ( a = qm_li ) ) {
    do{ qm_uo(a); }
    while( ( a = a["parentNode"] ) && !qm_a(a) )
  }
  qm_li=null;
}

function qm_a(a) {
  if( a["className"].indexOf("qmmc") + 1 ) {
    return 1;
  }
}

function qm_uo(a,go) {
  if( !go && a.qmtree ) {
    return;
  }

  if( window.qmad && qmad.bhide ) {
    eval(qmad.bhide);
  }
  a.style.visibility = "";
  update_class("qmactive", a.idiv);
}

function qm_oo(e,o,nt) {
  if( !o ) {
    o = this;
  }

  if( window.qmad && qmad.bhover && !nt ) {
    eval(qmad.bhover);
  }

  if( window.qmwait ) {
    qm_kille(e);
    return;
  }

  clearTimeout(qm_tt);
  qm_tt = null;

  if( !nt && o.qmts ) {
    qm_si = o;
    qm_tt = setTimeout("qm_oo(new Object(),qm_si,1)", o.qmts);
    return;
  }

  var a = o;

  if( a["parentNode"].isrun ) {
    qm_kille(e);
    return;
  }

  var go = true;

  while( ( a = a["parentNode"]) && !qm_a(a) ) {
    if( a == qm_li ) {
      go = false;
    }
  }

  if( qm_li && go ) {
    a=o;

    if( ( !a.cdiv ) || ( a.cdiv && a.cdiv != qm_li ) ) {
      qm_uo(qm_li);
    }

    a=qm_li;

    while( ( a = a["parentNode"] ) && !qm_a(a) ) {
      if( a != o["parentNode"] ) {
        qm_uo(a);
      }
      else {
        break;
      }
    }
  }

  var b = o;
  var c = o.cdiv;

  if( b.cdiv ) {
    var aw = b.offsetWidth;
    var ah = b.offsetHeight;
    var ax = b.offsetLeft;
    var ay = b.offsetTop;

    if( c["parentNode"].ch ) {
      aw = 0;
      if(c.fl) {
        ax=0;
      }
    }
    else {
      if( c.rl ) {
        ax = ax - c.offsetWidth;
        aw = 0;
      }
      ah=0;
    }

    /* Opera */
    if( ( navigator.userAgent.indexOf("Opera") + 1 ) ) {
      ax -= b["parentNode"].clientLeft;
      ay -= b["parentNode"].clientTop;
    }

    /* Safari w/ AJAX */
    if( navigator.userAgent.indexOf("afari") + 1 && window.XMLHttpRequest ) {
      ax -= qm_get_computed_style( b["parentNode"], "border-left-width", "borderLeftWidth" );
      ay -= qm_get_computed_style( b["parentNode"], "border-top-width", "borderTopWidth");
    }

    if( !c.ismove ) {
      c.style.left = (ax + aw) + "px";
      c.style.top  = (ay + ah) + "px";
    }

    update_class("qmactive", o, 1);

    if( window.qmad && qmad.bvis ) {
      eval(qmad.bvis);
    }

    c.style.visibility = "inherit";
    qm_li = c;
  }
  else {
    if( !qm_a( b["parentNode"] ) ) {
      qm_li = b["parentNode"];
    }
    else {
      qm_li = null;
    }
    qm_kille(e);
  }
}

function qm_get_computed_style(obj,sname,jname) {
  var v;
  if( document.defaultView && document.defaultView.getComputedStyle ) {
    v = document.defaultView.getComputedStyle(obj,null).getPropertyValue(sname);
  }
  else {
    if( obj.currentStyle ) {
      v = obj.currentStyle[jname];
    }
  }

  if( v && !isNaN(v = parseInt(v))) {
    return v;
  }
  else {
    return 0;
  }
}

function update_class(name,entity,add) {
  var a = entity["className"];

  if(add) {
    /* add name to class list */
    if( a.indexOf(name)==-1 ) {
      entity["className"] += ( a ? ' ' : '' ) + name;
    }
  }
  else {
    /* replace class list with name */
    entity["className"] = a.replace( " " + name, "" );
    entity["className"] = entity["className"].replace(name, "");
  }
}

function qm_kille(e) {
  if( !e ) {
    e = event;
  }

  e.cancelBubble = true;

  if( e.stopPropagation && !( ( navigator.userAgent.indexOf("afari") + 1 ) && e.type == "click" ) ) {
    e.stopPropagation();
  }
}


