var bName = navigator.appName;
var bVer = parseInt(navigator.appVersion);
var NS6 = (bName == "Netscape" && bVer >= 5);
var NS4 = (bName == "Netscape" && bVer >= 4 && bVer < 5);
var IE4 = (bName == "Microsoft Internet Explorer" && bVer >= 4);
var NS3 = (bName == "Netscape" && bVer < 4);
var IE3 = (bName == "Microsoft Internet Explorer" && bVer < 4);
if (NS4) {intTop=intTop-1;}

window.onerror = null;
var menuActive = 0;
var menuOn = 0;
var onLayer;
var timeOn = null;

if (NS4 || IE4 || NS6) {
  if (navigator.appName == "Netscape" && !document.getElementById){
    layerStyleRef='layer.';
    layerRef='document.layers';
    styleSwitch='';
    layerVis='show';
    layerHid='hide';
  }else if(!document.all && document.getElementById){
    layerStyleRef='layer.style.';
    layerRef='document.getElementById';
    styleSwitch='.style';
    layerVis='visible';
    layerHid='hidden';
  }else{
    layerStyleRef='layer.style.';
    layerRef='document.all';
    styleSwitch='.style';
    layerVis='visible';
    layerHid='hidden';
  }
}
/** get image instance **/
function getImage(name) {
  if (document.layers)
    return findImage(name, document);
  if (document.all)
    return document.all[name];
  else
    return document.getElementById(name);
}
/** find image in collection **/
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;
}
/** get image x **/
function getImagePageLeft(img) {
  var x, obj;
  if (!img)
    return 0;

  if (NS4 || NS6) {
    if (img.container != null)
      return img.container.pageX + img.x - 1;
    else
      return img.x - 1;
  }
  if (IE4) {
    x = 0;
    obj = img;
    while (obj.offsetParent != null) {
      x += obj.offsetLeft;
      obj = obj.offsetParent;
    }
    x += obj.offsetLeft;
    return x;
  }
  return -1;
}
/** get image y **/
function getImagePageTop(img) {
  var y, obj;
  if (!img)
    return 0;

  if (NS4 || NS6) {
    if (img.container != null)
      return img.container.pageY + img.y;
    else
      return img.y;
  }
  if (IE4) {
    y = 0;
    obj = img;
    while (obj.offsetParent != null) {
      y += obj.offsetTop;
      obj = obj.offsetParent;
    }
    y += obj.offsetTop;
    return y;
  }
  return -1;
}
/** hide current layer **/
function hideLayer(layerName){
 if (menuActive == 1) return;
 if (NS4 || IE4) eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="'+layerHid+'"');
 if (NS6) eval(layerRef+'("'+layerName+'")'+styleSwitch+'.visibility="'+layerHid+'"');
}
/** TIMER FOR BUTTON MOUSE OUT **/
function btnTimer() {
 timeOn = setTimeout("btnOut()",1000)
}
/** BUTTON MOUSE OUT **/
function btnOut(layerName) {
 if (menuActive == 0) {
 hideLayer(onLayer)
 }
}
/** MENU MOUSE OVER **/
function menuOver(elm) {
 elm.className = "menuOn";
 clearTimeout(timeOn);
 menuActive = 1;
}
/** MENU MOUSE OUT **/
function menuOut(elm) {
 elm.className="menuOff";
 menuActive = 0;
 timeOn = setTimeout("hideLayer(onLayer)", 400);
}
/** SET BACKGROUND COLOR **/
function setBgColor(layer, color) {
  if (NS6){
    eval('document.getElementById("'+layer+'").style.backgroundColor="'+color+'"');
  }
  else if (NS4){
    eval('window.document.layers["'+layer+'"].document.bgColor="'+color+'"');
        eval('window.document.layers["'+layer+'"].saveColor="'+color+'"');
  }
  else if (IE4){
    eval('document.all.'+layer+'.style.backgroundColor="'+color+'"');
  }
}

//*********************************************************
/**
 * Title: TextMenu
 * Description:
 */
function Menu( itemId, label, altLabel, url ) {
  this.id         = itemId;
  this.label      = label;
  this.altLabel   = altLabel;
  this.url        = url;
  this.menuWidth  = 200;
  this.bgColor    = '#FFD784';
  this.selBGColor = '#990000';
  this.fgColor    = '#FFB928';
  this.totalItems = 0;
  this.items      = new Object();
  this.offsetX    = 0;
  this.offsetY    = 5;

  /** add new sub item **/
  this.addItem = function( oItem ) {
    this.totalItems++;
    this.items[this.id + this.totalItems] = oItem;
  }

  /** build menu **/
  this.build = function() {
    document.write('<div id="' + this.id + '" style="Z-INDEX: 1; VISIBILITY: hidden; POSITION: absolute;">');
    document.write('<table border="0" cellSpacing="1" cellPadding="1" style="background:'+this.fgColor+';">');

    for (iPtr in this.items) {
      oItem = this.items[iPtr];

      document.write('<tr id="'+iPtr+'">');
      document.write('<td width="'+this.menuWidth+'" ');
      document.write('class="menuOff" ');
      document.write('style="padding-left:5px; padding-right:5px;" ');
      document.write('onmouseover="menuOver(this)" ');
      document.write('onmouseout="menuOut(this)" ');
      document.write('onclick="document.location=\''+oItem.url+'\'">');
      document.write(oItem.label+'</td></tr>');
    }

    document.write('</table>');
    document.write('</div>');
  }

  /** show menu **/
  this.show = function(layerName){
    img = getImage(layerName+"Img");
    menuX = getImagePageLeft(img) + this.offsetX;
    menuY = getImagePageTop(img) + img.height + this.offsetY;

    if (NS4 || IE4 || NS6) {
      if (timeOn != null) {
        clearTimeout(timeOn)
        hideLayer(onLayer)
      }
      if (NS4 || IE4) {
        eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="'+layerVis+'"');
        eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.top='+menuY);
        eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.left='+menuX);
      } else if (NS6) {
        eval(layerRef+'("'+layerName+'")'+styleSwitch+'.visibility="'+layerVis+'"');
        eval(layerRef+'("'+layerName+'")'+styleSwitch+'.top='+menuY);
        eval(layerRef+'("'+layerName+'")'+styleSwitch+'.left='+menuX);
      }
      onLayer = layerName
    }
  }
}
