var MENU_WIDTH = 120;
var BANNER_HEIGHT = 65;

var subMenuShowingId = "";
var subItemLastOverId = "";
var subMenuTimer = setTimeout("",10);

function Position(x,y)
{
  this.x = x;
  this.y = y;
}

function Size(width,height)
{
  this.width = width;
  this.height = height;
}

function getUnvWindowSize()
{
  var width;
  var height;
  if(document.body.clientWidth)
  {
    width = document.body.clientWidth;
    height = document.body.clientHeight;
  }
  else if (window.innerWidth)
  {
    width = window.innerWidth;
    height = window.innerHeight;
  }
  return new Size(width,height);
}

function getUnvElementById(id)
{
  if(document.all)
  {
    return document.all[id];
  }
  else if(document.getElementById)
  {
    // Netscape 6+
    return document.getElementById(id);
  }
  else if(document.layers)
  {
    // Netscape 4.X
  }
}

function getUnvPosition(e)
{
  var x;
  var y;
  if(e.pageX)
  {
    x = e.pageX;
    y = e.pageY;
  }
  else if (e.clientX)
  {
    x = e.clientX;
    y = e.clientY;
  }
  return new Position(x,y);
}

function overItem(event, menuId, absPos)
{
  overTimer();

  if(subMenuShowingId != menuId)
  {
    menuOut();
  }

  subMenuShowingId = menuId;
  
  var menu = getUnvElementById(menuId);
  var p = getUnvPosition(event);
  var vPos = p.y - 20;
 
  if(absPos)
  {
    vPos = absPos;
  }

  if(menu.style.visibility != "visible")
  {
    if(!menu.pos)
    {
      menu.pos = new Position(MENU_WIDTH - 20, vPos);
    }
    menu.style.top = menu.pos.y;
    menu.style.left = menu.pos.x;
    menu.style.visibility = "visible";
  }
}

function overMenu(event, menuId)
{
  overTimer();
}

function mouseOutItem(event, menuId)
{
  outTimer();
}

function mouseOutMenu(event, menuId)
{
  outTimer();
}

function overTimer()
{
  clearTimeout(subMenuTimer);
}

function outTimer()
{
  clearTimeout(subMenuTimer);
  subMenuTimer = setTimeout("menuOut()",200);
}

function menuOut()
{
  if(subMenuShowingId != "")
  {
    getUnvElementById(subMenuShowingId).style.visibility = "hidden";
  }
}

function layoutTarget()
{
  var theTarget = getUnvElementById("theTarget");
  theTarget.style.width = getUnvWindowSize().width - MENU_WIDTH - 20;
  theTarget.style.height = getUnvWindowSize().height - BANNER_HEIGHT - 20;
}

function layoutMenu()
{
  var theMenu = getUnvElementById("menuCell");
  theMenu.style.width = MENU_WIDTH;
}

function layoutBanner()
{
  var theMenu = getUnvElementById("bannerCell");
  theMenu.style.height = BANNER_HEIGHT;
  theMenu.style.width = getUnvWindowSize().width - 10;
}

var statusBuffer = "";
function statusOut(out)
{
  statusBuffer = statusBuffer + out + "|";
  while(statusBuffer.length > 80)
  {
    statusBuffer = statusBuffer.substring(1)
  }
  defaultStatus = statusBuffer; 
}

function layoutAll()
{
  if(document.layers)
  {
    location.href = "indexNS4.html";
  }
  else
  {
    layoutBanner();
    layoutTarget();
    layoutMenu();
  }
}
