// +------------------------------------------------------------+
// | yx_menu G2 (frame)              Full Version               |
// | Created 12/12/1999              Last Modified 03/07/2000   |
// | Web Site:                       http://yx.webprovider.com  |
// | eMail:                          yangxin@iname.com          |
// +------------------------------------------------------------+
// | Copyright 2000  Xin Yang        All Rights Reserved.       |
// +------------------------------------------------------------+
// | For personal purpose, send me your URL and put a link back |
// | to my web site, then you can use this script free.         |
// |                                                            |
// | For commercial purpose, obtain quotation for referencing,  |
// | using, hosting, selling or distributing this script.       |
// |                                                            |
// | In all cases copyright must remain intact.                 |
// +------------------------------------------------------------+

var _isIE4=false,_isNN4=false,_menuTimer=0,_menuOffset=0,frameOffset=0;
var popInstance=-1,popRegistered=false,mapRegistered=false,mapX=0,mapY=0;
var instanceValid=true,instanceReady=false;
var frameWidth=0,frameHeight=0,halfWidth=0,halfHeight=0,contentWidth=0,contentHeight=0,scrollBar=0;
var lastInstance=-1,lastIndex=1,holdOn=false;
var yxI=new Array(),iCount=0,yxS=new Array(),sCount=0;

function getInstance(_name) {
  for (var i=0; i<iCount; i++) {
    if (yxI[i].name==_name) { return i; break; }
  }

  return -1;
}

function newWin(url) {
 mywin = window.open(url,'','statusbar=yes,scrollbars=yes,resizable=yes,maximize=yes'); 
}


function setDIM() {
  if (_isNN4) {
    frameWidth=window.innerWidth; frameHeight=window.innerHeight;
    contentWidth=(frameHeight<window.document.height-frameOffset)?(frameWidth-scrollBar+frameOffset):(frameWidth+frameOffset);
    contentHeight=(frameWidth<window.document.width-frameOffset)?(frameHeight-scrollBar+frameOffset):(frameHeight+frameOffset);
  }
  else {
    contentWidth=window.document.body.clientWidth; contentHeight=window.document.body.clientHeight;
  }

  halfWidth=Math.ceil(contentWidth/2); halfHeight=Math.ceil(contentHeight/2);
}

function resizeFrame() {
  if (_isNN4) {
    if (window.innerWidth!=frameWidth || window.innerHeight!=frameHeight) { document.location.reload(); }
  }
  else {
    var oldWidth=contentWidth,oldHeight=contentHeight;
    setDIM();
    var dx=contentWidth-oldWidth,dy=contentHeight-oldHeight;

    if (dx!=0 || dy!=0) {
      for (var i=0; i<iCount; i++) {
        if ((yxI[i].position==1 || yxI[i].position==2 || yxI[i].position==3 || yxI[i].position==4 || yxI[i].position==5 || yxI[i].position==8) && dx!=0) { yxI[i].holder.xx+=dx; }
        if ((yxI[i].position==3 || yxI[i].position==4 || yxI[i].position==5 || yxI[i].position==6 || yxI[i].position==7 || yxI[i].position==8) && dy!=0) { yxI[i].holder.yy+=dy; }

        yxI[i].moveInstanceTo(yxI[i].holder.xx,yxI[i].holder.yy);
      }
    }
  }
}

function popMenu(e) {
  if (!holdOn) {
    holdOn=true;

    var menuX=0,menuY=0;
    if (_isIE4) {
      menuX=event.clientX+window.document.body.scrollLeft; menuY=event.clientY+window.document.body.scrollTop;
    }
    else {
      menuX=e.pageX; menuY=e.pageY;
    }

    for (var i=0; i<iCount; i++) {
      if (i==popInstance) {
        menuX+=(yxI[i].direction==0 || yxI[i].direction==3)?-_menuOffset:_menuOffset;
        menuY+=(yxI[i].direction==0 || yxI[i].direction==1)?-_menuOffset:_menuOffset;

        yxI[i].moveInstanceTo(menuX,menuY);
        yxI[i].showInstance();
      }
      else {
        yxI[i].hideInstance();
      }
    }

    holdOn=false;
  }

  return false;
}

function mapMenu(e) {
  if (_isIE4) {
    mapX=event.clientX+window.document.body.scrollLeft; mapY=event.clientY+window.document.body.scrollTop;
  }
  else {
    mapX=e.pageX; mapY=e.pageY;
  }

  return true;
}

function _hideInstance(_instance) { yxI[_instance].timer=eval('setTimeout("yxI['+_instance+'].hideInstance()",'+_menuTimer+')'); }
function clearTimer(_instance) { clearTimeout(yxI[_instance].timer); }

function _checkInstance(_instance) {
  var holder=yxI[_instance].holder;

  if (_isIE4) {
    holder.style.pixelLeft=holder.xx+window.document.body.scrollLeft;
    holder.style.pixelTop=holder.yy+window.document.body.scrollTop;
  }
  else {
    holder.moveTo(holder.xx+window.pageXOffset,holder.yy+window.pageYOffset);
  }

  eval('setTimeout("_checkInstance('+_instance+')",'+_menuTimer+')');
}

function _registerPop(_instance) {
  popInstance=_instance;

  if (_isIE4) {
    window.document.ondblclick=popMenu;
  }
  else {
    window.document.onDblClick=popMenu;
    window.document.captureEvents(Event.DBLCLICK);
  }
}

function _registerMap() {
  if (_isIE4) {
    window.document.onclick=mapMenu;
  }
  else {
    window.document.onClick=mapMenu;
    window.document.captureEvents(Event.CLICK);
  }
}

function _initMenu(_scrollBar) {
  _isIE4=top.isIE4; _isNN4=top.isNN4;
  _menuTimer=top.menuTimer; _menuOffset=top.menuOffset;

  if (self!=top) { frameOffset=2; }

  scrollBar=(_scrollBar==0)?0:20;
  setDIM();

  buildMenu();

  if (instanceValid) {
    instanceReady=true;

    window.onresize=resizeFrame;

    top.showMessage("Menu activated");
  }
}

function _openMap(_name) {
  if (!holdOn && instanceReady) {
    holdOn=true;

    for (var i=0; i<iCount; i++) {
      if (yxI[i].name==_name) {
        mapX+=((yxI[i].direction==0 || yxI[i].direction==3)?-_menuOffset:_menuOffset);
        mapY+=((yxI[i].direction==0 || yxI[i].direction==1)?-_menuOffset:_menuOffset);

        yxI[i].moveInstanceTo(mapX,mapY);
        yxI[i].showInstance();
      }
      else {
        yxI[i].hideInstance();
      }
    }

    holdOn=false;
  }
}

function _openMenu(_name) {
  if (!holdOn && instanceReady) {
    holdOn=true;

    for (var i=0; i<iCount; i++) {
      if (yxI[i].name==_name) {
        yxI[i].showInstance();
      }
      else {
        yxI[i].hideInstance();
      }
    }

    holdOn=false;
  }
}

function _closeMenu(_name) {
  if (!holdOn && instanceReady) {
    holdOn=true;

    var iIndex=getInstance(_name);
    if (iIndex!=-1) {
      if (yxI[iIndex].shown) { _hideInstance(iIndex); }
    }

    holdOn=false;
  }
}

function _closeMenuNow(_name) {
  if (!holdOn && instanceReady) {
    holdOn=true;

    var iIndex=getInstance(_name);
    if (iIndex!=-1) {
      if (yxI[iIndex].shown) { yxI[iIndex].hideInstance(); }
    }

    holdOn=false;
  }
}

function _switchMenu(_name) {
  if (!holdOn && instanceReady) {
    holdOn=true;

    for (var i=0; i<iCount; i++) {
      if (yxI[i].name==_name) {
        if (yxI[i].shown) {
          yxI[i].hideInstance();
        }
        else {
          yxI[i].showInstance();
        }
      }
      else {
        yxI[i].hideInstance();
      }
    }

    holdOn=false;
  }
}

function _moveMenuTo(_name,_x,_y) {
  if (instanceReady) {
    var iIndex=getInstance(_name);
    if (iIndex!=-1) { yxI[iIndex].moveInstanceTo(_x,_y); }
  }
}

function _moveMenuBy(_name,_x,_y) {
  if (instanceReady) {
    var iIndex=getInstance(_name);
    if (iIndex!=-1) { yxI[iIndex].moveInstanceBy(_x,_y); }
  }
}

function initMenu(_scrollBar) {
  if (top.groupReady) {
    _initMenu(_scrollBar);
  }
  else {
    eval('setTimeout("initMenu('+_scrollBar+')",200)');
  }
}

function addStyle(_styleName,_paddingWidth,_paddingHeight,_spacing,_spacingColor,_colorNormal,_colorHighlighted,_border,_borderColorBright,_borderColorDark,_textFont,_textSize,_textWeight,_textDecoration,_textColor,_tag,_tagWidth,_tagHeight,_tagImage,_imagePath,_widthRatio) {
  top.addStyle_(self,_styleName,_paddingWidth,_paddingHeight,_spacing,_spacingColor,_colorNormal,_colorHighlighted,_border,_borderColorBright,_borderColorDark,_textFont,_textSize,_textWeight,_textDecoration,_textColor,_tag,_tagWidth,_tagHeight,_tagImage,_imagePath,_widthRatio);
}

function addInstance(_name,_type,_position,_holder,_x,_y,_direction,_form,_initial,_target,_group,_style1,_style2) {
  top.addInstance_(self,_name,_type,_position,_holder,_x,_y,_direction,_form,_initial,_target,_group,_style1,_style2);
}

function addFrame(_name) { if (!top.addFrame_(_name,self)) { eval('setTimeout("addFrame('+_name+')",200)'); } }

function openMap(_fName,_iName) { top.openMap_(_fName,_iName); }
function openMenu(_fName,_iName) { top.openMenu_(_fName,_iName); }
function closeMenu(_fName,_iName) { top.closeMenu_(_fName,_iName); }
function closeMenuNow(_fName,_iName) { top.closeMenuNow_(_fName,_iName); }
function switchMenu(_fName,_iName) { top.switchMenu_(_fName,_iName); }
function moveMenuTo(_fName,_iName,_x,_y) { top.moveMenuTo_(_fName,_iName,_x,_y); }
function moveMenuBy(_fName,_iName,_x,_y) { top.moveMenuBy_(_fName,_iName,_x,_y); }

//function updateurl() {
// top.mainFrame.location="http://englishnet.homeip.net/index.html";
//}



