// JavaScript source code
var bForceRepaint = (navigator.family == "gecko");
var KnowzyTips = new Array();

// Knowzy InfoBubble 2005
function KnowzyTooltip()
{
	this.Container = null;
	this.Inner1 = null;
	this.TipBody = null;
	this.Heading = null;
	this.ParentContainer = null;
	this.ComesBefore = null;
	this.bGrowingOrShrinking = false;
	this.bDirection = true; // true expanding, false contracting
	this.nBoxWidth = 0;
	this.nBoxHeight = 0;
	this.nIncrement = 25;
	this.nDelay = 60;
	this.nMaxHeight = 200;
	this.nMinHeight = 0;
	this.nMaxWidth = 275;
	this.nMinWidth = 0;
}

function CreateKnowzyTooltip(event, strTipDiv, LinkElement)
{
	var nIndex = 0;
	var bPushIt = false;
	var TheTip = FindKToolTipById(strTipDiv);
	
	if (TheTip == null)
	{
		TheTip = new KnowzyTooltip();
		bPushIt = true;
	}
	else
		nIndex = GetTipIndex(TheTip);

	TheTip.Heading = document.getElementById(strTipDiv);
	TheTip.TipBody = TheTip.Heading.parentNode;
	TheTip.Inner1 = TheTip.TipBody.parentNode;
	TheTip.Container = TheTip.Inner1.parentNode;
	TheTip.ParentContainer = TheTip.Container.parentNode;
	TheTip.ComesBefore = TheTip.Container.nextSibling;
	
	KalcMaxDimensions(TheTip);
	SetMinimums(TheTip);
	PositionTip(TheTip, event, LinkElement);
	
	TheTip.Container.style.visibility = "visible";
	
	
	TheTip.bDirection = true;

	if (bPushIt)
	{
		KnowzyTips.push(TheTip);
		TheTip.bGrowingOrShrinking = true;
		AnimateKnowzyTooltips(nIndex);
	}
}

function DestroyKTooltip(strTipDiv)
{
	var CurrentTip = FindKToolTipById(strTipDiv);

	if (CurrentTip != null)
	{
		CurrentTip.bDirection = false;
		if (!CurrentTip.bGrowingOrShrinking)
		{
//			alert("Shrink");
			CurrentTip.bGrowingOrShrinking = true;
			AnimateKnowzyTooltips(GetTipIndex(CurrentTip));
		}
	}
}

function AnimateKnowzyTooltips(nIndex)
{
	if (KnowzyTips.length > 0)
	{
		var CurrentTip = KnowzyTips[nIndex];
		
		if (CurrentTip.bGrowingOrShrinking)
		{
			CurrentTip.nBoxWidth+= (CurrentTip.bDirection) ? 
				CurrentTip.nIncrement : -CurrentTip.nIncrement;

			if ((CurrentTip.bDirection && CurrentTip.nBoxWidth >= CurrentTip.nMaxWidth) ||
				(!CurrentTip.bDirection && CurrentTip.nBoxWidth <= CurrentTip.nMinWidth))
				CurrentTip.nBoxWidth = (CurrentTip.bDirection) ? 
					CurrentTip.nMaxWidth : CurrentTip.nMinWidth;
			
			CurrentTip.Container.style.width = CurrentTip.nBoxWidth + "px";
			var nInsideWidth = (CurrentTip.nBoxWidth - 20) >= 0 ? 
				(CurrentTip.nBoxWidth - 20) : 0;
			CurrentTip.Inner1.style.width = nInsideWidth + "px";
			CurrentTip.TipBody.style.width = nInsideWidth + "px";
			
			CurrentTip.nBoxHeight+= (CurrentTip.bDirection) ? 
				CurrentTip.nIncrement : -CurrentTip.nIncrement;

			if ((CurrentTip.bDirection && CurrentTip.nBoxHeight >= CurrentTip.nMaxHeight) ||
				(!CurrentTip.bDirection && CurrentTip.nBoxHeight <= CurrentTip.nMinHeight))
				CurrentTip.nBoxHeight = (CurrentTip.bDirection) ? 
					CurrentTip.nMaxHeight : CurrentTip.nMinHeight;

			if ((CurrentTip.bDirection && (CurrentTip.nBoxHeight >= CurrentTip.nMaxHeight && 
				CurrentTip.nBoxWidth >= CurrentTip.nMaxWidth)) ||
				(!CurrentTip.bDirection && (CurrentTip.nBoxHeight <= CurrentTip.nMinHeight && 
				CurrentTip.nBoxWidth <= CurrentTip.nMinWidth)))
			{
				//alert("I'm quitting, direction = " + CurrentTip.bDirection + "CurrentTip.nBoxHeight = " + CurrentTip.nBoxHeight);
				CurrentTip.bGrowingOrShrinking = false;
				CurrentTip.nBoxHeight = (CurrentTip.bDirection) ? 
					CurrentTip.nMaxHeight : CurrentTip.nMinHeight;
				
				if (!CurrentTip.bDirection)
				{
					//alert("Resetting to blank");
					CurrentTip.TipBody.style.width = "";
					CurrentTip.TipBody.style.height = "";
					CurrentTip.Inner1.style.height = ""; 
					CurrentTip.Inner1.style.width = "";
					CurrentTip.Container.style.height = "";
					CurrentTip.Container.style.width = "";
					CurrentTip.Container.style.position = "";
					CurrentTip.Container.style.top = "";
					CurrentTip.Container.style.bottom = "";
					CurrentTip.Container.style.left = "";
					CurrentTip.Container.style.right = "";
					//if (CurrentTip.ParentContainer.insertBefore(CurrentTip.Container, CurrentTip.ComesBefore) == null)
					//	alert("insertBefore failed");
					KnowzyTips.splice(nIndex,1);
					//ArrangeColumns();
					return;
				}
				else if (bForceRepaint)
				{
					CurrentTip.Container.style.visibility = "hidden";
					setTimeout("RepaintTooltip(" + nIndex + ")", 1);
				}
					
			}

			CurrentTip.Container.style.height = CurrentTip.nBoxHeight + "px";
			var nInsideHeight = (CurrentTip.nBoxHeight - 20) >= 0 ?
				(CurrentTip.nBoxHeight - 20) : 0;
			CurrentTip.Inner1.style.height = nInsideHeight + "px";
			CurrentTip.TipBody.style.height = nInsideHeight + "px";

			setTimeout("AnimateKnowzyTooltips(" + nIndex + ")", CurrentTip.nDelay);
		}
	}
}

function RepaintTooltip(nIndex)
{
	KnowzyTips[nIndex].Container.style.visibility = "visible";
}

function CurrentTimeTicks()
{
	var KnzDate = new Date();
	return Math.floor(KnzDate.getTime());	
}

function FindKToolTipById(strTipDiv)
{
	var i = 0;
	for (i=0;i<KnowzyTips.length;i++)
	{
		if (KnowzyTips[i].Heading.id == strTipDiv)
			return KnowzyTips[i];
	}
	
	return null;
}

function GetTipIndex(TheTip)
{
	var i = 0;
	for (i=0;i<KnowzyTips.length;i++)
	{
		if (KnowzyTips[i] == TheTip)
			return i;
	}
	
	return 0;
}

function KalcMaxDimensions(TheTip)
{
	TheTip.Container.style.visibility = "hidden";
	TheTip.Container.style.width = TheTip.nMaxWidth + "px";
	TheTip.Inner1.style.width = (TheTip.nMaxWidth - 20) + "px";
	TheTip.TipBody.style.width = (TheTip.nMaxWidth - 20) + "px";

	TheTip.Container.style.height = "";
	TheTip.Inner1.style.height = "";
	TheTip.TipBody.style.height = "";
	
	TheTip.nMaxHeight = TheTip.Container.offsetHeight - 20;
}

function SetMinimums(TheTip)
{
	TheTip.Container.style.overflow = "hidden";
	TheTip.Container.style.height = TheTip.nMinHeight + "px";
	var nInsideHeight = (TheTip.nMinHeight - 20) >= 0 ? 
		(TheTip.nMinHeight - 20) : 0;
	TheTip.Inner1.style.height = nInsideHeight + "px";
	TheTip.TipBody.style.height = nInsideHeight + "px";

	TheTip.Container.style.width = TheTip.nMinWidth + "px";
	var nInsideWidth = (TheTip.nMinWidth - 20) >= 0 ? 
		(TheTip.nMinWidth - 20) : 0;
	TheTip.Inner1.style.width = nInsideWidth + "px";
	TheTip.TipBody.style.width = nInsideWidth + "px";
}

function PositionTip(TheTip, event, LinkElement)
{
	var nIELeftSideFudge = 0;
	//alert("clientY: " + event.clientY + "\nclientX: " + event.clientX + "\nMaxHeight: " + TheTip.nMaxHeight + "\n" + (LinkElement.offsetHeight + event.clientY + TheTip.nMaxHeight) + "<" + (BrowserHeight()) + "\nY: " + event.y + "\noffsetY: " + event.offsetY + "\ngetEltPageTop: " + (getEltPageTop(LinkElement)) + "\nLink Height: " + LinkElement.offsetHeight + "\nLink X Relative to Container:" + LinkElement.offsetLeft + "\nParent Padding Left: " + LinkElement.parentElement.style.paddingLeft);
	TheTip.Container.style.position = "absolute";

	if (typeof(LinkElement.offsetLeft) == 'number' && !(navigator.family == "gecko") && LinkElement.offsetLeft <= 45)
		nIELeftSideFudge = LinkElement.offsetHeight;

	if (LinkElement.offsetHeight + event.clientY + TheTip.nMaxHeight < BrowserHeight())
		TheTip.Container.style.top = (getEltPageTop(LinkElement) + LinkElement.offsetHeight + 5 + nIELeftSideFudge) + "px";
	else
		TheTip.Container.style.top = (getEltPageTop(LinkElement) - LinkElement.offsetHeight - 5 - TheTip.nMaxHeight + nIELeftSideFudge) + "px";

		
	if (event.clientX + TheTip.nMaxWidth < BrowserWidth())
		TheTip.Container.style.left = (event.clientX) + "px";
	else
		TheTip.Container.style.left = (BrowserWidth() - 40 - TheTip.nMaxWidth) + "px";
}

function BrowserHeight()
{
	return ConsistentBrowserDimension(false);
}

function BrowserWidth()
{
	return ConsistentBrowserDimension(true);
}

function ConsistentBrowserDimension(bWidth)
{
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' )
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}

	if (bWidth)
	{
		//alert("Width: " + myWidth);
		return myWidth;
	}
	else
	{
		//alert("Height: " + myHeight);
		return myHeight;
	}
}

function FindAbsoluteTop(TheElement)
{
	var nTop = 0;
	while (TheElement != null)
	{
		nTop+= TheElement.offsetX;
		TheElement = TheElement.parentNode;
	}
	
	return nTop;
}

/* xbrowser pageX equivalent

http://www.mozilla.org/docs/web-developer/csspapi/xbdhtml.txt

*/
function getEltPageLeft(elt) {
  var x;

  if ( typeof(elt.pageX) == 'number' )
    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;
}

/* xbrowser pageY equivalent */
function getEltPageTop(elt) {
  var y = 0;

  if ( typeof(elt.pageY) == 'number' )
    return elt.pageY;
//  if (is.ie4up)
//  {
    while (elt.offsetParent != null) {
      y += elt.offsetTop;
      elt = elt.offsetParent;
    }
    y += elt.offsetTop;
    return y;
//  }

  /* ie5/mac modification added per comment from David Weingard */
/*  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;
}