// variables
var timerMenuId = "";	// Name of active menu
var timerId = -1;	// Timer ID variable

function loadImage(image)
{
  if (document.images) {
    res = new Image();
    res.src = image;
    return res;
  }
}

function setImage(imageid, image)
{
//  if (document.images && (preload == true))
//      document[imageid].src = image;
  if (document.getElementById)
    document.getElementById(imageid).src = image;
}

function hideMenu(menuId)
{
  if (document.getElementById) {
    if (document.getElementById(menuId))
      document.getElementById(menuId).style.visibility = 'hidden';
    else if (document.all)
      document.all[menuId].style.visibility = 'hidden';
  }
}

function resetTimer(menuId)
{
//  if (menuId.Compare(timerMenuId) != 0)
  if (menuId != timerMenuId && timerMenuId != "")
    hideMenu(timerMenuId);
  clearTimeout(timerId);
}


function setTimer(menuId)
{
  timerMenuId = menuId;
  timerId = setTimeout('hideMenu(timerMenuId)', 100);
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	} else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function startMenu(menuId, imageId, image)
{
  setImage(imageId, image);
  resetTimer(menuId)

  var menuObj = document.getElementById(menuId);
  var imageObj = document.getElementById(imageId);
  var x = findPosX(imageObj);
//  var y = findPosY(imageObj);

  menuObj.style.visibility = 'visible';
  menuObj.style.left = x + "px";
//  menuObj.style.top = y + "px";
}

function activateMenu(menuId, imageId, image)
{
  setImage(imageId, image);
  setTimer(menuId);
}

/*
var preload = false;
if (document.images && !preload) {
  menu_products_o = loadImage("_res/img/menu_products_o.gif");
  menu_trail_o = loadImage("_res/img/menu_trail_o.gif");
  menu_purchase_o = loadImage("_res/img/menu_purchase_o.gif");
  menu_support_o = loadImage("_res/img/menu_support_o.gif");
  menu_company_o = loadImage("_res/img/menu_company_o.gif");
  preload = true;
}
*/

// Write a main anchor tag
function WriteMailAnchor(user, domain, tld, text)
{
   var address = user + "@" + domain + "." + tld;
   if (text == undefined || text == "")
     text = address;
   document.write("<a href=\"mailto:" + address + "\">" + text + "</a>");
}

// popup image window
function imagewin(image,title,width,height)
{
  var sImage = sBase + image;
  var sClose = sBase + "_res/img/close.png";

  var cond = "width="+(width+20)+",height="+(height+65)+"";
  var t1 ="<html><title>" + title + "</title><body bgcolor=#FFFFFF>";
  var t2 ="<table align='center' cellpadding=0 cellspacing=0 border=0><tr><td><img src='"+sImage+"' border=0></td></tr>";
  var t3 ="<tr><td align='center' height='40' valign='bottom'><a href='#' onclick='window.close();return false'><img src='" + sClose + "' border='0'></a></td></tr></table>";
  var t4 ="</body></html>";
  var ImageWindow=window.open("", "win"+width,"toolbar=no,scrollbars="+scroll+",menubar=no,"+cond);
  ImageWindow.document.write(t1+t2+t3+t4);
  ImageWindow.document.close();
}

function imagewincap(image,title,width,height)
{
  var sImage = sBase + image;
  var sClose = sBase + "_res/img/close.png";

  var cond = "width="+(width+20)+",height="+(height+80)+"";
  var t1 ="<html><title>" + title + "</title><body bgcolor=#FFFFFF>";
  var t2 ="<table align='center' cellpadding=0 cellspacing=0 border=0><tr><td><img src='"+sImage+"' border=0></td></tr>";
  var t3 ="<tr><td align='center' style='font: 8pt sans-serif'>" + title + "</td></tr>";
  var t4 ="<tr><td align='center' height='40' valign='bottom'><a href='#' onclick='window.close();return false'><img src='" + sClose + "' border='0'></a></td></tr></table>";
  var t5 ="</body></html>";
  var ImageWindow=window.open("", "win"+width,"toolbar=no,scrollbars="+scroll+",menubar=no,"+cond);
  ImageWindow.document.write(t1+t2+t3+t4+t5);
  ImageWindow.document.close();
}
