var theX = 0;
var theY = 0;
var netscapeCursorOffset = 10;
var ieCursorOffset = 20;
if(!al) { var al = null; }
var activeLabelDisplayed = false;
var timeoutID = null;
if(!is) { var is = new Is(); }
if(is.nav4up)
{
	window.captureEvents(Event.MOUSEMOVE);
	window.onmousemove=mouseMoveNetscape;
}

function mouseMoveNetscape(e)
{
	theX=e.pageX;
	theY=e.pageY;
	conditionalShow();
}

function mouseMoveIE()
{
  if (!is.nav)
  {
  	theX=document.body.scrollLeft+window.event.clientX;
	  theY=document.body.scrollTop+window.event.clientY;
	  conditionalShow();
	}
}

function createLayer(w,h,text) {
	var id = "activeLabelLayer";
	if (is.nav4up && !is.moz)
	{
		w = (w!=null ? w : window.innerWidth);
		lyr = new Layer(w,self);
		if(text!=null)
		{
			lyr.document.open();
			lyr.document.writeln(text);
			lyr.document.close();
		}
		lyr.visibility="show";
		return lyr;
	}
	else
	{
		var parentElement = document.body;
		if (is.ie4)
		{
			var code = '<div id="' + id + '" style="position:absolute; left:0px; top:0px;';
			if(w!=null)
			{
				code += ' width:'+w+'px;';
			}
			if(h!=null)
			{
				code += ' height:'+h+'px;';
			}
			code +='"></div>';
			parentElement.insertAdjacentHTML("beforeEnd", code);
			lyr = parentElement.children[parentElement.children.length-1];
			if(text!=null)
			{
				lyr.innerHTML = text;
			}
			return lyr;
		}
		else if (is.ie5 || is.moz)
		{
			lyr = document.createElement("DIV");
			lyr.style.position = "absolute";
			if(w!=null)
			{
				lyr.style.width = w;
			}
			/*  causes issues on IE 5 (5.00.2314.1003)
			if(h!=null)
			{
				lyr.style.height = h;
			}
			*/
			lyr.id=id;
			if(text!=null)
			{
				lyr.innerHTML = text;
			}
			parentElement.appendChild(lyr);
			return lyr;
		}
	}
}

function conditionalShow()
{
	if(activeLabelDisplayed)
	{
		showLayer(getLayer());
	}
}

//
// Get a layer
//
function getLayer () 
{ 
	if(al==null)
	{
		if(is.nav4up)
		{
			al = createLayer(window.innerWidth,window.innerHeight,"<table width='"+window.innerWidth+"' height='"+window.innerHeight+"'><tr><td>&nbsp;</td></tr></table>");
		}
		else if(is.ie)
		{
			al = createLayer(null,null,"<table><tr><td>&nbsp;</td></tr></table>");
		}
		setEltVisibility (al, "hidden")
	}
	return al;
}

//
// Set a layer's visibility
//
function setEltVisibility (elt, value)
{
	if (is.nav4up && !is.moz)
		elt.visibility = value;
	else if (is.moz || is.ie4up) {
		elt.style.visibility = value;
  }
}

//
// Set a layer's position and clip rect
//
function setEltRect (elt, x, y, width, height)
{
	setEltPos(elt, x, y);
	if(is.nav4up && !is.moz)
	{
		elt.clip.top=0;
		elt.clip.left=0;
		elt.clip.right=width;
		elt.clip.bottom=height;
	}
	else if(is.moz || is.ie4up)
	{
		elt.style.clipTop = 0;
		elt.style.clipLeft = 0;
		elt.style.clipRight = width;
		elt.style.clipBottom = height;
	}
}

//
// Set a layer's position

//
function setEltPos(elt, x, y)
{
	if(is.nav4up && !is.moz)
	{
		elt.x = x;
		elt.y = y;
	}
	else if(is.moz || is.ie4up)
	{
		elt.style.left = x + 'px';
		elt.style.top = y + 'px';
	}
}

//
// Set a layer's contents
//
function setEltContents (elt, contents)
{
	if(is.nav4up && !is.moz)
	{
		elt.document.open();
		elt.document.writeln(contents);
		elt.document.close();
	}
	else if(is.moz || is.ie4up)
	{
		elt.innerHTML = contents;
	}
}

function showLayer(layr)
{
	if(is.nav4up && !is.moz)
	{
		setEltRect(layr, theX-layr.document.width/2, theY-layr.document.height-netscapeCursorOffset, layr.document.width, layr.document.height);
	}
	else if(is.moz || is.ie4up)
	{
		setEltPos(layr, theX-layr.scrollWidth/2, theY-layr.scrollHeight-ieCursorOffset);
	}
	setEltVisibility(layr, "visible");
}

function Is ()
{
    var agt=navigator.userAgent.toLowerCase()
    this.major  = parseInt(navigator.appVersion)
    this.minor  = parseFloat(navigator.appVersion)
    this.nav    = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1)))
    this.moz    = this.nav && (this.major >= 5)
    this.nav4up = this.nav && (this.major >= 4)
    this.ie     = (agt.indexOf("msie") != -1)
    this.ie4    = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.")==-1));
    this.ie5    = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.")!=-1));
    this.ie4up  = this.ie && (this.major >= 4)
}

//
// Dispose of the Active Label
//
function unDisplayActiveLabel()
{
	if(is.nav4up || is.ie4up)
	{
		var layr = getLayer();
		setEltVisibility(layr, "hidden");
	}
	window.status = "";
	clearTimeout(timeoutID);
	activeLabelDisplayed = false;
	return true;
}

//
// Display the Active Label with the given text
//
function displayActiveLabel(which, text)
{
	if(is.nav4up || is.ie4up)
	{
		var layr = getLayer();
		setEltContents(layr, begin[which]+text+end[which]);
		showLayer(layr);
	}
	window.status = text;
	timeoutID = setTimeout("window.status = unescape('"+escape(text)+"');", 0);
	activeLabelDisplayed = true;
	return true;
}
