var NS = (document.layers) ? 1 : 0;
var IE = (document.all) ? 1 : 0;
var IE5 = (IE && navigator.appVersion.indexOf("5.")  >= 0) ? 1 : 0;
var IE55 = (IE && navigator.appVersion.indexOf("5.5") >= 0) ? 1 : 0;
var IE6 = (IE && navigator.appVersion.indexOf("6.") >= 0) ? 1 : 0;

function hideLayer(layer) 
{
  if (NS) layer.visibility = "hide";
  else layer.style.visibility = "hidden";
}

function showLayer(layer) 
{
  if (NS) layer.visibility = "show";
  else layer.style.visibility = "visible";
}

function inheritLayer(layer) 
{
  if (NS) layer.visibility = "inherit";
  else layer.style.visibility = "inherit";
}

function getVisibility(layer) 
{
  if (NS) {
    if (layer.visibility == "show") return "visible";
    if (layer.visibility == "hide") return "hidden";
  }
  return layer.style.visibility;
}

function moveLayerTo(layer, x, y) 
{
  if (NS) layer.moveTo(x, y);
  else {
    layer.style.left = x;
    layer.style.top  = y;
  }
}

function moveLayerBy(layer, dx, dy) 
{
  if (NS) layer.moveBy(dx, dy);
  else {
    layer.style.pixelLeft += dx;
    layer.style.pixelTop  += dy;
  }
}

function getLeft(layer) 
{
  if (NS) return layer.left;
  return layer.style.pixelLeft;
}

function getTop(layer) 
{
  if (NS) return layer.top;
  return layer.style.pixelTop;
}

function getRight(layer) 
{
  if (NS) return layer.left + getWidth(layer);
  return layer.style.pixelLeft + getWidth(layer);
}

function getBottom(layer) 
{
  if (NS) return layer.top + getHeight(layer);
  return layer.style.pixelTop + getHeight(layer);
}

function getPageLeft(layer) 
{
  var x;
  if (NS) return layer.pageX;
  x = 0;
  while (layer.offsetParent != null) {
    x += layer.offsetLeft;
    layer = layer.offsetParent;
  }
  x += layer.offsetLeft;
  return x;
}

function getPageTop(layer) 
{
  var y;
  if (NS) return layer.pageY;
  y = 0;
  while (layer.offsetParent != null) {
    y += layer.offsetTop;
    layer = layer.offsetParent;
  }
  y += layer.offsetTop;
  return y;
}

function getWidth(layer) 
{
  if (NS) {
    if (layer.document.width) return layer.document.width;
    else return layer.clip.right - layer.clip.left;
  }
  if (layer.style.pixelWidth) return layer.style.pixelWidth;
  else return layer.clientWidth;
}

function getHeight(layer) 
{
  if (NS) {
    if (layer.document.height) return layer.document.height;
    else return layer.clip.bottom - layer.clip.top;
  }
  if (layer.style.pixelHeight) return layer.style.pixelHeight;
  else return layer.clientHeight;
}

function getzIndex(layer) 
{
  if (NS) return layer.zIndex;
  return layer.style.zIndex;
}

function setzIndex(layer, z) 
{
  if (NS) layer.zIndex = z;
  else layer.style.zIndex = z;
}

function clipLayer(layer, clipleft, cliptop, clipright, clipbottom) 
{
  if (NS) {
    layer.clip.left   = clipleft;
    layer.clip.top    = cliptop;
    layer.clip.right  = clipright;
    layer.clip.bottom = clipbottom;
  } else layer.style.clip = 'rect(' + cliptop + ' ' +  clipright + ' ' + clipbottom + ' ' + clipleft +')';
}

function getClipLeft(layer) 
{
  if (NS) return layer.clip.left;
  var str = layer.style.clip;
  if (!str) return 0;
  var clip = getIEClipValues(layer.style.clip);
  return(clip[3]);
}

function getClipTop(layer) 
{
  if (NS) return layer.clip.top;
  var str = layer.style.clip;
  if (!str) return 0;
  var clip = getIEClipValues(layer.style.clip);
  return clip[0];
}

function getClipRight(layer)
{
  if (NS) return layer.clip.right;
  var str = layer.style.clip;
  if (!str) return layer.style.pixelWidth;
  var clip = getIEClipValues(layer.style.clip);
  return clip[1];
}

function getClipBottom(layer)
{
  if (NS) return layer.clip.bottom;
  var str = layer.style.clip;
  if (!str) return layer.style.pixelHeight;
  var clip = getIEClipValues(layer.style.clip);
  return clip[2];
}

function getClipWidth(layer) {
  if (NS) return layer.clip.width;
  var str = layer.style.clip;
  if (!str) return layer.style.pixelWidth;
  var clip = getIEClipValues(layer.style.clip);
  return clip[1] - clip[3];
}

function getClipHeight(layer) {
  if (NS) return layer.clip.height;
  var str = layer.style.clip;
  if (!str) return layer.style.pixelHeight;
  var clip = getIEClipValues(layer.style.clip);
  return clip[2] - clip[0];
}

function getIEClipValues(str) {
  var clip = new Array();
  var i;
  i = str.indexOf("(");
  clip[0] = parseInt(str.substring(i + 1, str.length), 10);
  i = str.indexOf(" ", i + 1);
  clip[1] = parseInt(str.substring(i + 1, str.length), 10);
  i = str.indexOf(" ", i + 1);
  clip[2] = parseInt(str.substring(i + 1, str.length), 10);
  i = str.indexOf(" ", i + 1);
  clip[3] = parseInt(str.substring(i + 1, str.length), 10);
  return clip;
}

function scrollLayerTo(layer, x, y, bound) {
  var dx = getClipLeft(layer) - x;
  var dy = getClipTop(layer) - y;
  scrollLayerBy(layer, -dx, -dy, bound);
}

function scrollLayerBy(layer, dx, dy, bound) {
  var cl = getClipLeft(layer);
  var ct = getClipTop(layer);
  var cr = getClipRight(layer);
  var cb = getClipBottom(layer);
  if (bound) {
    if (cl + dx < 0) dx = -cl;
    else if (cr + dx > getWidth(layer)) dx = getWidth(layer) - cr;
    if (ct + dy < 0) dy = -ct;
    else if (cb + dy > getHeight(layer)) dy = getHeight(layer) - cb;
  }
  clipLayer(layer, cl + dx, ct + dy, cr + dx, cb + dy);
  moveLayerBy(layer, -dx, -dy);
}

function setBgColor(layer, color,opt) 
{
  if (opt == 1)
  {
     if (NS) 
        layer.bgColor = color;
     else 
        layer.style.backgroundColor = color;
  }
}

function setBgImage(layer, src) {
  if (NS) layer.background.src = src;
  else layer.style.backgroundImage = "url(" + src + ")";
}

function getLayer(name) {
  if (NS) return findLayer(name, document);
  return eval('document.all.' + name);
}

function findLayer(name, doc) {
  var i, layer;
  for (i = 0; i < doc.layers.length; i++) {
    layer = doc.layers[i];
    if (layer.name == name) return layer;
    if (layer.document.layers.length > 0)
      if ((layer = findLayer(name, layer.document)) != null)
        return layer;
  }
  return null;
}

function getImage(name) {
  if (NS) return findImage(name, document);
  return eval('document.all.' + name);
}

function findImage(name, doc) {
  var i, img;
  for (i = 0; i < doc.images.length; i++)
    if (doc.images[i].name == name) return doc.images[i];
  for (i = 0; i < doc.layers.length; i++)
    if ((img = findImage(name, doc.layers[i].document)) != null) {
      img.container = doc.layers[i];
      return img;
    }
  return null;
}

function getImagePageLeft(img) {
  var x, obj;
  if (NS) {
    if (img.container != null) return img.container.pageX + img.x;
    else return img.x;
  }
  x = 0;
  obj = img;
  while (obj.offsetParent != null) {
    x += obj.offsetLeft;
    obj = obj.offsetParent;
  }
  x += obj.offsetLeft;
  return x;
}

function getImagePageTop(img) {
  var y, obj;
  if (NS) {
    if (img.container != null) return img.container.pageY + img.y;
    else return img.y;
  }
  y = 0;
  obj = img;
  while (obj.offsetParent != null) {
    y += obj.offsetTop;
    obj = obj.offsetParent;
  }
  y += obj.offsetTop;
  return y;
}
function getWindowWidth() {
  if (NS) return window.innerWidth;
  return document.body.clientWidth;
}
function getWindowHeight() {
  if (NS) return window.innerHeight;
  return document.body.clientHeight;
}
function getPageWidth() {
  if (NS) return document.width;
  return document.body.scrollWidth;
}
function getPageHeight() {
  if (NS) return document.height;
  return document.body.scrollHeight;
}
function getPageScrollX() {
  if (NS) return window.pageXOffset;
  return document.body.scrollLeft;
}
function getPageScrollY() {
  if (NS) return window.pageYOffset;
  return document.body.scrollTop;
}

// bug with IE 5.5.
var F_ITEMs = new Array();
function ITEM(text,link,text2) 
{  
  this.text = text;
  this.link = link;
  //當item項目增加時,此處也要新增
  this.text2 = text2;
}

function ECSmenu(hdrWidth, menuWidth) 
{
  this.hdrWidth = hdrWidth;
  this.width = menuWidth;  
  this.height = 0;
  this.items = new Array();
  this.addItem = ECSmenuaddItem;
}
function ECSmenuaddItem(item)
{    
   this.items[this.items.length] = item; 
}

function F_ITEM(width) 
{
  this.x = 178;   //menu left pos
  this.y = 92;    //menu top pos
  this.width = width;
  this.height = 0;
  this.align = "left";
  this.minWidth = 0;
  this.inverted = false;
  this.menus = new Array();
  this.created = false;
  this.addNAVm = F_ITEMaddNAVm;
  this.create = F_ITEMCreate;
  this.moveTo = F_ITEMMoveTo;
  this.moveBy = F_ITEMMoveBy;
  this.getzIndex = F_ITEMGetzIndex;
  this.setzIndex = F_ITEMSetzIndex;
  this.getWidth = F_ITEMGetWidth;
  this.getMinWidth = F_ITEMGetMinWidth;
  this.getAlign = F_ITEMGetAlign;
  this.resize = F_ITEMResize;
  this.invert = F_ITEMInvert;
  this.isInverted = F_ITEMIsInverted;
  this.index = F_ITEMs.length;
  F_ITEMs[this.index] = this;
}

function F_ITEMaddNAVm(menu) 
{ 
   if (!this.created) this.menus[this.menus.length] = menu;    
}

function F_ITEMCreate() 
{  
  var str;
  var i, j;
  var norm, high, end;
  var width, height;
  var x, y;
  var scrX, scrY;
  
  if (this.created) return;  
  str = "";
  
  if (!NS && !IE5) 
  {
    scrX = getPageScrollX();
    scrY = getPageScrollY();
    window.scrollTo(getPageWidth(), getPageHeight());
  }
  
  if (NS) 
  {
    str += '<layer name="F_ITEM' + this.index + '_filler"></layer>\n'
    +  '<layer name="F_ITEM' + this.index + '_hdrsBase">\n';
  }
  else 
  {
    str += '<div id="F_ITEM' + this.index + '_filler" style="position:absolute;"></div>\n'
    +  '<div id="F_ITEM' + this.index + '_hdrsBase" style="position:absolute;">\n';
  }  
  
  for (i = 0; i < this.menus.length; i++) 
  {
    norm = '<table border=0 cellpadding=0 cellspacing=0'
    + (this.menus[i].hdrWidth > 0 ? ' width=' + this.menus[i].hdrWidth : '')
    + ((!NS && !IE5) ? ' id="F_ITEM' + this.index + '_tbl' + i + '"': '')
    + '><tr><td'
    + (this.menus[i].hdrWidth == 0 ? ' nowrap=1' + this.menus[i].hdrWidth : '')
    + '>'    
    high = '<table border=0 cellpadding=0 cellspacing=0'
    + (this.menus[i].hdrWidth > 0 ? ' width=' + this.menus[i].hdrWidth : '')
    + '><tr><td'
    + (this.menus[i].hdrWidth == 0 ? ' nowrap=1' + this.menus[i].hdrWidth : '')
    + '>'    
    end  = '</td></tr></table>';
    
    if (NS)
      str += '<layer name="F_ITEM' + this.index + '_head' + i + '">'
      + norm + this.menus[i].items[0].text + end
      + '</layer>\n'
      + '<layer name="F_ITEM' + this.index + '_headHigh' + i + '">'
      + high + this.menus[i].items[0].text + end
      + '</layer>\n'
      + '<layer name="F_ITEM' + this.index + '_headDummy' + i + '">'
      + '</layer>\n';
    else 
    {
      str += '<div id="F_ITEM' + this.index + '_head' + i + '"'
      + ' style="position:absolute;">'
      + norm + this.menus[i].items[0].text + end
      + '</div>\n'
      //變換menu第一層圖片位置
      + '<div id="F_ITEM' + this.index + '_headHigh' + i + '"'
      + ' style="position:absolute;">'      
      + high + this.menus[i].items[0].text2 + end
      + '</div>\n'
      //對第一層圖片加上style位置
      + '<div id="F_ITEM' + this.index + '_headDummy' + i + '"'
      + ' style="position:absolute;">';
      if (IE55 || IE6)
        str += '<table border=0 cellspacing=0 cellpadding=0 width="100%" height="100%"><tr><td>&nbsp;</td></tr></table>';
      str += '</div>\n';
    }
  }
  
  if (NS) 
  {
    str += '</layer>\n';
    this.baseLayer = new Layer(this.width);
    this.baseLayer.document.open();
    this.baseLayer.document.write(str);
    this.baseLayer.document.close();
  }
  else
  {
    str += '</div>\n';
    str = '<div id="F_ITEM' + this.index + '"'
    + ' style="position:absolute;left:0px;top:0px;">\n'
    + str + '</div>\n';    
    document.body.insertAdjacentHTML("beforeEnd", str);
    this.baseLayer = getLayer("F_ITEM" + this.index);
  }
  
  width = 0;
  height = 0;
  for (i = 0; i < this.menus.length; i++) 
  {
    this.menus[i].hdrNormLayer = getLayer('F_ITEM' + this.index + '_head' + i);
    this.menus[i].hdrHighLayer = getLayer('F_ITEM' + this.index + '_headHigh' + i);
    this.menus[i].hdrDmmyLayer = getLayer('F_ITEM' + this.index + '_headDummy' + i);
    height = Math.max(height, getHeight(this.menus[i].hdrNormLayer));
    this.height = height + 2;
    
    if (!NS && !IE5) 
    {
      width = this.menus[i].hdrWidth;
      if (width == 0)
      width = eval('document.all.F_ITEM' + this.index + '_tbl' + i + '.clientWidth');
      F_ITEMIEResizeLayer(this.menus[i].hdrNormLayer, width, height);
      F_ITEMIEResizeLayer(this.menus[i].hdrHighLayer, width, height);
      F_ITEMIEResizeLayer(this.menus[i].hdrDmmyLayer, width, height);
    }
  }
  
  x = 1;
  y = 1;
  
  for (i = 0; i < this.menus.length; i++) 
  {
    width = Math.max(this.menus[i].hdrWidth, getWidth(this.menus[i].hdrNormLayer));
    if (this.menus[i].width == 0) 
      this.menus[i].width = width + 2;
    
    moveLayerTo(this.menus[i].hdrNormLayer, x, y);
    setBgColor(this.menus[i].hdrNormLayer, "Silver",0);    
    clipLayer(this.menus[i].hdrNormLayer, 0, 0, width, height);
    inheritLayer(this.menus[i].hdrNormLayer);
    moveLayerTo(this.menus[i].hdrHighLayer, x, y);
    setBgColor(this.menus[i].hdrHighLayer, "Navy",0);    
    clipLayer(this.menus[i].hdrHighLayer, 0, 0, width, height);
    hideLayer(this.menus[i].hdrHighLayer);
    moveLayerTo(this.menus[i].hdrDmmyLayer, x, y);
    
    if (!NS) F_ITEMIEResizeLayer(this.menus[i].hdrDmmyLayer, width, height);
    
    clipLayer(this.menus[i].hdrDmmyLayer, 0, 0, width, height);
    inheritLayer(this.menus[i].hdrDmmyLayer);
    this.menus[i].hdrDmmyLayer.highLayer = this.menus[i].hdrHighLayer;
    this.menus[i].hdrLeft = x;
    x += width + 1;
    this.menus[i].hdrRight = x;
  }
  
  this.minWidth = x;
  this.width = Math.max(this.minWidth, this.width);
  moveLayerTo(this.baseLayer, this.x, this.y);
  setBgColor(this.baseLayer, "Gray",0);  
  
  if (!NS) F_ITEMIEResizeLayer(this.baseLayer, this.width, this.height);
  
  clipLayer(this.baseLayer, 0, 0, this.width, this.height);
  this.fillerLayer = getLayer('F_ITEM' + this.index + '_filler');
  moveLayerTo(this.fillerLayer, 1, 1);
  setBgColor(this.fillerLayer, "Silver",0);  
  width = this.width - 2;
  height = this.height - 2;
  
  if (!NS) F_ITEMIEResizeLayer(this.fillerLayer, width, height);
  
  clipLayer(this.fillerLayer, 0, 0, width, height);
  inheritLayer(this.fillerLayer);
  this.hdrsBaseLayer = getLayer('F_ITEM' + this.index + '_hdrsBase');
  if (this.align == "left") this.hdrsOffsetX = 0;
  else if (this.align == "center") this.hdrsOffsetX = Math.round((this.width - this.minWidth) / 2);
  else if (this.align == "right") this.hdrsOffsetX = this.width - this.minWidth;
  else this.hdrsOffsetX = Math.min(parseInt(this.align, 10), this.width - this.minWidth);
  moveLayerTo(this.hdrsBaseLayer, this.hdrsOffsetX, 0);
  //Albert 底色修改
  setBgColor(this.hdrsBaseLayer, "Gray",0);
  
  if (!NS) F_ITEMIEResizeLayer(this.hdrsBaseLayer, this.minWidth, this.height);
  
  clipLayer(this.hdrsBaseLayer, 0, 0, this.minWidth, this.height);
  inheritLayer(this.hdrsBaseLayer);
  
  for (i = 0; i < this.menus.length; i++) 
  {
    this.menus[i].hdrDmmyLayer.index = this.index;
    this.menus[i].hdrDmmyLayer.offsetX = this.menus[i].hdrLeft - 1;
    
    if (this.menus[i].hdrDmmyLayer.offsetX + this.menus[i].width > this.width)
      this.menus[i].hdrDmmyLayer.offsetX = this.menus[i].hdrRight - this.menus[i].width;
      
    this.menus[i].hdrDmmyLayer.offsetY = this.height - 1;
    this.menus[i].hdrDmmyLayer.onmouseover = F_ITEMHeaderOn;
    this.menus[i].hdrDmmyLayer.onmouseout = F_ITEMHeaderOff;
    
    if (NS) 
    {
      this.menus[i].hdrDmmyLayer.document.highLayer = this.menus[i].hdrHighLayer;
      this.menus[i].hdrDmmyLayer.document.link = this.menus[i].items[0].link;
      this.menus[i].hdrDmmyLayer.document.captureEvents(Event.MOUSEUP);
      this.menus[i].hdrDmmyLayer.document.onmouseup = F_ITEMItemClick;
    }
    else
    {
      this.menus[i].hdrDmmyLayer.highLayer = this.menus[i].hdrHighLayer;
      this.menus[i].hdrDmmyLayer.link = this.menus[i].items[0].link;
      this.menus[i].hdrDmmyLayer.onclick = F_ITEMItemClick;
    }
  }
  
  //第二層
  norm = '<table border=0 cellpadding=3 cellspacing=0 width="100%"><tr><td>'
  + '<span style="color:Black; font-size:9pt; font-weight:normal;">';
  high = '<table border=0 cellpadding=3 cellspacing=0 width="100%"><tr><td>'
  + '<span style="color:White; font-size:9pt; font-weight:normal;">';  
  end  = '</span></td></tr></table>';
  
  for (i = 0; i < this.menus.length; i++) 
  {
    width = this.menus[i].width - 2;
    str = "";
    for (j = 1; j < this.menus[i].items.length; j++) 
    {
      if (NS)
        str += '<layer name="F_ITEM' + this.index + '_menu' + i + '_norm' + j + '"'
        + ' width=' + width + '>'
        + norm + this.menus[i].items[j].text + end + '</layer>\n'
        + '<layer name="F_ITEM' + this.index + '_menu' + i + '_high' + j + '"'
        + ' width=' + width + '>'
        + high + this.menus[i].items[j].text + end + '</layer>\n'
        + '<layer name="F_ITEM' + this.index + '_menu' + i + '_dmmy' + j + '"'
        + ' width=' + width + '>' + '</layer>\n';
      else 
      {
        str += '<div id="F_ITEM' + this.index + '_menu' + i + '_norm' + j + '"'
        + ' style="position:absolute;width:' + width + 'px;">'
        + norm + this.menus[i].items[j].text + end + '</div>\n'
        + '<div id="F_ITEM' + this.index + '_menu' + i + '_high' + j + '"'
        + ' style="position:absolute;width:' + width + 'px;">'
        + high + this.menus[i].items[j].text + end + '</div>\n'
        + '<div id="F_ITEM' + this.index + '_menu' + i + '_dmmy' + j + '"'
        + ' style="position:absolute;width:' + width + 'px;';
        
        if (this.menus[i].items[j].link == "")
           str = str + '">';
        else
           str = str + 'cursor:hand;">';
        
        if (IE55 || IE6)
          str += '<table border=0 cellspacing=0 width="100%" height="100%"><tr><td>&nbsp;</td></tr></table>';
        str += '</div>\n';
      }
    }
    if (NS) 
    {
      this.menus[i].baseLayer = new Layer(this.menus[i].width);
      this.menus[i].baseLayer.document.open();
      this.menus[i].baseLayer.document.write(str);
      this.menus[i].baseLayer.document.close();
    }
    else 
    {
      str = '<div id="F_ITEM' + this.index + '_menu' + i + '"'
      + ' style="position:absolute;left:0px; top:0px;'
      + 'width:' + this.menus[i].width + 'px;visibility:hidden;">\n'
      + str + '</div>\n';
      document.body.insertAdjacentHTML("beforeEnd", str);
      this.menus[i].baseLayer = getLayer("F_ITEM" + this.index + "_menu" + i);
    }
  }
  if (!NS && !IE5) window.scrollTo(x, y);
  
  for (i = 0; i < this.menus.length; i++)   
  {
    moveLayerTo(this.menus[i].baseLayer, this.menus[i].hdrDmmyLayer.offsetX, this.menus[i].hdrDmmyLayer.offsetY);
    //menu第二層底色
    setBgColor(this.menus[i].baseLayer, "#FFFFFF",1);
    
    if (this.menus[i].items.length > 1) 
    {
      this.menus[i].hdrDmmyLayer.menuLayer = this.menus[i].baseLayer;
      if (NS) this.menus[i].hdrDmmyLayer.document.menuLayer = this.menus[i].baseLayer;
    }
    else 
    {
      this.menus[i].hdrDmmyLayer.menuLayer = null;
      if (NS) this.menus[i].hdrDmmyLayer.document.menuLayer = this.menus[i].baseLayer;
    }
    
    x = 1;
    y = 1;
    width = this.menus[i].width - 2;
    
    for (j = 1; j < this.menus[i].items.length; j++) 
    {
      this.menus[i].items[j].normLayer = getLayer('F_ITEM' + this.index + '_menu' + i + '_norm' + j);
      this.menus[i].items[j].highLayer = getLayer('F_ITEM' + this.index + '_menu' + i + '_high' + j);
      this.menus[i].items[j].dmmyLayer = getLayer('F_ITEM' + this.index + '_menu' + i + '_dmmy' + j);
      height = getHeight(this.menus[i].items[j].normLayer);      
      moveLayerTo(this.menus[i].items[j].normLayer, x, y);
      //menu第二層mouseout color
      setBgColor(this.menus[i].items[j].normLayer, "#6E8BAD",1);
      clipLayer(this.menus[i].items[j].normLayer, 0, 0, width, height);
      inheritLayer(this.menus[i].items[j].normLayer);
      moveLayerTo(this.menus[i].items[j].highLayer, x, y);
      //menu第二層mouseover color
      if (this.menus[i].items[j].link == "")
         setBgColor(this.menus[i].items[j].highLayer, "#6E8BAD",1);      
      else
         setBgColor(this.menus[i].items[j].highLayer, "#92A7C2",1);      
         
      clipLayer(this.menus[i].items[j].highLayer, 0, 0, width, height);
      hideLayer(this.menus[i].items[j].highLayer);
      moveLayerTo(this.menus[i].items[j].dmmyLayer, x, y);
      
      if (!NS) F_ITEMIEResizeLayer(this.menus[i].items[j].dmmyLayer, width, height);
      clipLayer(this.menus[i].items[j].dmmyLayer, 0, 0, width, height);
      inheritLayer(this.menus[i].items[j].dmmyLayer);
      this.menus[i].items[j].dmmyLayer.highLayer = this.menus[i].items[j].highLayer;
      this.menus[i].items[j].dmmyLayer.onmouseover = F_ITEMItemOn;
      this.menus[i].items[j].dmmyLayer.onmouseout = F_ITEMItemOff;
      
      if (NS) 
      {
        this.menus[i].items[j].dmmyLayer.document.highLayer = this.menus[i].items[j].highLayer;
        this.menus[i].items[j].dmmyLayer.document.parentHighLayer = this.menus[i].hdrHighLayer;
        this.menus[i].items[j].dmmyLayer.document.menuLayer = this.menus[i].baseLayer;
        this.menus[i].items[j].dmmyLayer.document.link = this.menus[i].items[j].link;
        this.menus[i].items[j].dmmyLayer.document.captureEvents(Event.MOUSEUP);
        this.menus[i].items[j].dmmyLayer.document.onmouseup = F_ITEMItemClick;
      }
      else 
      {
        this.menus[i].items[j].dmmyLayer.highLayer = this.menus[i].items[j].highLayer;
        this.menus[i].items[j].dmmyLayer.parentHighLayer = this.menus[i].hdrHighLayer;
        this.menus[i].items[j].dmmyLayer.menuLayer = this.menus[i].baseLayer;
        this.menus[i].items[j].dmmyLayer.link = this.menus[i].items[j].link;
        this.menus[i].items[j].dmmyLayer.onclick = F_ITEMItemClick;
      }
      y += height + 1;
    }
    
    width = this.menus[i].width;
    height = y - 2;
    this.menus[i].baseLayer.width = this.menus[i].width;
    this.menus[i].baseLayer.height = height;
    if (!NS) F_ITEMIEResizeLayer(this.menus[i].baseLayer, width, height);
    clipLayer(this.menus[i].baseLayer, 0, 0, width, height);
    this.menus[i].baseLayer.parentHighLayer = this.menus[i].hdrHighLayer;
    this.menus[i].baseLayer.onmouseout = ECSmenuOff;
  }
  this.created = true;
  this.resize(this.width);
  showLayer(this.baseLayer);  
}

function F_ITEMMoveTo(x, y) {
  this.x = x;
  this.y = y;
  if (this.created) moveLayerTo(this.baseLayer, this.x, this.y);
}
function F_ITEMMoveBy(dx, dy) {
  this.x += dx;
  this.y += dy;
  if (this.created) moveLayerTo(this.baseLayer, this.x, this.y);
}
function F_ITEMGetzIndex() {
  if (this.created) return getzIndex(this.baseLayer);
  return 0;
}
function F_ITEMSetzIndex(z) {
  var i;
  if (this.created) {
    setzIndex(this.baseLayer, z);
    for (i = 0; i < this.menus.length; i++) setzIndex(this.menus[i].baseLayer, z);
  }
}
function F_ITEMGetWidth() 
{ 
   return this.width;    
}
function F_ITEMGetMinWidth() { return this.minWidth; }
function F_ITEMGetAlign() { return this.align; }
function F_ITEMResize(width) {
  if (this.created) {
    this.width = Math.max(width, this.minWidth);
    if (!NS) {
      F_ITEMIEResizeLayer(this.fillerLayer, this.width - 2, this.height - 2);
      F_ITEMIEResizeLayer(this.baseLayer, this.width, this.height);
    }
    clipLayer(this.fillerLayer, 0, 0, this.width - 2, this.height - 2);
    clipLayer(this.baseLayer, 0, 0, this.width, this.height);
    if (this.align == "left") this.hdrsOffsetX = 0;
    else if (this.align == "center") this.hdrsOffsetX = Math.round((this.width - this.minWidth) / 2);
    else if (this.align == "right") this.hdrsOffsetX = this.width - this.minWidth;
    else this.hdrsOffsetX = Math.min(parseInt(this.align, 10), this.width - this.minWidth);
    moveLayerTo(this.hdrsBaseLayer, this.hdrsOffsetX, 0);
    for (i = 0; i < this.menus.length; i++) {
      this.menus[i].hdrDmmyLayer.offsetX = this.menus[i].hdrLeft - 1;
      if (this.hdrsOffsetX + this.menus[i].hdrDmmyLayer.offsetX + this.menus[i].width > this.width)
        this.menus[i].hdrDmmyLayer.offsetX = this.menus[i].hdrRight - this.menus[i].width;
    }
  } else this.width = width;
}
function F_ITEMInvert() { this.inverted = !this.inverted; }
function F_ITEMIsInverted() { return this.inverted; }
function F_ITEMIEResizeLayer(layer, width, height) {
  layer.style.pixelWidth = width;
  layer.style.pixelHeight = height;
}
function F_ITEMHeaderOn(e) {
  var bar;
  var x, y;
  bar = F_ITEMs[this.index];
  if (this.menuLayer != null) {
    x = bar.x + bar.hdrsOffsetX + this.offsetX;
    y = bar.y + this.offsetY;
    if (bar.inverted) y = bar.y - this.menuLayer.height + bar.border;
    moveLayerTo(this.menuLayer, x, y);
    this.menuLayer.left = getPageLeft(this.menuLayer);
    this.menuLayer.top = getPageTop(this.menuLayer);
    this.menuLayer.right = this.menuLayer.left + this.menuLayer.width + 1;
    this.menuLayer.bottom = this.menuLayer.top + this.menuLayer.height + 1;
  }
  if (!NS) {
    if (bar.activeHeader != null && bar.activeHeader != this) {
      hideLayer(bar.activeHeader.highLayer);
      if (bar.activeHeader.menuLayer != null) hideLayer(bar.activeHeader.menuLayer);
    }
    bar.activeHeader = this;
  }
  showLayer(this.highLayer);
  if (this.menuLayer != null) showLayer(this.menuLayer);
}
function F_ITEMHeaderOff(e) {
  if (this.menuLayer != null) {
    if (!NS) {
      mouseX = window.event.clientX + document.body.scrollLeft;
      mouseY = window.event.clientY + document.body.scrollTop;
    }
    if (mouseX >= this.menuLayer.left && mouseX <= this.menuLayer.right &&
    mouseY >= this.menuLayer.top && mouseY <= this.menuLayer.bottom)
      return;
    hideLayer(this.menuLayer);
  }
  hideLayer(this.highLayer);
}

function ECSmenuOff(e) {
  if (!NS) {
    mouseX = window.event.clientX + document.body.scrollLeft;
    mouseY = window.event.clientY + document.body.scrollTop;
    if (mouseX >= this.left && mouseX <= this.right && mouseY >= this.top && mouseY <= this.bottom)
      return;
  }
  hideLayer(this);
  hideLayer(this.parentHighLayer);
}

function F_ITEMItemOn() { showLayer(this.highLayer); }
function F_ITEMItemOff() { hideLayer(this.highLayer); }

function F_ITEMItemClick(e) 
{
  if (this.link == "") return true;
  if (this.menuLayer != null) hideLayer(this.menuLayer);
  if (this.parentHighLayer != null) hideLayer(this.parentHighLayer);
  hideLayer(this.highLayer);
  if (this.link.indexOf("javascript:") == 0) eval(this.link);
  else window.location.href = this.link;
  return true;
}

// MOUSE TRACKING
var mouseX = 0;
var mouseY = 0;
if (NS) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = F_ITEMGetMousePosition;

function F_ITEMGetMousePosition(e) 
{
  if (NS) {
    mouseX = e.pageX;
    mouseY = e.pageY;
  } else {
    mouseX = window.event.clientX + document.body.scrollLeft;
    mouseY = window.event.clientY + document.body.scrollTop;
  }
}

// EVENT: Window Resizing
var origWidth;
var origHeight;
if (NS) {
  origWidth  = window.innerWidth;
  origHeight = window.innerHeight;
}

function Reload() {
  if (NS && origWidth == window.innerWidth && origHeight == window.innerHeight) return;
  if (IE) setTimeout('window.location.href = window.location.href', 2000);
  else window.location.href = window.location.href;
}

function init() {
  fullWidth = getWindowWidth() - (NS && getWindowHeight() < getPageHeight() ? 16 : 0);
  F_BAR.create();  
  /*固定在TOP的功能
  F_BAR.moveBy(0,-getWindowHeight()+17);  
  NAVupdatePOSY();
  F_BAR.resize(fullWidth);*/
  //調整視窗大小配合menu
  F_BAR.resize(600);
  F_BAR.setzIndex(0);
}

function NAVupdatePOSY() {
  var viewTop;
  var viewBottom;
  var dy;
  viewTop = getPageScrollY();
  viewBottom = viewTop + getWindowHeight();
  dy = Math.round(Math.abs(viewTop - F_BAR.y));
  if (viewTop < F_BAR.y) dy = -dy;
  if (F_BAR.bottom < viewTop) F_BAR.moveTo(0, viewTop - F_BAR.height);
  if (F_BAR.top > viewBottom) F_BAR.moveTo(0, viewBottom);
  F_BAR.moveBy(0, dy);
  setTimeout('NAVupdatePOSY()', 0);
}

function maximizeWin() {
  if (window.screen) {
    var aw = screen.availWidth;
    var ah = screen.availHeight;
    window.moveTo(0, 0);
    window.resizeTo(aw, ah);
  }
}

