
// ------
var isIE4=false,isNN4=false;
var flagMenu="M",flagLink="L",flagCommand="C",flagSeparator="S",flagInfo="I",flagImageLink="iL",flagImageMenu="iM",flagImageCommand="iC";
var menuTimer=600,layerCount=0,imageCount=0;
var groupValid=true,groupReady=false,holdIt=false;
var turnOn="",turnOff="",menuOffset=0;
var onePixel=new Image(1,1); onePixel.src="tags/onePixel.gif";
var pixelImage='<img src="'+onePixel.src+'" width="1" height="1" border="0">';
var defaultTag=new Image(7,7); defaultTag.src="tags/tag1r.gif";
var yxG=new Array(),gCount=0,yxF=new Array(),fCount=0,yxGroup=null,yxStyle=null;

// ------
function getArray(_array) { return eval("window."+_array); }
function getID() { return "yxLayer"+(++layerCount)+""; }
function getName() { return "yxImage"+(++imageCount)+""; }
function showMessage(_message) { window.status=_message; }
function showError(_error) { showMessage(_error); groupValid=false; }
function checkBrowser() { isIE4=(document.all)?true:false; isNN4=(document.layers)?true:false; }

function setParameter() {
  if (isNN4) {
    turnOn="show"; turnOff="hidden"; menuOffset=1;
  }
  else {
    turnOn="visible"; turnOff="hidden"; menuOffset=2;
  }
}

function getGroup(_name) {
  var theGroup=null;

  for (var i=0; i<gCount; i++) {
    if (yxG[i].name==_name) { theGroup=yxG[i]; break; }
  }

  return theGroup;
}

function _getHolder(_frame,_name) {
  var holder=null;

  if (isIE4) {
    if (_frame.document.all[_name]) { holder=_frame.document.all[_name]; holder.css=holder.style; }
  }
  else {
    if (_frame.document.layers[_name]) { holder=_frame.document.layers[_name]; holder.css=holder; }
  }

  holder.xx=0; holder.yy=0;

  return holder;
}

function _makeHolder(_frame,_position) {
  var holder=null,holderX=0,holderY=0;

  holderX=(_frame.contentWidth)-((_position==0 || _position==6 || _position==7)?_frame.contentWidth:((_position==1 || _position==5 || _position==8)?_frame.halfWidth:0));
  holderY=(_frame.contentHeight)-((_position==0 || _position==1 || _position==2)?_frame.contentHeight:((_position==3 || _position==7 || _position==8)?_frame.halfHeight:0));

  if (isIE4) {
    var layerID=getID();
    _frame.document.body.insertAdjacentHTML("BeforeEnd",('<div id="'+layerID+'" style="position:absolute; left:'+holderX+'; top:'+holderY+'; width:0; visibility:visible; z-index:1;"></div>'));
    holder=_frame.document.all[layerID];

    holder.css=holder.style;
  }
  else {
    holder=new Layer(1,_frame);

    holder.zIndex=1;
    holder.visibility="show";

    holder.left=holderX; holder.top=holderY;

    holder.css=holder;
  }

  holder.xx=holderX; holder.yy=holderY;

  return holder;
}

function _getLeft(_holder) { return (_holder.offsetParent.tagName=="BODY")?(_holder.offsetLeft):(_holder.offsetLeft+_getLeft(_holder.offsetParent)); }
function _getTop(_holder) { return (_holder.offsetParent.tagName=="BODY")?(_holder.offsetTop):(_holder.offsetTop+_getTop(_holder.offsetParent)); }
function getTop(_holder) { return (isIE4)?_getTop(_holder):_holder.pageY; }

function getHolder(_frame,_name,_position,_x,_y) {
  var holder=null;

  if (_name!="") { holder=_getHolder(_frame,_name); }
  if (holder==null) { holder=_makeHolder(_frame,_position); }

  moveLayerBy(holder,_x,_y);
  holder.xx+=_x; holder.yy+=_y; holder.dy=getTop(holder);

  return holder;
}

function getStyle(_frame,_name) {
  _name=(_name=="")?"default":_name;
  for (var i=0; i<_frame.sCount; i++) {
    if (_frame.yxS[i].styleName==_name) { return _frame.yxS[i]; }
  }

  return yxStyle;
}

function getLength(_frame,_content) {
  var theLength=0;

  if (isIE4) {
    var layerID=getID();
    _frame.document.body.insertAdjacentHTML("BeforeEnd",('<div id="'+layerID+'" style="position:absolute; visibility:hidden;">'+_content+'</div>'));
    theLength=_frame.document.all[layerID].children[0].offsetWidth;
  }
  else {
    var layer=new Layer(1,_frame);
    layer.visibility="hidden";
    with (layer.document) {
      open(); writeln(_content); close();
    }

    theLength=layer.document.width;
  }

  return theLength;
}

function getFrame(_name) {
  for (var i=0; i<fCount; i++) {
    if (yxF[i].name==_name) { return yxF[i].frame; }
  }

  return null;
}

function makeLayer(_width,_content,_color,_index,_holder) {
  var layer=null;

  if (isIE4) {
    var layerID=getID();
    _holder.insertAdjacentHTML("BeforeEnd",('<div id="'+layerID+'" style="position:absolute; left:0; top:0; width:'+_width+'; background-color:'+_color+'; visibility:hidden; z-index:'+_index+';">'+_content+'</div>'));
    layer=_holder.document.all[layerID];

    layer.css=layer.style;
  }
  else {
    layer=new Layer(_width,_holder);

    layer.zIndex=_index;
    layer.visibility="hidden";

    layer.left=-_width; layer.top=0;

    with (layer.document) {
      open(); writeln(_content); close();
    }

    layer.bgColor=_color;

    layer.css=layer;
  }

  return layer;
}

function moveLayerTo(_layer,_x,_y) {
  if (isIE4) {
    _layer.style.pixelLeft=_x; _layer.style.pixelTop=_y;
  }
  else {
    _layer.moveTo(_x,_y);
  }
}

function moveLayerBy(_layer,_x,_y) {
  if (isIE4) {
    _layer.style.pixelLeft+=_x; _layer.style.pixelTop+=_y;
  }
  else {
    _layer.moveBy(_x,_y);
  }
}

function makeSeparator(_separator,_width,_height,_form,_style) {
  var itemWidth=0,itemHeight=0,itemLayout="";

  if (_form==0) {
    itemWidth=_width-_style.spacing*2; itemHeight=2;
    itemLayout='<table align="left" width="'+itemWidth+'" height="2" cellpadding="0" cellspacing="0" border="0"><tr align="left" valign="top"><td bgcolor="'+_style.borderColorDark+'" width="'+itemWidth+'" height="1">'+pixelImage+'</td></tr><tr align="left" valign="top"><td bgcolor="'+_style.borderColorBright+'" width="'+itemWidth+'" height="1">'+pixelImage+'</td></tr></table>';
  }
  else {
    itemWidth=2; itemHeight=_height-_style.spacing*2;
    itemLayout='<table align="left" width="2" height="'+itemHeight+'" cellpadding="0" cellspacing="0" border="0"><tr align="left" valign="top"><td bgcolor="'+_style.borderColorDark+'" width="1" height="'+itemHeight+'">'+pixelImage+'</td><td bgcolor="'+_style.borderColorBright+'" width="1" height="'+itemHeight+'">'+pixelImage+'</td></tr></table>';
  }

  if (isIE4) {
    _separator.layer.innerHTML=itemLayout;
  }
  else {
    with (_separator.layer.document) {
      open(); writeln(itemLayout); close();
    }
  }

  _separator.width=itemWidth; _separator.height=itemHeight;
}

function setClip(_layer,_x1,_y1,_x2,_y2) {
  _layer.clip.left=_x1; _layer.clip.top=_y1;
  _layer.clip.width=_x2-_x1; _layer.clip.height=_y2-_y1;
}

function blurIt(_items) {
  var itemCount=_items.length;
  for (var i=0; i<itemCount; i++) {
    if (_items[i].layer.focused) {
      if (_items[i].type==flagMenu || _items[i].type==flagImageMenu) { _items[i].menu.hideMenu(); }

      _items[i].layer.turnColor(false);
      break;
    }
  }
}

function _initGroup() {
  showMessage("Parsing menu definitions");

  gCount=yxGroup.length;
  for (var i=0; i<gCount && groupValid; i++) {
    yxG[i]=new _groupOBJ(yxGroup[i]);
    yxG[i].readGroup();
  }

  if (groupValid) {
    yxStyle=new _styleOBJ("default",6,1,2,"#cccccc","#cccccc","#ffffff",1,"#f8f8f8","#666666","verdana,arial",14,"normal","none","#000000",1,7,7,"tag1r.gif","tags/",100);

    groupReady=true;
    showMessage("Parsed menu definitions");
  }
}

// ------
function _itemOBJ(_ITEM) {
  this.type=_ITEM[0];

  if (this.type!=flagSeparator) {
    this.name=_ITEM[1];

    if (this.type!=flagInfo) {
      this.help=_ITEM[2];
      this.value=_ITEM[3];

      if (this.type==flagMenu || this.type==flagImageMenu) {
        this.menu=new _menuOBJ(_ITEM[4],parseInt(_ITEM[5]));
        this.tag=_ITEM[6];
      }
      else {
        this.tag="0";
      }

      if (this.type==flagCommand || this.type==flagImageCommand || this.type==flagLink || this.type==flagImageLink) {
        this.onCodes=_ITEM[4]; this.outCodes=_ITEM[5];
      }

      if (this.type==flagImageLink || this.type==flagImageCommand) {
        this.initial=_ITEM[6]; this.swapping=_ITEM[7];
        this.imageWidth=parseInt(_ITEM[8]); this.imageHeight=parseInt(_ITEM[9]);
      }
      else if (this.type==flagImageMenu) {
        this.initial=_ITEM[7]; this.swapping=_ITEM[8];
        this.imageWidth=parseInt(_ITEM[9]); this.imageHeight=parseInt(_ITEM[10]);
      }
    }
  }
}

function _menuOBJ(_array,_width) {
  this.array=_array;
  this.width=_width;

  this.items=new Array();

  this.readMenu=readMenu;
}

function _groupOBJ(_GROUP) {
  this.name=_GROUP[0];

  this.menu=new _menuOBJ(_GROUP[1],parseInt(_GROUP[2]));

  this.readGroup=readGroup;
}

function _styleOBJ(_styleName,_paddingWidth,_paddingHeight,_spacing,_spacingColor,_colorNormal,_colorHighlighted,_border,_borderColorBright,_borderColorDark,_textFont,_textSize,_textWeight,_textDecoration,_textColor,_tag,_tagWidth,_tagHeight,_tagImage,_imagePath,_widthRatio) {
  this.styleName=_styleName;
  this.paddingWidth=_paddingWidth; this.paddingHeight=_paddingHeight;
  this.spacing=_spacing; this.spacingColor=_spacingColor;
  this.colorNormal=_colorNormal; this.colorHighlighted=_colorHighlighted;
  this.borderOn=(_border==0)?false:true; this.borderColorBright=_borderColorBright; this.borderColorDark=_borderColorDark;
  this.textFont=_textFont; this.textSize=_textSize; this.textWeight=_textWeight; this.textDecoration=_textDecoration; this.textColor=_textColor;
  this.tagOn=(_tag==0)?false:true; this.tagWidth=_tagWidth; this.tagHeight=_tagHeight; this.tagImage=_tagImage;
  this.imagePath=_imagePath;
  this.widthRatio=_widthRatio;
}

function styleOBJ(_style) {
  this.tagOpening='<span style="text-decoration:'+_style.textDecoration+'; font-size:'+_style.textSize+'px; color:'+_style.textColor+'; font-weight:'+_style.textWeight+'; font-family:'+_style.textFont+';">';
  this.tagClosing='</span>';
  this.tagImage='<td width="'+_style.tagWidth+'" align="left" valign="middle"><img src="'+_style.imagePath+_style.tagImage+'" width="'+_style.tagWidth+'" height="'+_style.tagHeight+'" border="0"></td>';
  this.tagDummy='<td width="'+_style.tagWidth+'" align="left" valign="middle">'+pixelImage+'</td>';
  this.paddingCol=(_style.paddingWidth==0)?'':('<td width="'+_style.paddingWidth+'">'+pixelImage+'</td>');
}

function itemOBJ(_instance,_type) {
  this.instance=_instance;
  this.type=_type;

  this.x=0; this.y=0;
  this.width=0; this.height=0;

  this.layer=null;

  this.makeItem=makeItem;
  this.showItem=showIt;
  this.hideItem=hideIt;
  this.moveItem=moveIt;

  if (this.type==flagMenu || this.type==flagImageMenu) {
    this.menu=new menuOBJ(this.instance,false);
  }
}

function padOBJ(_instance) {
  this.instance=_instance;

  this.x=0; this.y=0; this.dy=0;
  this.width=0; this.height=0;

  this.layer=null;

  this.makePad=makePad;
  this.showPad=showIt;
  this.hidePad=hideIt;
  this.movePad=moveIt;
}

function paraOBJ(_frame,_x,_y,_menu,_index,_form,_pad,_level) {
  this._frame=_frame;
  this._x=_x; this._y=_y;
  this._menu=_menu;
  this._index=_index;
  this._form=_form;
  this._pad=_pad;
  this._level=_level;
}

function menuOBJ(_instance,_initial) {
  this.instance=_instance;
  this.initial=_initial;

  this.ready=false;
  this.shown=false;
  this.para=null;

  this.clipX=0; this.clipY=0; this.clipWidth=0; this.clipHeight=0;

  this.pad=new padOBJ(this.instance);
  this.items=new Array();

  this.addMenu=addMenu;
  this.makeMenu=makeMenu;
  this.showMenu=showMenu;
  this.hideMenu=hideMenu;
}

function instanceOBJ(_frame,_instance,_name,_type,_position,_holder,_x,_y,_direction,_form,_initial,_target,_group,_style1,_style2) {
  this.frame=_frame;
  this.instance=_instance,
  this.name=_name;
  this.type=_type;
  this.position=_position;
  this.holder=getHolder(_frame,((_type!=1 && _type!=2)?_holder:""),_position,_x,_y);
  this.x=0; this.y=0;
  this.direction=_direction;
  this.form=_form;
  this.initial=(_initial==0)?false:true;
  this.target=(_target=="")?'':(' target="'+_target+'"');
  this.group=getGroup(_group);

  this.style=new Array();
  this.style[0]=getStyle(_frame,_style1); this.style[1]=getStyle(_frame,_style2);

  this.styleX=new Array();
  this.styleX[0]=new styleOBJ(this.style[0]); this.styleX[1]=new styleOBJ(this.style[1]);

  this.maxX=0; this.maxY=0; this.minX=0; this.minY=0;

  this.timer=-1;
  this.shown=false;

  this.menu=new menuOBJ(this.instance,this.initial);

  this.makeInstance=makeInstance;
  this.showInstance=showInstance;
  this.hideInstance=hideInstance;
  this.moveInstanceTo=moveInstanceTo;
  this.moveInstanceBy=moveInstanceBy;
  this.checkInstance=checkInstance;
  this.registerPop=registerPop;
  this.registerMap=registerMap;
}

function frameOBJ(_name,_frame) { this.name=_name; this.frame=_frame; }

// ------
function readMenu() {
  var theMenu=getArray(this.array);
  if (theMenu) {
    var menuLength=theMenu.length;
    for (var i=0; i<menuLength && groupValid; i++) {
      this.items[i]=new _itemOBJ(theMenu[i]);

      if (this.items[i].type==flagMenu || this.items[i].type==flagImageMenu) { this.items[i].menu.readMenu(); }
    }
  }
  else {
    showError("Menu Not Found: ["+this.array+"]");
  }
}

function readGroup() { this.menu.readMenu(); }
function showIt() { this.layer.css.visibility=turnOn; }
function hideIt() { this.layer.css.visibility=turnOff; }
function moveIt(_x,_y) { moveLayerTo(this.layer,_x,_y); }

function makeItem(item,_tag,_frame,_width,_index,_form,_active,_level) {
  var instance=_frame.yxI[this.instance],iStyle=instance.style[_level],iStyleX=instance.styleX[_level],holder=instance.holder;
  var itemBar="",itemIt=""
  var paddingSpan=(((iStyle.paddingWidth==0)?1:3)+((_tag)?1:0));
  var paddingRow="",tagContent="",barWidth=(item.type==flagSeparator)?2:(_width+((_tag)?iStyle.tagWidth:0)+iStyle.paddingWidth*2);

  if (item.type==flagSeparator) {
    itemBar='<table align="left" width="2" height="2" cellpadding="0" cellspacing="0" border="0"><tr><td width="2" height="2"></td></tr></table>';
  }
  else {
    tagContent=(_tag)?(((item.type==flagImageMenu)||(item.type==flagMenu))?((item.tag=="0")?iStyleX.tagDummy:iStyleX.tagImage):iStyleX.tagDummy):"";

    if (item.type==flagImageLink || item.type==flagImageMenu || item.type==flagImageCommand) {
      if (_form!=2) {
        var imageWidth=(item.imageWidth<=_width)?item.imageWidth:_width;
        var imageHeight=Math.floor(item.imageHeight*imageWidth/item.imageWidth);
      }
      else {
        var imageWidth=item.imageWidth,imageHeight=item.imageHeight;

        barWidth+=(imageWidth-_width);
      }

      var imageName=getName();
      itemIt='<img src="'+iStyle.imagePath+item.initial+'" name="'+imageName+'" width="'+imageWidth+'" height="'+imageHeight+'" border="0">'
    }
    else {
      itemIt=iStyleX.tagOpening+item.name+iStyleX.tagClosing;

      if (_form==2 && item.type!=flagInfo) {
        itemIt="<nobr>"+itemIt+"</nobr>";
        barWidth+=(getLength(_frame,itemIt)-_width);
      }
    }

    if (item.type!=flagInfo) {
      itemIt='<a href="'+((item.type==flagCommand || item.type==flagImageCommand)?'#" onclick="'+item.value+';return false;':item.value)+'" onMouseOver="'+((item.type!=flagMenu && item.type!=flagImageMenu)?item.onCodes:'')+';window.status='+"'"+item.help+"'"+';return true;"'+((item.type!=flagMenu && item.type!=flagImageMenu)?(' onMouseOut="'+item.outCodes+'"'):'')+((item.type==flagCommand || item.type==flagImageCommand)?'':instance.target)+'>'+itemIt+'</a>';
    }

    paddingRow=(iStyle.paddingHeight==0)?'':('<tr align="left" valign="top"><td colspan="'+paddingSpan+'" width="'+barWidth+'" height="'+iStyle.paddingHeight+'">'+pixelImage+'</td></tr>');

    itemBar='<table align="left" width="'+barWidth+'" cellpadding="0" cellspacing="0" border="0">'+paddingRow+'<tr align="'+((_form==0)?"left":"center")+'" valign="middle">'+((instance.direction==0||instance.direction==3)?'':tagContent)+iStyleX.paddingCol+'<td width="'+_width+'">'+itemIt+'</td>'+iStyleX.paddingCol+((instance.direction==0||instance.direction==3)?tagContent:'')+'</tr>'+paddingRow+'</table>';
  }

  this.layer=makeLayer(barWidth,itemBar,iStyle.colorNormal,_index,holder);

  this.layer.frame=_frame;
  this.layer.instance=this.instance;
  this.layer.type=item.type;
  this.layer.help=(item.type==flagSeparator || item.type==flagInfo)?"":item.help;
  this.layer.focused=false;
  this.layer.active=_active;
  this.layer.dy=0;

  this.layer.colorHighlighted=iStyle.colorHighlighted; this.layer.colorNormal=iStyle.colorNormal;

  if (item.type==flagImageLink || item.type==flagImageMenu || item.type==flagImageCommand) {
    this.layer.initial=iStyle.imagePath+item.initial; this.layer.swapping=iStyle.imagePath+item.swapping;
    this.layer.imageName=imageName;
  }

  this.layer.onmouseover=overItem;
  this.layer.onmouseout=outIt;
  this.layer.turnColor=turnIt;

  this.width=barWidth;
  this.height=(isIE4)?(this.layer.children[0].offsetHeight):(this.layer.document.height);
}

function makePad(_frame,_index,_active,_level) {
  var instance=_frame.yxI[this.instance],iStyle=instance.style[_level],holder=instance.holder;
  var menuPad=(iStyle.borderOn && iStyle.spacing>0)?('<table align="left" width="'+this.width+'" height="'+this.height+'" cellspacing="0" cellpadding="0" border="0"><tr align="left" valign="top"><td bgcolor="'+iStyle.borderColorBright+'" width="1" height="'+(this.height-1)+'" rowspan="2">'+pixelImage+'</td><td bgcolor="'+iStyle.borderColorBright+'" width="'+(this.width-2)+'" height="1">'+pixelImage+'</td><td bgcolor="'+iStyle.borderColorDark+'" width="1" height="'+(this.height-1)+'" rowspan="2">'+pixelImage+'</td></tr><tr align="left" valign="top"><td width="'+(this.width-2)+'" height="'+(this.height-2)+'">'+pixelImage+'</td></tr><tr align="left" valign="top"><td bgcolor="'+iStyle.borderColorDark+'" width="'+this.width+'" height="1" colspan="3">'+pixelImage+'</td></tr></table>'):('<table align="left" width="'+this.width+'" height="'+this.height+'" cellpadding="0" cellspacing="0" border="0"><tr><td>'+pixelImage+'</td></tr></table>');

  this.layer=makeLayer(this.width,menuPad,iStyle.spacingColor,_index,holder);

  this.layer.frame=_frame;
  this.layer.instance=this.instance;
  this.layer.active=_active;

  this.layer.onmouseover=overPad;
  this.layer.onmouseout=outIt;
}

function addMenu(_frame,_x,_y,_menu,_index,_form,_pad,_level) { this.para=new paraOBJ(_frame,_x,_y,_menu,_index,_form,_pad,_level); }

function makeMenu() {
  var para=this.para,instance=para._frame.yxI[this.instance],iStyle=instance.style[para._level],direction=instance.direction;
  var items=para._menu.items,itemCount=items.length;
  var useTag=false;

  for (var i=0; i<itemCount; i++) {
    if (items[i].type==flagMenu || items[i].type==flagImageMenu) {
      useTag=(items[i].tag=="")?(iStyle.tagOn&&para._form==0):((items[i].tag=="0")?false:true);
      if (useTag) { break; }
    }
  }

  var itemWidth=Math.floor(para._menu.width*iStyle.widthRatio/100);
  if (para._form==0) {
    this.pad.width=itemWidth+(iStyle.paddingWidth+iStyle.spacing)*2+((useTag)?iStyle.tagWidth:0);
    this.pad.height=iStyle.spacing*2;
  }
  else {
    this.pad.width=iStyle.spacing*2;
  }

  for (var i=0; i<itemCount; i++) {
    this.items[i]=new itemOBJ(this.instance,items[i].type);
    this.items[i].makeItem(items[i],useTag,para._frame,itemWidth,para._index+1,para._form,this.initial,para._level);

    if (para._form==0) {
      this.pad.height+=this.items[i].height;
    }
    else {
      if (this.pad.height<(this.items[i].height+iStyle.spacing*2)) { this.pad.height=this.items[i].height+iStyle.spacing*2; }
      this.pad.width+=this.items[i].width;
    }
  }

  this.pad.makePad(para._frame,para._index,this.initial,para._level);

  this.pad.x=para._x-((direction==1||direction==2)?this.pad.width:0);
  this.pad.y=para._y-((direction==2||direction==3)?this.pad.height:0);

  this.pad.movePad(this.pad.x,this.pad.y);

  if (isNN4) {
    this.pad.pminX=para._pad.minX; this.pad.pminY=para._pad.minY;
    this.pad.pmaxX=para._pad.maxX; this.pad.pmaxY=para._pad.maxY;

    this.pad.minX=(para._pad.minX>this.pad.x)?this.pad.x:para._pad.minX;
    this.pad.minY=(para._pad.minY>this.pad.y)?this.pad.y:para._pad.minY;
    this.pad.maxX=(para._pad.maxX<this.pad.x+this.pad.width)?(this.pad.x+this.pad.width):para._pad.maxX;
    this.pad.maxY=(para._pad.maxY<this.pad.y+this.pad.height)?(this.pad.y+this.pad.height):para._pad.maxY;
  }

  var itemX=this.pad.x+iStyle.spacing,itemY=this.pad.y+iStyle.spacing,subX=0,subY=0;
  for (var i=0; i<itemCount; i++) {
    this.items[i].layer.peer=this.items;
    this.items[i].x=itemX; this.items[i].y=itemY;
    this.items[i].moveItem(itemX,itemY);

    if (items[i].type==flagMenu || items[i].type==flagImageMenu) {
      if (para._form==0) {
        subX=itemX+((direction==0||direction==3)?(this.items[i].width):0);
        subY=itemY+((direction==0||direction==1)?(-iStyle.spacing):(this.items[i].height+iStyle.spacing));
      }
      else {
        subX=itemX+((direction==0||direction==3)?(-iStyle.spacing):(this.items[i].width+iStyle.spacing));
        subY=itemY+((direction==0||direction==1)?(this.pad.height-iStyle.spacing):(-iStyle.spacing));
      }

      this.items[i].menu.addMenu(para._frame,subX,subY,items[i].menu,para._index+2,0,this.pad,1);
      this.items[i].layer.menu=this.items[i].menu;
    }
    else if (items[i].type==flagSeparator) {
      makeSeparator(this.items[i],this.pad.width,this.pad.height,para._form,iStyle);
    }

    if (para._form==0) {
      itemY+=this.items[i].height;
    }
    else {
      itemX+=this.items[i].width;

      if (isIE4) {
        this.items[i].layer.style.height=this.pad.height-iStyle.spacing*2;
      }
      else {
        this.items[i].layer.clip.height=this.pad.height-iStyle.spacing*2;
      }
    }
  }

  this.ready=true;
}

function showMenu(_dy) {
  if (!this.ready) { this.makeMenu(); }

  var frame=this.pad.layer.frame,instance=frame.yxI[this.instance],holder=instance.holder,pad=this.pad,items=this.items,itemCount=items.length;
  var padTop=holder.dy+this.pad.y,padBottom=padTop+this.pad.height;

  if (this!=instance.menu) {
    var dy=0,scrollY=(isNN4)?frame.pageYOffset:frame.document.body.scrollTop;

    if (isNN4) {
      this.clipX=holder.clip.left; this.clipY=holder.clip.top;
      this.clipWidth=holder.clip.width; this.clipHeight=holder.clip.height;
    }

    if (instance.direction==0||instance.direction==1) {
      if (padBottom+_dy-scrollY>frame.contentHeight) {
        dy=frame.contentHeight+scrollY-padBottom;
        if (padTop+dy<scrollY) { dy=scrollY-padTop; }
      }
      else {
        dy=_dy;
      }
  
      if (isNN4) { setClip(holder,pad.minX,pad.minY+dy,pad.maxX,pad.maxY); }
    }
    else {
      dy=(padTop+_dy<scrollY)?scrollY-padTop:_dy;
      if (isNN4) { setClip(holder,pad.minX,pad.minY,pad.maxX,pad.maxY+dy); }
    }
  
    if (pad.dy!=dy) {
      pad.movePad(pad.x,pad.y+dy); pad.dy=dy;
      for (var i=0; i<itemCount; i++) {
        items[i].moveItem(items[i].x,items[i].y+dy);
        items[i].layer.dy=dy;
      }
    }
  }
  else if (isNN4) {
    setClip(holder,pad.minX,pad.minY,pad.maxX,pad.maxY);
  }

  pad.showPad();
  for (var i=0; i<itemCount; i++) { items[i].showItem(); }

  this.shown=true;
}

function hideMenu() {
  if (this.ready) {
    var items=this.items,pad=this.pad;

    if (this.initial) {
      blurIt(items);
    }
    else {
      var itemCount=items.length;
      for (var i=0; i<itemCount; i++) {
        if (items[i].type==flagMenu || items[i].type==flagImageMenu) {
          if (items[i].menu.shown) { items[i].menu.hideMenu(); }
        }

        items[i].hideItem();
        items[i].layer.turnColor(false);
      }

      pad.hidePad();
      if (isNN4) { setClip(pad.layer.frame.yxI[this.instance].holder,this.clipX,this.clipY,this.clipX+this.clipWidth,this.clipY+this.clipHeight); }
    }

    this.shown=this.initial;
  }
}

function makeInstance() { this.menu.addMenu(this.frame,this.x,this.y,this.group.menu,1,this.form,this,0); }

function showInstance() {
  var frame=this.frame;

  frame.clearTimer(this.instance);

  this.holder.css.zIndex=++frame.lastIndex;

  if (!this.shown) {
    this.menu.showMenu(0);
    this.shown=true;
  }
  else {
    blurIt(this.menu.items);
  }

  frame.lastInstance=this.instance;
}

function hideInstance() {
  this.frame.clearTimer(this.instance);
  window.status=""; 

  if (this.shown) {
    this.menu.hideMenu();
    this.shown=this.initial;
    this.holder.css.zIndex=1;
  }
}

function moveInstanceTo(_x,_y) {
  this.frame.clearTimer(this.instance);
  moveLayerTo(this.holder,_x,_y);

  this.holder.xx=_x; this.holder.yy=_y; this.holder.dy=getTop(this.holder);
}

function moveInstanceBy(_x,_y) {
  this.frame.clearTimer(this.instance);

  moveLayerBy(this.holder,_x,_y);
  this.holder.xx+=_x; this.holder.yy+=_y; this.holder.dy=getTop(this.holder);
}

function checkInstance() { this.frame._checkInstance(this.instance); }
function registerPop() { this.frame._registerPop(this.instance); }
function registerMap() { this.frame._registerMap(); }

// ------
function turnIt(_mode) {
  if (this.type==flagImageLink || this.type==flagImageMenu || this.type==flagImageCommand) {
    this.document.images[this.imageName].src=(_mode)?this.swapping:this.initial;
  }
  else {
    if (isIE4) {
      this.style.backgroundColor=(_mode)?this.colorHighlighted:this.colorNormal;
    }
    else {
      this.bgColor=(_mode)?this.colorHighlighted:this.colorNormal;
    }
  }

  this.focused=_mode;
}

function overItem() {
  var frame=this.frame,instance=frame.yxI[this.instance];

  frame.clearTimer(this.instance);

  if (frame.lastInstance!=this.instance && frame.lastInstance!=-1) { frame.yxI[frame.lastInstance].hideInstance(); }

  if (this.active && instance.holder.css.zIndex<frame.lastIndex) { instance.holder.css.zIndex=++frame.lastIndex; }

  frame.lastInstance=this.instance;

  if (this.focused) {
    if (this.type==flagMenu || this.type==flagImageMenu) { blurIt(this.menu.items); }
  }
  else {
    blurIt(this.peer);
  }

  if (this.type!=flagSeparator && this.type!=flagInfo) {
    this.turnColor(true);
    window.status=this.help;
  }

  if (this.type==flagMenu || this.type==flagImageMenu) { this.menu.showMenu(this.dy); }
}

function overPad() {
  var frame=this.frame,instance=frame.yxI[this.instance];

  frame.clearTimer(this.instance);

  if (frame.lastInstance!=this.instance && frame.lastInstance!=-1) { frame.yxI[frame.lastInstance].hideInstance(); }

  if (this.active && instance.holder.css.zIndex<frame.lastIndex) { instance.holder.css.zIndex=++frame.lastIndex; }

  frame.lastInstance=this.instance;
}

function outIt() { this.frame._hideInstance(this.instance); }

// ------
function initGroup(_group) {
  checkBrowser();

  if (isIE4 || isNN4) {
    setParameter();

    yxGroup=getArray(_group);
    if (yxGroup) {
      setTimeout("_initGroup()",50);
    }
    else {
      showError("Menu Group Not Found: ["+_group+"]");
    }
  }
  else {
    showError("Sorry,you are not using IE4+ or NN4+");
  }
}

function addStyle_(_frame,_styleName,_paddingWidth,_paddingHeight,_spacing,_spacingColor,_colorNormal,_colorHighlighted,_border,_borderColorBright,_borderColorDark,_textFont,_textSize,_textWeight,_textDecoration,_textColor,_tag,_tagWidth,_tagHeight,_tagImage,_imagePath,_widthRatio) {
  _frame.yxS[_frame.sCount++]=new _styleOBJ(_styleName,_paddingWidth,_paddingHeight,_spacing,_spacingColor,_colorNormal,_colorHighlighted,_border,_borderColorBright,_borderColorDark,_textFont,_textSize,_textWeight,_textDecoration,_textColor,_tag,_tagWidth,_tagHeight,_tagImage,_imagePath,_widthRatio);
}

function addInstance_(_frame,_name,_type,_position,_holder,_x,_y,_direction,_form,_initial,_target,_group,_style1,_style2) {
  if (groupReady && _frame.instanceValid) {
    showMessage("Adding menu instance: ["+_name+"]");

    var iIndex=_frame.iCount++;
    _frame.yxI[iIndex]=new instanceOBJ(_frame,iIndex,_name,_type,_position,_holder,_x,_y,_direction,_form,_initial,_target,_group,_style1,_style2);

    if (_frame.yxI[iIndex].group!=null) {
      _frame.yxI[iIndex].makeInstance();
      if (_frame.yxI[iIndex].initial) { _frame.yxI[iIndex].showInstance(); }

      if (_frame.yxI[iIndex].type==1 && !_frame.mapRegistered) {
        _frame.mapRegistered=true;
        _frame.yxI[iIndex].registerMap();
      }
      else if (_frame.yxI[iIndex].type==2 && !_frame.popRegistered) {
        _frame.popRegistered=true;
        _frame.yxI[iIndex].registerPop();
      }
      else if (_frame.yxI[iIndex].type==3) {
        _frame.yxI[iIndex].checkInstance();
      }

      showMessage("Added menu instance: ["+_name+"]");
    }
    else {
      _frame.instanceValid=false;
      showError("Menu Group Not Found: ["+_group+"] for Instance ["+_name+"]");
    }
  }
}

function addFrame_(_name,_frame) {
  if (!holdIt) {
    holdIt=true;

    for (var i=0; i<fCount; i++) {
      if (yxF[i].name==_name) {
        yxF[i].frame=_frame;
        holdIt=false;
        return true;
      }
    }

    yxF[fCount++]=new frameOBJ(_name,_frame);
    holdIt=false;
    return true;
  }
  else {
    return false;
  }
}

function delFrame(_frame) {
  for (var i=0; i<fCount; i++) {
    if (yxF[i].frame==_frame) { yxF[i].frame=null; break; }
  }
}

function openMap_(_fName,_iName) {
  var frame=getFrame(_fName);
  if (frame!=null) {
    if (frame.instanceReady) { return frame._openMap(_iName); }
  }
  return false;
}

function openMenu_(_fName,_iName) {
  var frame=getFrame(_fName);
  if (frame!=null) {
    if (frame.instanceReady) { return frame._openMenu(_iName); }
  }
  return false;
}

function closeMenu_(_fName,_iName) {
  var frame=getFrame(_fName);
  if (frame!=null) {
    if (frame.instanceReady) { return frame._closeMenu(_iName); }
  }
  return false;
}

function closeMenuNow_(_fName,_iName) {
  var frame=getFrame(_fName);
  if (frame!=null) {
    if (frame.instanceReady) { return frame._closeMenuNow(_iName); }
  }
  return false;
}

function switchMenu_(_fName,_iName) {
  var frame=getFrame(_fName);
  if (frame!=null) {
    if (frame.instanceReady) { return frame._switchMenu(_iName); }
  }
  return false;
}

function moveMenuTo_(_fName,_iName,_x,_y) {
  var frame=getFrame(_fName);
  if (frame!=null) {
    if (frame.instanceReady) { return frame._moveMenuTo(_iName,_x,_y); }
  }
  return false;
}

function moveMenuBy_(_fName,_iName,_x,_y) {
  var frame=getFrame(_fName);
  if (frame!=null) {
    if (frame.instanceReady) { return frame._moveMenuBy(_iName,_x,_y); }
  }
  return false;
}

function getMenuDim_(_fName,_iName) {
  var frame=getFrame(_fName);
  if (frame!=null) {
    if (frame.instanceReady) { return frame._getMenuDim(_iName); }
  }
  return null;
}

function getItemDim_(_fName,_iName,_iIndex) {
  var frame=getFrame(_fName);
  if (frame!=null) {
    if (frame.instanceReady) { return frame._getItemDim(_iName,_iIndex); }
  }
  return null;
}
