// +------------------------------------------------------------+
// | Menu G3.1(loader/non-frame)     Last Modified 03-Feb-2003  |
// | Web Site:                       http://www.yxScripts.com   |
// | EMail:                          m_yangxin@hotmail.com      |
// +------------------------------------------------------------+
// |   Copyright 2002, 2003  Xin Yang   All Rights Reserved.    |
// +------------------------------------------------------------+

// default settings, can be overwritten by a path script
var _webPath="";                                              // web base path for all relative links in the menus
var _scriptPath="http://www.yxScripts.com/menuG3.1/script/";  // full web path of the script directory
var _imagePath="http://www.yxScripts.com/menuG3.1/img/";      // full web path of the img directory
var _contentScript="";                                        // full web path of the menu content script
var _styleScript="";                                          // full web path of the menu style script
var _instanceScript="";                                       // full web path of the menu instance script
var _nonMenuPage="";                                          // full web path of the page for browsers not supported by Menu G3.1
var _menuTimer=500;                                           // timer for hovering before opening a sub-menu
var _zBase=2;                                                 // base z-index for a menu
// ------

var yx_isOpera=(navigator.userAgent.indexOf("Opera")!=-1);
var yx_isKon=(navigator.userAgent.indexOf("Konqueror")!=-1);
var yx_isMac=(navigator.userAgent.indexOf("Mac")!=-1);

var yx_isIE=(typeof(document.all)!="undefined" && !yx_isOpera && !yx_isKon);
var yx_isIE4=(yx_isIE && navigator.appVersion.indexOf("MSIE 4")!=-1);
var yx_isIE5=(yx_isIE && !yx_isIE4);
var yx_isN4=(typeof(document.layers)!="undefined");
var yx_isN6=(navigator.userAgent.indexOf("Gecko")!=-1);
var yx_isK3=(yx_isKon && navigator.appVersion.indexOf('Konqueror/3')!=-1);
var yx_isO7=(navigator.userAgent.indexOf("Opera 7")!=-1);

var yx_menuSafe=(yx_isN6 || yx_isN4 || yx_isIE5 || yx_isIE4 && !yx_isMac || yx_isK3 || yx_isO7);

if (typeof(webPath)=="undefined") { webPath=_webPath; }
if (typeof(scriptPath)=="undefined") { scriptPath=_scriptPath; }
if (typeof(imagePath)=="undefined") { imagePath=_imagePath; }
if (typeof(contentScript)=="undefined") { contentScript=_contentScript; }
if (typeof(styleScript)=="undefined") { styleScript=_styleScript; }
if (typeof(instanceScript)=="undefined") { instanceScript=_instanceScript; }
if (typeof(nonMenuPage)=="undefined") { nonMenuPage=_nonMenuPage; }
if (typeof(menuTimer)=="undefined") { menuTimer=_menuTimer; }
if (typeof(zBase)=="undefined") { zBase=_zBase; }

function buildMenu() { return; }

var yx_Top="T", yx_M="M", yx_iM="iM", yx_L="L", yx_iL="iL", yx_C="C", yx_iC="iC", yx_I="I", yx_S="S";
var yx_goodM=true, yx_goodI=true, yx_doneM=false, yx_winEvent="";
var yx_cCount=0, yx_cBack=new Array(), yxIdx=-1, yxIns=new Array();;
var yx_sX=0, yx_sY=0, yx_wW=0, yx_wH=0, yx_iTimer=0, yx_offTimer=0, yx_onItem=false;
var yx_actionOverIt="mouse-over", yx_actionClickIt="mouse-click", yx_menuSticky="sticky", yx_tagOn="on", yx_menuBar="bar";
var yx_onePixel=imagePath+"onePixel.gif", yx_pImage=new Image(1,1); yx_pImage.src=yx_onePixel;
var yx_sPixel='<img src="'+yx_pImage.src+'" width="1" height="1" border="0" hspace="0" vspace="0">';
var yx_pathRE=/^\w+:|^\//;

function yx_setIt() { yx_cutIt(); yx_offTimer=setTimeout("yx_clickIt()",menuTimer*2); }
function yx_cutIt() { if (yx_offTimer>0) clearTimeout(yx_offTimer); }
function yx_getPath(path) { return yx_pathRE.test(path)?path:(webPath+path); }
function yx_showMsg(msg) { window.status=msg; }
function yx_callBack(obj,func,t) {
  var x=yx_cCount++; yx_cBack[x]=obj;
  var tm=setTimeout(("yx_cBack["+x+"]."+func),t);
  if (yx_cCount>200) { yx_cCount=0; }
  return tm;
}

function yx_fgOBJ(obj,name,mode) {
  for (var i=0; i<obj.length; i++) {
    if (obj[i].name==name) { return obj[i]; }
  }
  return mode?obj[0]:null;
}
function yx_findOBJ(obj,name) { return yx_fgOBJ(obj,name,false); }
function yx_getOBJ(obj,name) { return yx_fgOBJ(obj,name,true); }

function yx_sPadOBJ(sp_name,s_width,s_height,s_color,b_size,b_style,b_color,p_dx,p_dy,p_mode,p_dir) {
  this.name=sp_name;
  this.sWidth=s_width; this.sHeight=s_height; this.sColor=s_color;
  this.bSize=b_size; this.bStyle=b_style; this.bColor=b_color;
  this.dx=p_dx; this.dy=p_dy;
  this.mode=(typeof(p_mode)!="undefined")?p_mode:"";
  this.dir=(typeof(p_dir)!="undefined")?p_dir:"";

  this.bColor1=""; this.bColor2=""
  if (b_size>0 && b_color!="") {
    if (b_style=="outset") {
      this.bColor1=yx_getColor(b_color,1); this.bColor2=yx_getColor(b_color,-1);
    }
    else if (b_style=="inset") {
      this.bColor1=yx_getColor(b_color,-1); this.bColor2=yx_getColor(b_color,1);
    }
    else {
      this.bColor1=b_color; this.bColor2=b_color;
    }
  }
}; var yx_sPads=new Array(); yx_sPads[0]=new yx_sPadOBJ("",3,3,"#c0c0c0",2,"outset","#c0c0c0",0,0,"pad","");

function yx_sItemOBJ(si_name,i_width,i_height,p_width,p_height,b_size,b_style_N,b_style_H,b_color_N,b_color_H,i_color_N,i_color_H,i_method,si_dis) {
  this.name=si_name;
  this.iWidth=i_width; this.iHeight=(typeof(i_height)!="undefined")?i_height:0;
  this.pWidth=p_width; this.pHeight=p_height;
  this.bSize=b_size; this.bStyleN=b_style_N; this.bStyleH=b_style_H; this.bColorN=b_color_N; this.bColorH=b_color_H;
  this.iColorN=i_color_N; this.iColorH=i_color_H;
  this.iMethod=(i_method=="")?yx_actionOverIt:i_method;
  this.dis=(typeof(si_dis)!="undefined")?si_dis:0;

  this.bColorN1=""; this.bColorN2=""; this.bColorH1=""; this.bColorH2="";
  if (b_size>0) {
    if (b_style_N=="outset") {
      this.bColorN1=yx_getColor(b_color_N,1); this.bColorN2=yx_getColor(b_color_N,-1);
    }
    else if (b_style_N=="inset") {
      this.bColorN1=yx_getColor(b_color_N,-1); this.bColorN2=yx_getColor(b_color_N,1);
    }
    else {
      this.bColorN1=b_color_N; this.bColorN2=b_color_N;
    }

    if (b_style_H=="outset") {
      this.bColorH1=yx_getColor(b_color_H,1); this.bColorH2=yx_getColor(b_color_H,-1);
    }
    else if (b_style_H=="inset") {
      this.bColorH1=yx_getColor(b_color_H,-1); this.bColorH2=yx_getColor(b_color_H,1);
    }
    else {
      this.bColorH1=b_color_H; this.bColorH2=b_color_H;
    }
  }
}; var yx_sItems=new Array(); yx_sItems[0]=new yx_sItemOBJ("",120,0,6,1,0,"","","","","#c0c0c0","#000080","",0);

function yx_sFontOBJ(sf_name,f_family,f_size,f_weight,f_style,f_color_N,f_color_H,f_align) {
  this.name=sf_name;
  this.fFamily=f_family; this.fSize=f_size; this.fWeight=f_weight; this.fStyle=f_style;
  this.fColorN=f_color_N; this.fColorH=f_color_H;
  this.fAlign=f_align;
}; var yx_sFonts=new Array(); yx_sFonts[0]=new yx_sFontOBJ("","Arial","14","normal","normal","#000000","#ffffff","left");

function yx_sTagOBJ(st_name,t_option,t_path,t_N,t_H,t_width,t_height,t_align) {
  this.name=st_name;
  this.tOption=t_option;
  if (this.tOption==yx_tagOn) {
    this.tPath=yx_getPath(t_path); this.tN=t_N; this.tH=t_H;
    this.tWidth=t_width; this.tHeight=t_height;
    this.tAlign=t_align;

    this.t0=new Image(t_width,t_height); this.t0.src=this.tPath+t_N;
    this.t1=new Image(t_width,t_height); this.t1.src=this.tPath+t_H;
  }
}; var yx_sTags=new Array(); yx_sTags[0]=new yx_sTagOBJ("","on",imagePath,"tagRN.gif","tagRH.gif",8,11,"right");

function yx_sSeparatorOBJ(ss_name,s_style,s_color,s_size) {
  this.name=ss_name;
  this.sStyle=s_style;
  this.sColor=s_color;
  if (s_style=="outset") {
    this.color1=yx_getColor(s_color,1); this.color2=yx_getColor(s_color,-1); this.sSize=2;
  }
  else if (s_style=="inset") {
    this.color1=yx_getColor(s_color,-1); this.color2=yx_getColor(s_color,1); this.sSize=2;
  }
  else {
    this.color1=s_color; this.color2=s_color; this.sSize=(s_size==1)?1:2;
  }
}; var yx_sSeparators=new Array(); yx_sSeparators[0]=new yx_sSeparatorOBJ("","inset","#c0c0c0",2);

function yx_sMenuOBJ(sm_name,sp_name,si_name,sf_name,st_name,ss_name) {
  this.name=sm_name;
  this.sPad=(yx_sMenus.length>0 && sp_name=="")?yx_sMenus[0].sPad:yx_getPad(sp_name);
  this.sItem=(yx_sMenus.length>0 && si_name=="")?yx_sMenus[0].sItem:yx_getItem(si_name);
  this.sFont=(yx_sMenus.length>0 && sf_name=="")?yx_sMenus[0].sFont:yx_getFont(sf_name);
  this.sTag=(yx_sMenus.length>0 && st_name=="")?yx_sMenus[0].sTag:yx_getTag(st_name);
  this.sSeparator=(yx_sMenus.length>0 && ss_name=="")?yx_sMenus[0].sSeparator:yx_getSeparator(ss_name);
}; var yx_sMenus=new Array(); yx_sMenus[0]=new yx_sMenuOBJ("","","","","","");

function yx_memOBJ(menu,style) { this.menu=menu; this.style=style; }

function yx_sGroupOBJ(sg_name) {
  this.name=sg_name;
  this.member=new Array();
}; var yx_sGroups=new Array();

function addStylePad(sp_name,s_width,s_height,s_color,b_size,b_style,b_color,p_dx,p_dy,p_mode,p_dir) { yx_sPads[yx_sPads.length]=new yx_sPadOBJ(sp_name,s_width,s_height,s_color,b_size,b_style,b_color,p_dx,p_dy,p_mode,p_dir); }
function addStyleItem(si_name,i_width,p_width,p_height,b_size,b_style_N,b_style_H,b_color_N,b_color_H,i_color_N,i_color_H,i_method,si_dis,i_height) { addStyleItem31(si_name,i_width,i_height,p_width,p_height,b_size,b_style_N,b_style_H,b_color_N,b_color_H,i_color_N,i_color_H,i_method,si_dis); }
function addStyleItem31(si_name,i_width,i_height,p_width,p_height,b_size,b_style_N,b_style_H,b_color_N,b_color_H,i_color_N,i_color_H,i_method,si_dis) { yx_sItems[yx_sItems.length]=new yx_sItemOBJ(si_name,i_width,i_height,p_width,p_height,b_size,b_style_N,b_style_H,b_color_N,b_color_H,i_color_N,i_color_H,i_method,si_dis); }
function addStyleFont(sf_name,f_family,f_size,f_weight,f_style,f_color_N,f_color_H,f_align) { yx_sFonts[yx_sFonts.length]=new yx_sFontOBJ(sf_name,f_family,f_size,f_weight,f_style,f_color_N,f_color_H,f_align); }
function addStyleTag(st_name,t_option,t_path,t_N,t_H,t_width,t_height,t_align) { yx_sTags[yx_sTags.length]=new yx_sTagOBJ(st_name,t_option,t_path,t_N,t_H,t_width,t_height,t_align); }
function addStyleSeparator(ss_name,s_style,s_color,s_size) { yx_sSeparators[yx_sSeparators.length]=new yx_sSeparatorOBJ(ss_name,s_style,s_color,s_size); }
function addStyleMenu(sm_name,sp_name,si_name,sf_name,st_name,ss_name) { yx_sMenus[yx_sMenus.length]=new yx_sMenuOBJ(sm_name,sp_name,si_name,sf_name,st_name,ss_name); }
function addStyleGroup(sg_name,sm_name) {
  var xGroup=yx_findGroup(sg_name);

  if (xGroup==null) {
    var x=yx_sGroups.length;
    yx_sGroups[x]=new yx_sGroupOBJ(sg_name);
    xGroup=yx_sGroups[x];
  }

  var xLen=xGroup.member.length;
  for (var i=2; i<addStyleGroup.arguments.length; i++) {
    xGroup.member[xLen+i-2]=new yx_memOBJ(addStyleGroup.arguments[i],sm_name);
  }
}
function setDefaultStyle(sp_name,si_name,sf_name,st_name,ss_name) {
  if (sp_name!="") { yx_sMenus[0].sPad=yx_getPad(sp_name); }
  if (si_name!="") { yx_sMenus[0].sItem=yx_getItem(si_name); }
  if (sf_name!="") { yx_sMenus[0].sFont=yx_getFont(sf_name); }
  if (st_name!="") { yx_sMenus[0].sTag=yx_getTag(st_name); }
  if (ss_name!="") { yx_sMenus[0].sSeparator=yx_getSeparator(ss_name); }
}

function yx_getPad(sp_name) { return yx_getOBJ(yx_sPads,sp_name); }
function yx_getItem(si_name) { return yx_getOBJ(yx_sItems,si_name); }
function yx_getFont(sf_name) { return yx_getOBJ(yx_sFonts,sf_name); }
function yx_getTag(st_name) { return yx_getOBJ(yx_sTags,st_name); }
function yx_getSeparator(ss_name) { return yx_getOBJ(yx_sSeparators,ss_name); }
function yx_getMenu(sm_name) { return yx_getOBJ(yx_sMenus,sm_name); }
function yx_findGroup(sg_name) { return yx_findOBJ(yx_sGroups,sg_name); }
function yx_findContent(c_name) { return yx_findOBJ(yxContent,c_name); }
function yx_findImage(i_name) { return yx_findOBJ(yxImages,i_name); }
function yx_findItemEvent(e_name) { return yx_findOBJ(yxICodes,e_name); }
function yx_findMenuEvent(e_name) { return yx_findOBJ(yxMCodes,e_name); }
function yx_findImg(i_group) { return yx_findOBJ(yxImg,i_group); }

function yx_mlOBJ(i_type,i_dis,i_msg,i_link,i_group) {
  this.type=i_type;
  this.dis=i_dis; this.msg=i_msg; this.link=i_link;
  this.group=i_group;
}

function yx_mcOBJ(i_type,i_dis,i_msg,i_code,i_group) {
  this.type=i_type;
  this.dis=i_dis; this.msg=i_msg; this.code=i_code;
  this.group=i_group;
}

function yx_miOBJ(i_type,i_dis,i_group) { this.type=i_type; this.dis=i_dis; this.group=i_group; }

function yx_msOBJ(i_type) { this.type=i_type; }

function yx_mmOBJ(i_type,i_dis,i_msg,i_link,sm_name,i_group) {
  var xMenu=yx_findMenu(sm_name);

  this.type=i_type;
  this.dis=i_dis; this.msg=i_msg; this.link=i_link;
  this.group=i_group;
  this.name=sm_name;
  this.items=(xMenu==null)?new Array():xMenu.menu.items;
  this.addM=yx_addM; this.addL=yx_addL; this.addC=yx_addC; this.addI=yx_addI; this.addS=yx_addS;
}

function yx_mOBJ(i_type,m_name) {
  this.type=i_type; this.dis="";
  this.name=m_name;
  this.items=new Array();
  this.addM=yx_addM; this.addL=yx_addL; this.addC=yx_addC; this.addI=yx_addI; this.addS=yx_addS;
}; var yxMenu=new Array();

function yx_mnOBJ(m_name,m_obj){
  this.name=m_name; this.menu=m_obj;
}; var yxName=new Array(), yxNx=null, yxContent=new Array();

function yx_addM(m_type,i_dis,i_msg,i_link,sm_name,i_group) {
  var items=this.items,x=items.length;
  items[x]=new yx_mmOBJ(m_type,i_dis,i_msg,i_link,sm_name,i_group);

  if (yx_findMenu(sm_name)==null) {
    yxName[yxName.length]=new yx_mnOBJ(sm_name,items[x]);
  }
}
function yx_addL(l_type,i_dis,i_msg,i_link,i_group) { this.items[this.items.length]=new yx_mlOBJ(l_type,i_dis,i_msg,i_link,i_group); }
function yx_addC(c_type,i_dis,i_msg,i_code,i_group) { this.items[this.items.length]=new yx_mcOBJ(c_type,i_dis,i_msg,i_code,i_group); }
function yx_addI(i_type,i_dis,i_group) { this.items[this.items.length]=new yx_miOBJ(i_type,i_dis,i_group); }
function yx_addS(s_type) { this.items[this.items.length]=new yx_msOBJ(s_type); }

function yx_findMenu(m_name) { return (yxNx!=null&&yxNx.name==m_name)?yxNx:yx_findOBJ(yxName,m_name); }

function addMenu(c_name,m_name) {
  if (yx_goodM) {
    yx_showMsg("Parsing ["+m_name+"]");

    var x=yxMenu.length;
    yxMenu[x]=new yx_mOBJ(yx_Top,m_name);

    yxNx=new yx_mnOBJ(m_name,yxMenu[x]);
    yxName[yxName.length]=yxNx;

    yxContent[yxContent.length]=new yx_mnOBJ(c_name,yxMenu[x]);
  }
}

function _yx_addSubMenu_(m_type,m_name,i_dis,i_msg,i_link,sm_name,i_group) {
  if (yx_goodM) {
    yxNx=yx_findMenu(m_name);

    if (yxNx!=null) {
      yxNx.menu.addM(m_type,i_dis,i_msg,i_link,sm_name,i_group);
    }
    else {
      yx_goodM=false;
      yx_showMsg("Missing declaration of menu ["+m_name+"]");
    }
  }
}
function addSubMenu(m_name,i_dis,i_msg,i_link,sm_name,i_group) { _yx_addSubMenu_(yx_M,m_name,i_dis,i_msg,i_link,sm_name,i_group); }
function addSubMenuX(m_name,i_dis,i_msg,i_link,sm_name,i_group) { _yx_addSubMenu_(yx_iM,m_name,i_dis,i_msg,i_link,sm_name,i_group); }

function _yx_addLink_(l_type,m_name,i_dis,i_msg,i_link,i_group) {
  if (yx_goodM) {
    yxNx=yx_findMenu(m_name);

    if (yxNx!=null) {
      yxNx.menu.addL(l_type,i_dis,i_msg,i_link,i_group);
    }
    else {
      yx_goodM=false;
      yx_showMsg("Missing declaration of menu ["+m_name+"]");
    }
  }
}
function addLink(m_name,i_dis,i_msg,i_link,i_group) { _yx_addLink_(yx_L,m_name,i_dis,i_msg,i_link,i_group); }
function addLinkX(m_name,i_dis,i_msg,i_link,i_group) { _yx_addLink_(yx_iL,m_name,i_dis,i_msg,i_link,i_group); }

function _yx_addCommand_(c_type,m_name,i_dis,i_msg,i_code,i_group) {
  if (yx_goodM) {
    yxNx=yx_findMenu(m_name);

    if (yxNx!=null) {
      yxNx.menu.addC(c_type,i_dis,i_msg,i_code,i_group);
    }
    else {
      yx_goodM=false;
      yx_showMsg("Missing declaration of menu ["+m_name+"]");
    }
  }
}
function addCommand(m_name,i_dis,i_msg,i_code,i_group) { _yx_addCommand_(yx_C,m_name,i_dis,i_msg,i_code,i_group); }
function addCommandX(m_name,i_dis,i_msg,i_code,i_group) { _yx_addCommand_(yx_iC,m_name,i_dis,i_msg,i_code,i_group); }

function addInfo(m_name,i_dis,i_group) {
  if (yx_goodM) {
    yxNx=yx_findMenu(m_name);

    if (yxNx!=null) {
      yxNx.menu.addI(yx_I,i_dis,i_group);
    }
    else {
      yx_goodM=false;
      yx_showMsg("Missing declaration of menu ["+m_name+"]");
    }
  }
}

function addSeparator(m_name) {
  if (yx_goodM) {
    yxNx=yx_findMenu(m_name);

    if (yxNx!=null) {
      yxNx.menu.addS(yx_S);
    }
    else {
      yx_goodM=false;
      yx_showMsg("Missing declaration of menu ["+m_name+"]");
    }
  }
}

function endMenu() {
  yx_doneM=true;
  if (yx_goodM) { yx_showMsg("Menu parsed"); }
}

function yx_iOBJ(i_name,i_path,i_initial,i_swap,i_width,i_height) {
  this.name=i_name;
  this.path=yx_getPath(i_path);
  this.initial=i_initial; this.swap=i_swap;
  this.width=i_width; this.height=i_height;
}; var yxImages=new Array();

function addImage(i_name,i_path,i_initial,i_swap,i_width,i_height) {
  yxImages[yxImages.length]=new yx_iOBJ(i_name,i_path,i_initial,i_swap,i_width,i_height);
}

function yx_toHex(num) {
  var hexStr="0123456789ABCDEF", num2=num%16, num1=(num-num2)/16;
  return hexStr.charAt(num1)+hexStr.charAt(num2);
}

function yx_toTen(num) {
  var hexStr="0123456789ABCDEF";
  return hexStr.indexOf(num.toUpperCase());
}

function yx_fromHex(num) {
  var char1=num.charAt(0), char2=num.charAt(1);
  return yx_toTen(char1)*16+yx_toTen(char2);
}

function yx_getColor(color,m) {
  var red=color.substring(1,3), green=color.substring(3,5), blue=color.substring(5,7);
  var num1=yx_fromHex(red)+m*51, num2=yx_fromHex(green)+m*51, num3=yx_fromHex(blue)+m*51;
  if (num1<0) { num1=0; }
  if (num1>255) { num1=255; }
  if (num2<0) { num2=0; }
  if (num2>255) { num2=255; }
  if (num3<0) { num3=0; }
  if (num3>255) { num3=255; }
  return "#"+yx_toHex(num1)+yx_toHex(num2)+yx_toHex(num3);
}

function yx_getStyle() {
  if (this.head.style!=null) {
    var styles=this.head.style.member;
    for (var i=0; i<styles.length; i++) {
      if (styles[i].menu==this.content.name) {
        this.style=yx_getMenu(styles[i].style); return;
      }
    }
  }
  this.style=yx_sMenus[0];
}

function yx_getItemStyle(lead) {
  if (this.content.group!="" && lead.head.style!=null) {
    var styles=lead.head.style.member;
    for (var i=0; i<styles.length; i++) {
      if (styles[i].menu==this.content.group) {
        return yx_getMenu(styles[i].style);
      }
    }
  }
  return lead.style;
}

function yx_xyObj(x,y) { this.x=x; this.y=y; }
function yx_getSlot(n) {
  var w=yx_getWinWidth(), h=yx_getWinHeight();
  var x=(n==0 || n==6 || n==7)?0:((n==1 || n==5 || n== 8)?Math.round(w/2):(w-1));
  var y=(n==0 || n==1 || n==2)?0:((n==3 || n==7 || n== 8)?Math.round(h/2):(h-1));
  return (new yx_xyObj(x,y));
}

function yx_findIns(name,mode) {
  var ins=yx_findOBJ(yxIns, name);
  return mode?((ins!=null && ins.menu!=null && ins.menu.ready)?ins:null):ins;
}

function yx_closeIns(ins) {
  for (var i=0; i<yxIns.length; i++) {
    if (yxIns[i].menu.shown && yxIns[i]!=ins) yxIns[i].hideIns();
  }
}

function yx_setIdx(ins,idx) { ins.z=idx; yx_setZIndex(ins.menu.holder,idx); }

function addInstance(i_name,i_menu,i_type,i_pos,i_ref,i_idx,i_xalign,i_yalign,i_x,i_y,i_form,i_dir,i_vis,i_target,i_style,i_mode) {
  if (yx_goodI) {
    var content=yx_findContent(i_menu);
    if (content!=null) {
      yx_showMsg("Adding menu ["+i_name+"]");

      var newIns=yx_findIns(i_name,false);
      if (newIns==null) {
        newIns=new yx_insOBJ(i_name,content.menu,i_type,i_pos,i_ref,i_idx,i_xalign,i_yalign,i_x,i_y,i_form,i_dir,i_vis,i_target,i_style,i_mode);
        yxIns[++yxIdx]=newIns;
      }

      if (newIns.vis=="show") { newIns.showIns(); }

      yx_showMsg("Menu Instance ["+i_name+"] enabled");
    }
    else {
      yx_goodI=false;
      yx_showMsg("Menu content not found: ["+i_menu+"]");
    }
  }
}

function yx_imgOBJ(i_group,i_path,i_initial,i_swap,i_width,i_height,i_align) {
  this.name=i_group;
  this.path=yx_getPath(i_path);
  this.initial=i_initial; this.swap=i_swap;
  this.width=i_width; this.height=i_height; this.align=i_align;
}; var yxImg=new Array();

function appendImage(i_group,i_path,i_initial,i_swap,i_width,i_height,i_align) {
  yxImg[yxImg.length]=new yx_imgOBJ(i_group,i_path,i_initial,i_swap,i_width,i_height,i_align);
}

function yx_eventOBJ(e_name,e_handler1,e_handler2) {
  this.name=e_name;
  this.code1=e_handler1; this.code2=e_handler2;
}; var yxICodes=new Array(), yxMCodes=new Array();

function yx_dimOBJ(x,y,width,height,scrollx,scrolly) {
  this.x=x; this.y=y; this.width=width; this.height=height; this.scrollx=scrollx; this.scrolly=scrolly;
}

function yx_getDim() { yx_sX=yx_getScrollX(); yx_sY=yx_getScrollY(); yx_wW=yx_getWinWidth(); yx_wH=yx_getWinHeight(); }

function yx_getPos(mode) {
  var head=this.head, pItem=this.lead, pMenu=pItem.lead, sPad=this.style.sPad, sW=sPad.bSize+sPad.sWidth, sH=sPad.bSize+sPad.sHeight;
  var x_align=head.xAlign, y_align=head.yAlign, dir=(pMenu==null)?"":(pMenu.lead==head)?(head.dir):(pMenu.style.sPad.dir=="")?(head.dir):(pMenu.style.sPad.dir);

  yx_getDim();

  var padX=0, padY=0;
  if (pItem==head) {
    if (x_align=="left") {
      padX=0;
    }
    else if (x_align=="center") {
      padX=-Math.round(this.width/2);
    }
    else {
      padX=-this.width;
    }

    if (y_align=="top") {
      padY=0;
    }
    else if (y_align=="middle") {
      padY=-Math.round(this.height/2);
    }
    else {
      padY=-this.height;
    }

    padX+=head.holder.x; padY+=head.holder.y;
  }
  else if (pMenu.lead==head && head.form==yx_menuBar || pMenu.lead!=head && pMenu.style.sPad.mode==yx_menuBar) {
    var iX=pMenu.x+pItem.x, iY=pMenu.y+pItem.y, iW=pItem.width, iH=pItem.height;

    if (dir=="right-down") {
      padX=iX-sW; padY=iY+iH;
    }
    else if (dir=="right-up") {
      padX=iX-sW; padY=iY-this.height;
    }
    else if (dir=="left-down") {
      padX=iX+iW-this.width+sW; padY=iY+iH;
    }
    else {
      padX=iX+iW-this.width+sW; padY=iY-this.height;
    }
  }
  else {
    var iX=pMenu.x+pItem.x, iY=pMenu.y+pItem.y, iW=pItem.width, iH=pItem.height;

    if (dir=="right-down") {
      padX=iX+iW; padY=iY-sH;
    }
    else if (dir=="right-up") {
      padX=iX+iW; padY=iY+iH-this.height+sH;
    }
    else if (dir=="left-down") {
      padX=iX-this.width; padY=iY-sH;
    }
    else {
      padX=iX-this.width; padY=iY+iH-this.height+sH;
    }
  }

  padX+=sPad.dx; padY+=sPad.dy;

  if (pItem!=head) {
    var padTop=padY, padBottom=padTop+this.height-1, padLeft=padX, padRight=padLeft+this.width-1;
    var dx=0, dy=0;

    if (padBottom-yx_sY>=yx_wH) {
      dy=yx_wH+yx_sY-padBottom-1;
      if (padTop+dy<yx_sY) { dy=yx_sY-padTop; }
    }
    else {
      dy=(padTop<yx_sY)?(yx_sY-padTop):0;
    }
  
    if (padRight-yx_sX>=yx_wW) {
      dx=yx_wW+yx_sX-padRight-1;
      if (padLeft+dx<yx_sX) { dx=yx_sX-padLeft; }
    }
    else {
      dx=(padLeft<yx_sX)?(yx_sX-padLeft):0;
    }
  
    if (dx!=0 || dy!=0) { padX+=dx; padY+=dy; }
  }

  this.movMenuTo(padX,padY);

  if (mode && !this.shown && (pMenu==null || pMenu.active==pItem)) {
    if (pMenu!=null) {
      yx_setZIndex(this.holder, yx_getZIndex(pMenu.holder)+1);
    }
    else {
      yx_setZIndex(this.holder, ++zBase);
    }
    if (this.code1!="") { eval(this.code1); }
    yx_showLayer(this.holder); this.shown=true;
  }

  if (pItem==head && head.type=="floating" && head.timer<0) { head.timeIt(); }
}

function yx_showM() {
  if (this.ready) {
    this.getPos(true);
  }
  else {
    if (!this.flying) {
      this.flying=true;
      yx_callBack(this,"makeM()",0);
    }
  }
}

function yx_hideM(mode) {
  if (this.shown) {
    for (var i=0; i<this.itemL; i++) {
      if (this.items[i].menu!=null) { this.items[i].menu.hideM(true); }
    }

    if (this.active!=null) { this.active.offIt(); this.active=null; }

    if (this.lead!=this.head || (mode && this.head.vis!="show")) {
      yx_hideLayer(this.holder); this.shown=false;
      if (this.code2!="") { eval(this.code2); }
    }
  }
}

function yx_movMenuTo(x,y) { yx_moveLayerTo(this.holder,x,y); this.x=x; this.y=y; }
function yx_movMenuBy(x,y) { yx_moveLayerBy(this.holder,x,y); this.x+=x; this.y+=y; }

function yx_menuOBJ(head,lead,content) {
  this.head=head;
  this.lead=lead;
  this.content=content;

  this.holder=null; this.pad=null;
  this.padB=null; this.padP=null; this.me=-1;

  this.itemL=content.items.length;
  this.items=new Array();

  this.ready=false; this.flying=false; this.shown=false; this.active=null;

  this.x=0; this.y=0; this.width=0; this.height=0; this.getPos=yx_getPos;
  this.code1=""; this.code2="";

  this.style=null; this.getStyle=yx_getStyle;

  this.makeP=yx_makeP; this.makeM=yx_makeM; this.showM=yx_showM; this.hideM=yx_hideM; this.movMenuTo=yx_movMenuTo; this.movMenuBy=yx_movMenuBy;
}

function yx_showIns() {
  if (this.holder==null) { this.getHolder(); }
  yx_closeIns(this); this.menu.showM();
}
function yx_hideIns() { this.menu.hideM(true); }
function yx_movInsTo(x,y) {
  if (this.menu.ready) {
    this.holder.x=x; this.holder.y=y;
    this.menu.hideM(false); this.menu.getPos(false);
  }
}
function yx_movInsBy(x,y) {
  if (this.menu.ready) {
    this.holder.x+=x; this.holder.y+=y;
    this.menu.hideM(false); this.menu.movMenuBy(x,y);
  }
}

function yx_timeIt() {
  yx_getDim();

  if (this.sX!=yx_sX || this.sY!=yx_sY) {
    var dx=yx_sX-this.sX, dy=yx_sY-this.sY; this.sX=yx_sX; this.sY=yx_sY;
    this.movInsBy(dx,dy);
  }

  this.timer=yx_callBack(this,"timeIt()",menuTimer);
}

function yx_getHolder() {
  var x=0, y=0;
  if (this.pos=="relative") {
    var l=yx_findLayer(((yx_isN4 || yx_isK3) && this.idx!="")?this.idx:this.ref);
    if (l!=null) {
      x=yx_getLeft(l); y=yx_getTop(l); 
    }
  }
  else if (this.pos=="slot") {
    var s=yx_getSlot(parseInt(this.idx));
    x=s.x; y=s.y;
  }

  x+=this.dx; y+=this.dy; this.ox=x; this.oy=y;
  this.holder=new yx_xyObj(x,y);
}

// ------
function getMenuDim(i_name) {
  var ins=yx_findIns(i_name,true);
  if (ins!=null) {
    return new yx_dimOBJ(ins.menu.x, ins.menu.y, ins.menu.width, ins.menu.height, yx_getScrollX(), yx_getScrollY());
  }
  else {
    return null;
  }
}

function showMenu(n) {
  var ins=yx_findIns(n,false);
  if (ins!=null) {
    if (yx_iTimer>0) { clearTimeout(yx_iTimer); }
    ins.showIns();
  }
}

function showMenuX(n) {
  var ins=yx_findIns(n,false);
  if (ins!=null) {
    if (yx_iTimer>0) { clearTimeout(yx_iTimer); }
    ins.vis="show"; ins.showIns();
  }
}

function hideMenu(n) {
  var ins=yx_findIns(n,true);
  if (ins!=null) { ins.hideIns(); }
}

function hideMenuX(n) {
  var ins=yx_findIns(n,true);
  if (ins!=null) { ins.vis="hide"; ins.hideIns(); }
}

function moveMenuTo(n,x,y) {
  var ins=yx_findIns(n,true);
  if (ins!=null) { ins.movInsTo(x,y); }
}

function moveMenuBy(n,x,y) {
  var ins=yx_findIns(n,true);
  if (ins!=null) { ins.movInsBy(x,y); }
}

function moveMenuBack(n) {
  var ins=yx_findIns(n,true);
  if (ins!=null) { ins.movInsTo(ins.ox,ins.oy); }
}

function addItemEvent(e_name,e_handler1,e_handler2) {
  var x=yx_findItemEvent(e_name);
  if (x==null) { yxICodes[yxICodes.length]=new yx_eventOBJ(e_name,e_handler1,e_handler2); }
}

function addMenuEvent(e_name,e_handler1,e_handler2) {
  var x=yx_findMenuEvent(e_name);
  if (x==null) { yxMCodes[yxMCodes.length]=new yx_eventOBJ(e_name,e_handler1,e_handler2); }
}

function addWindowEvent(e_handler) { yx_winEvent=e_handler; }
// ------

if (yx_menuSafe) {
  var yx_menuScript=scriptPath+(yx_isN6?"menuG3N6.js":yx_isN4?"menuG3N4.js":yx_isK3?"menuG3K3.js":yx_isO7?"menuG3O7.js":yx_isIE5?"menuG3IE5.js":"menuG3IE4.js");
  document.write("<scr"+"ipt language='javascript' src='"+yx_menuScript+"' type='text/javascript'><\/scr" + "ipt>");
  if (contentScript!="") {
    document.write("<scr"+"ipt language='javascript' src='"+contentScript+"' type='text/javascript'><\/scr" + "ipt>");
  }
  if (styleScript!="") {
    document.write("<scr"+"ipt language='javascript' src='"+styleScript+"' type='text/javascript'><\/scr" + "ipt>");
  }
  if (instanceScript!="") {
    document.write("<scr"+"ipt language='javascript' src='"+instanceScript+"' type='text/javascript'><\/scr" + "ipt>");
  }
}
else if (nonMenuPage!="") {
  setTimeout("window.location.replace('"+nonMenuPage+"')",0);
}

