function Is ()
{   // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase()

    // --- BROWSER VERSION ---
    this.major = stringToNumber(navigator.appVersion)
    this.minor = parseFloat(navigator.appVersion)

    this.nav  = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1)))
    this.nav2 = (this.nav && (this.major == 2))
    this.nav3 = (this.nav && (this.major == 3))
    this.nav4 = (this.nav && (this.major == 4))
	
	//Netscape 6
	this.nav5 =	(this.nav && (this.major == 5))
	this.nav6 = (this.nav && (this.major == 5))
	this.gecko = (this.nav && (this.major >= 5))

    this.ie   = (agt.indexOf("msie") != -1)
    this.ie3  = (this.ie && (this.major == 2))
    this.ie4  = (this.ie && (this.major == 3))
    this.ie5  = (this.ie && (this.major == 4))


    this.opera = (agt.indexOf("opera") != -1)
     
    this.nav4up = this.nav && (this.major >= 4)
    this.ie4up  = this.ie  && (this.major >= 4)
    
    this.mac = (agt.indexOf('mac') != -1);
    this.safari = (this.mac && (agt.indexOf('safari') != -1));
    this.konqueror = (agt.indexOf('konqueror') != -1);
    if (this.konqueror) {
    	this.gecko = this.konqueror;
    }
    //alert("This is a "+agt);
}


var is = new Is();

function getElt () 
{ if (is.nav4)
  {
    var currentLayer = document.layers[getElt.arguments[0]];
    for (var i=1; i<getElt.arguments.length && currentLayer; i++)
    {   currentLayer = currentLayer.document.layers[getElt.arguments[i]];
    }
    return currentLayer;
  } 
  else if(document.getElementById && document.getElementsByName)
  { 
    var name = getElt.arguments[getElt.arguments.length-1];
    if(document.getElementById(name))                      //First try to find by id
       return document.getElementById(name);
    else if (document.getElementsByName(name))             //Then if that fails by name
	   return document.getElementsByName(name)[0];
  }
  else if (is.ie4up) {
    var elt = eval('document.all.' + getElt.arguments[getElt.arguments.length-1]);
    return(elt);
  }

}

function showElt(elt)
{
	setEltVisibility(elt,'visible');
}

function hideElt(elt)
{
	setEltVisibility(elt, 'hidden');
}

function setEltVisibility (elt, value)
{  if (is.nav4) elt.visibility = value;
   else if (elt.style) elt.style.visibility = value;
}


function getEltVisibility (elt)
{  if (is.nav4) 
   {  var value = elt.visibility;
      if (value == "show") return "visible";
      else if (value == "hide") return "hidden";
      else return value;
   }
   else if (elt.style) return elt.style.visibility;
}

function moveEltTo (elt, x, y) 
{ if (is.nav4) elt.moveTo(x, y);
  else if (is.ie4up) {
    elt.style.pixelLeft = x;
    elt.style.pixelTop  = y;
  }
  else if (is.gecko) {
    elt.style.left = x;
    elt.style.top  = y;
  }
}

function moveEltBy (elt, x, y) 
{ if (is.nav4) elt.moveBy(x, y);
  else if (is.ie4up)  {
    elt.style.pixelLeft += x;
    elt.style.pixelTop  += y;
  }
  else if (is.gecko)  {
    elt.style.left = (stringToNumber(elt.style.left) + x + "px");
    elt.style.top  = (stringToNumber(elt.style.top)  + y + "px");
  }
}
function getEltPageLeft(elt) {
  var x;

  if (is.nav4)
    return elt.pageX;
  if (is.ie4up) {
    x = 0;
    while (elt.offsetParent != null) {
      x += elt.offsetLeft;
      elt = elt.offsetParent;
    }
    x += elt.offsetLeft;
    return x;
  }
  if (is.gecko) {
    x = 0;
    while (elt.offsetParent != null) {
      x += elt.offsetLeft;
      elt = elt.offsetParent;
    }
    x += elt.offsetLeft;
    return x;
  }
  return -1;
}
function getEltPageTop(elt) {
  var y = 0;

  if (is.nav4)
    return elt.pageY;
  if (is.ie4up) {
    while (elt.offsetParent != null) {
      y += elt.offsetTop;
      elt = elt.offsetParent;
    }
    y += elt.offsetTop;
    return y;
  }

  if (is.mac && is.ie5)
  {
    y += stringToNumber(document.body.currentStyle.marginTop);
  }

  if (is.gecko) {
    while (elt.offsetParent != null) {
      y += elt.offsetTop;
      elt = elt.offsetParent;
    }
    y += elt.offsetTop;
    return y;
  }
  return -1;
}

function setEltLeft (elt, x) {
  if (is.nav4)     elt.left=x;
  else if (is.ie4up) elt.style.pixelLeft=x;
  else if (is.gecko) elt.style.left = (x + "px");
}

function getEltLeft (elt) {
  if (is.nav4)     return (elt.left);
  else if (is.ie4up) return (elt.style.pixelLeft);
  else if (is.gecko) return stringToNumber(elt.style.left);
}

function setEltTop (elt, y) 
{ if (is.nav4)     elt.top=y;
  else if (is.ie4up) elt.style.pixelTop=y;
  else if (is.gecko) elt.style.top= (y + "px");
}

function getEltTop (elt) 
{ if (is.nav4)     return (elt.top);
  else if (is.ie4up) return (elt.style.pixelTop);
  else if (is.gecko) return stringToNumber(elt.style.top);
}

function getEltWidth(elt) {

  if (is.nav4) {
    if (elt.document.width)
      return elt.document.width;
    else
      return elt.clip.right - elt.clip.left;
  }
  if (is.ie4up) {
    if (elt.style.pixelWidth)
      return elt.style.pixelWidth;

    else
      return elt.offsetWidth;
  }
  if (is.gecko) {
    if (elt.style.width)
      return stringToNumber(elt.style.width);
    else
      return stringToNumber(elt.offsetWidth);
  }
  return -1;
}

function setEltWidth(elt,wdth)
{
	if(is.nav4)
    { 
	     elt.document.width = wdth;
    }
    else if(elt.style)
    { 
        elt.style.width = wdth;
    }
}

function getEltHeight(elt) {
  if (is.nav4) {
    if (elt.document.height)
      return elt.document.height;
    else
      return elt.clip.bottom - elt.clip.top;
  }
  if (is.ie4up) {
    if (elt.style.pixelHeight)
      return elt.style.pixelHeight;
    else
      return elt.clientHeight;
  }
  if (is.gecko) {
    if (elt.style.height)
      return stringToNumber(elt.style.height);
    else
      return stringToNumber(elt.offsetHeight);
  }
  return -1;
}

function setEltHeight(elt,hght)
{
	if(is.nav4)
    { 
		elt.document.height = hght;
    }
    else if(elt.style)
    { 
        elt.style.height = hght;
    }
}

function setEltClip (elt, cliptop, clipright, clipbottom, clipleft) 
{ if (is.nav4) {
    elt.clip.left   = clipleft;
    elt.clip.top    = cliptop;
    elt.clip.right  = clipright;
    elt.clip.bottom = clipbottom;
  }
  else if (is.ie4up)  elt.style.clip = 'rect(' + cliptop + ' ' +  
       clipright + ' ' + clipbottom + ' ' + clipleft +')';
  else if (is.gecko)  elt.style.clip = 'rect(' + cliptop + ' ' +  
       clipright + ' ' + clipbottom + ' ' + clipleft +')';
}

function tempClipObj (elt)
{  var clipStr = elt.style.clip;
  
   clipStr = clipStr.substring (clipStr.indexOf("(") + 1);
   this.top = stringToNumber(clipStr);
   clipStr = clipStr.substring (clipStr.indexOf(" ") + 1);
   this.right = stringToNumber(clipStr);
   clipStr = clipStr.substring (clipStr.indexOf(" ") + 1);
   this.bottom = stringToNumber(clipStr);
   clipStr = clipStr.substring (clipStr.indexOf(" ") + 1);
   this.left = stringToNumber(clipStr);
}

function getEltClipLeft (elt) 
{ if (is.nav4)     return (elt.clip.left);
  else if (elt.style) 
  {  var tempClip = new tempClipObj (elt);
     return tempClip.left;
  }
}
function getEltClipTop (elt) 
{ if (is.nav4)     return (elt.clip.top);
  else if (elt.style) 
  {  var tempClip = new tempClipObj (elt);
     return tempClip.top;
  }
}

function getEltClipRight (elt) {
  if (is.nav4)     return (elt.clip.right);
  else if (elt.style) 
  {  var tempClip = new tempClipObj (elt);
     return tempClip.right;
  }

}

function getEltClipBottom (elt) 
{ if (is.nav4)     return (elt.clip.bottom);
  else if (elt.style) 
  {  var tempClip = new tempClipObj (elt);
     return tempClip.bottom;
  }
}

function getEltClipWidth (elt) 
{
    return (getEltClipRight(elt) - getEltClipLeft(elt));
}


function getEltClipHeight (elt) 
{
    return (getEltClipBottom(elt) - getEltClipTop(elt));
}


function getCurrentWinWidth() 
{ if (is.nav4)     return(window.innerWidth);
  else if (is.ie4up) return(document.body.clientWidth);
  else if (is.gecko) return(window.innerWidth);
}

function getCurrentWinHeight() 
{ if (is.nav4)     return(window.innerHeight);
  else if (is.ie4up) return(document.body.clientHeight);
  else if (is.gecko) return(window.innerHeight);

}

function getEltZIndex (elt) 
{ if (is.nav4) return(elt.zIndex);
  else if (elt.style) return (elt.style.zIndex);
}
function setEltZIndex (elt, z) 
{ if (is.nav4) elt.zIndex = z;
  else if (elt.style) elt.style.zIndex = z;
}

/* A version of stringToNumber that returns 0 if there is NaN returned, or number is part of a string, like 100px... */
function stringToNumber(s)
{
        return parseInt(('0' + s), 10)
}


// futurelab specific functions
var viewed = new Array();
var highlighted = new Array();
var timeout_id = 0;

function setLayer(level, path) {
	if (viewed[level]) {
		hideElt(viewed[level]);
	}
	var posObj = getElt('level_'+level);
	if (! posObj) {
		//alert('Cannot find object level_'+level);
		return;
	}
	var x = getEltPageLeft(posObj);
	var y = getEltPageTop(posObj);
	var treestring = path.join("_");
	var newEl = getElt('navlay_' + treestring);
	if (! newEl) {
		//alert('Cannot find object navlay_'+treestring);
		return;
	}
	if (is.ie4up && is.mac) {
		x += 10;
		y += 15;
	} else if (is.safari) {
		x -= 8;
		y -= 8;
	} else if (is.konqueror) {
		x -= 10;
		y -= 10;
	}
	moveEltTo(newEl, x, y);
	//alert("move nav_"+level+"_"+treestring+" to "+x+", "+y);
	showElt(newEl);
	viewed[level] = newEl;
}

function resetMenu() {
	clearMenu(1);
	resetPicts("");
	if (default_path.length > 0) {
		var tp = default_path.concat();
		while (tp.length) {
			showMenu(tp);
			highlightPict(tp.join("_"), true);
			tp.pop();
		}
	}
}

function highlightPict(path_string, high) {
	var pict = getElt('nav_'+path_string);
	if (pict) {
		pict.src = pictbase + 'nav' + (high ? 'h' : '') + '_' + path_string + '.png';
	}
	highlighted[parsePathString(path_string).length] = (high ? path_string : 0);
}


function resetPicts(path_string) {
	var i;
	for (i = 1; i <= maxlevel; i++) {
		var pstr = highlighted[i];
		if (pstr) {
			var sstr = path_string.substring(0, pstr.length);
			if (sstr != pstr) {
				//win.document.write('check: '+pstr+' != '+sstr+'('+path_string+'):   ');
				//win.document.writeln('no match -> reset pict<br>');
				highlightPict(pstr, false);
			} else {
				//win.document.write('check: '+pstr+' != '+sstr+'('+path_string+'):   ');
				//win.document.writeln('has matched or pstr empty<br>');
			}
		}
	}
}

function parsePathString(path_string) {
	return path_string.split("_");
}

function clearMenu(startlevel) {
	var i;
	for (i = startlevel; i < maxlevel; i++) {
		if (viewed[i]) {
			hideElt(viewed[i]);
			viewed[i] = 0;
		}
	}
}

function showMenu(path) {
	var level = path.length;
	setLayer(level, path);
}

function mouseOverHandler(path_string, nolayer) {
	resetPicts(path_string);
	var path = parsePathString(path_string);
	highlightPict(path_string, true);
	clearMenu(path.length);
	if (! nolayer) {
		showMenu(path);
	}
	clearTimeout(timeout_id);
}

function mouseOutHandler(path_string) {
	timeout_id = setTimeout("resetMenu()", delay);
}


