var TooltipArray = new Array();

/************************************************************************************************************
(C) www.dhtmlgoodies.com, October 2005

This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.
www.dhtmlgoodies.com

************************************************************************************************************/
var dhtmlgoodies_tooltip = false;
var dhtmlgoodies_tooltipShadow = false;
var dhtmlgoodies_shadowSize = 4;
var dhtmlgoodies_tooltipMaxWidth = 300;
var dhtmlgoodies_tooltipMinWidth = 100;
var dhtmlgoodies_iframe = false;
var tooltipTimerId = -1;
var tooltip_is_msie = (navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('opera')==-1 && document.all)?true:false;

function showTooltip(e, arrayIndex)
{
	var nIndex = parseInt(arrayIndex);
	tooltipTxt = TooltipArray[nIndex];
	if (tooltipTxt == "")
	{
		return;
	}

	var bodyWidth = Math.max(document.body.clientWidth,document.documentElement.clientWidth) - 20;
	var bodyHeight = Math.min(document.body.clientHeight,document.documentElement.clientHeight) - 5;

	if(!dhtmlgoodies_tooltip){
		dhtmlgoodies_tooltip = document.createElement('DIV');
		dhtmlgoodies_tooltip.id = 'dhtmlgoodies_tooltip';
		dhtmlgoodies_tooltip.onmouseover = stopTooltipTimer;
		dhtmlgoodies_tooltip.onmouseout = mouseOutTooltip;
		
		dhtmlgoodies_tooltipShadow = document.createElement('DIV');
		dhtmlgoodies_tooltipShadow.id = 'dhtmlgoodies_tooltipShadow';

		document.body.appendChild(dhtmlgoodies_tooltip);
		document.body.appendChild(dhtmlgoodies_tooltipShadow);

		if(tooltip_is_msie){
			dhtmlgoodies_iframe = document.createElement('IFRAME');
			dhtmlgoodies_iframe.frameborder='5';
			dhtmlgoodies_iframe.style.backgroundColor='#FFFFFF';
			dhtmlgoodies_iframe.src = '#';
			dhtmlgoodies_iframe.style.zIndex = 100;
			dhtmlgoodies_iframe.style.position = 'absolute';
			document.body.appendChild(dhtmlgoodies_iframe);
		}
	}
	else {
		stopTooltipTimer();
	}

	dhtmlgoodies_tooltip.style.display='block';
	dhtmlgoodies_tooltipShadow.style.display='block';
	if(tooltip_is_msie) dhtmlgoodies_iframe.style.display='block';

	//Chrome uses document.body.scrollTop
	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	//if(navigator.userAgent.toLowerCase().indexOf('safari')>=0) st=0;
	var leftPos = e.clientX + 10;
	var topPos = e.clientY + 3 + st;

	dhtmlgoodies_tooltip.style.width = null;		// Reset style width if it's set
	dhtmlgoodies_tooltip.innerHTML = tooltipTxt;
	dhtmlgoodies_tooltip.style.left = leftPos + 'px';
	dhtmlgoodies_tooltip.style.top = topPos + 'px';

	dhtmlgoodies_tooltipShadow.style.left = leftPos + dhtmlgoodies_shadowSize + 'px';
	dhtmlgoodies_tooltipShadow.style.top = topPos + dhtmlgoodies_shadowSize + 'px';

	if(dhtmlgoodies_tooltip.offsetWidth>dhtmlgoodies_tooltipMaxWidth){	// Exceeding max width of tooltip?
		dhtmlgoodies_tooltip.style.width = dhtmlgoodies_tooltipMaxWidth + 'px';
	}

	var tooltipWidth = dhtmlgoodies_tooltip.offsetWidth;
	if(tooltipWidth<dhtmlgoodies_tooltipMinWidth)tooltipWidth = dhtmlgoodies_tooltipMinWidth;

	dhtmlgoodies_tooltip.style.width = tooltipWidth + 'px';
	dhtmlgoodies_tooltipShadow.style.width = dhtmlgoodies_tooltip.offsetWidth + 'px';
	dhtmlgoodies_tooltipShadow.style.height = dhtmlgoodies_tooltip.offsetHeight + 'px';

	var tooltipHeight = dhtmlgoodies_tooltip.offsetHeight;

	if((leftPos + tooltipWidth) > bodyWidth){
		dhtmlgoodies_tooltip.style.left = (dhtmlgoodies_tooltipShadow.style.left.replace('px','') - ((leftPos + tooltipWidth)-bodyWidth)) + 'px';
		dhtmlgoodies_tooltipShadow.style.left = (dhtmlgoodies_tooltipShadow.style.left.replace('px','') - ((leftPos + tooltipWidth)-bodyWidth) + dhtmlgoodies_shadowSize) + 'px';
	}

	bodyBottom = bodyHeight + st;
	if((topPos + tooltipHeight) > bodyBottom){
		//alert("topPos=" + topPos + ", tooltipHeight=" + tooltipHeight + ", bodyBottom=" + bodyBottom + ", e.clientY=" + e.clientY + ", st=" + st);
		dhtmlgoodies_tooltip.style.top = (dhtmlgoodies_tooltipShadow.style.top.replace('px','') - ((topPos + tooltipHeight)-bodyBottom)) + 'px';
		dhtmlgoodies_tooltipShadow.style.top = (dhtmlgoodies_tooltipShadow.style.top.replace('px','') - ((topPos + tooltipHeight)-bodyBottom) + dhtmlgoodies_shadowSize) + 'px';
	}

	if(tooltip_is_msie){
		dhtmlgoodies_iframe.style.left = dhtmlgoodies_tooltip.style.left;
		dhtmlgoodies_iframe.style.top = dhtmlgoodies_tooltip.style.top;
		dhtmlgoodies_iframe.style.width = dhtmlgoodies_tooltip.offsetWidth + 'px';
		dhtmlgoodies_iframe.style.height = dhtmlgoodies_tooltip.offsetHeight + 'px';

	}
}

function hideTooltip()
{
	dhtmlgoodies_tooltip.style.display='none';
	dhtmlgoodies_tooltipShadow.style.display='none';
	if(tooltip_is_msie) dhtmlgoodies_iframe.style.display='none';
	if (tooltipTimerId >= 0) {
		clearTimeout(tooltipTimerId);
		tooltipTimerId = -1;
	}
}

//If the mouse is moved over the tooltip then turn off the timer that closes
//the tooltip since we want to keep it displayed.
function stopTooltipTimer() {
	if (tooltipTimerId >= 0) {
		clearTimeout(tooltipTimerId);
		tooltipTimerId = -1;
	}
}


function mouseOutTooltip(e) {
	var evt = e||window.event;		//IE will use window.event
	var mouseInTooltip = false;
	var element = null;
	if (evt.toElement!=null) {		//IE
		element = evt.toElement;
	}
	else if (evt.relatedTarget!=null) {	//Firefox
		element = evt.relatedTarget;
	}
	else if (evt.target!=null) {
		element = evt.target;
	}
	//Since the onmouseout event is fired when moving over the elements
	//in the tooltip, we need to bubble up through the parent elements
	//to determine if the mouse is still in the tooltip. If one of the 
	//parent elements is "dhtmlgoodies_tooltip" then we're still in the tooltip.
	while (element) {
		//alert(element.id + ", " + element.tagName);
		if (element.id == "dhtmlgoodies_tooltip") { //the mouse is still in the tooltip
			mouseInTooltip = true;
			break;
		}
		element = element.parentNode;
	}
	if (mouseInTooltip==false)
	{
		//alert('out of div');
		hideTooltip();
	}	
}


function startHideTooltipTimer() {
	tooltipTimerId = setTimeout('timerHideTooltip()', 250);
}

//When the timer fires this event close the tooltip
function timerHideTooltip() {
	tooltipTimerId = -1;	//timer fired, so reset tooltipTimerId 
	hideTooltip();
}


/************************************************************************************************************

Show a popup DIV for displaying content (news and calendar items).

************************************************************************************************************/

var content_popup = false;
var background_popup = false;
//var content_popupShadow = false;
//var content_popup_shadowSize = 4;
var content_popupMaxWidth = 300;
var content_popupMinWidth = 100;
var content_iframe = false;

/*
//If width or height are <=0 then size them at 80% of the client window.
function showContentPopup(contentHtml, left, top, width, height)
{
	var bodyWidth = Math.max(document.body.clientWidth,document.documentElement.clientWidth) - 20;
	var bodyHeight = Math.min(document.body.clientHeight,document.documentElement.clientHeight) - 5;

	if(!content_popup){
		content_popup = document.createElement('DIV');
		content_popup.id = 'content_popup';
		content_popup.style.display="none";		//added for testing fade-in
		//content_popup.style.overflow = 'auto';	//set in CSS
		content_popupShadow = document.createElement('DIV');
		content_popupShadow.id = 'content_popupShadow';

		document.body.appendChild(content_popup);
		document.body.appendChild(content_popupShadow);

		if(tooltip_is_msie){
			content_iframe = document.createElement('IFRAME');
			content_iframe.frameborder='5';
			content_iframe.style.backgroundColor='#FFFFFF';
			content_iframe.src = '#';
			content_iframe.style.zIndex = 100;
			content_iframe.style.position = 'absolute';
			document.body.appendChild(content_iframe);
		}
	}

	//$('content_popup').appear();
	content_popup.style.display='block';
	content_popupShadow.style.display='block';
	if(tooltip_is_msie) content_iframe.style.display='block';

	//Chrome uses document.body.scrollTop
	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	//if(navigator.userAgent.toLowerCase().indexOf('safari')>=0) st=0;

	var computedWidth = bodyWidth * 0.8;
	var computedHeight = bodyHeight * 0.8;
	var computedLeft = Math.round((bodyWidth - computedWidth) / 2);
	var computedTop = Math.round((bodyHeight - computedHeight) / 2);
	computedTop += st;


	content_popup.style.width = null;		// Reset style width if it's set
	//content_popup.innerHTML = contentHtml;
	content_popup.style.left = computedLeft + 'px';
	content_popup.style.top = computedTop + 'px';

	shadowLeft = computedLeft + content_popup_shadowSize;
	shadowTop = computedTop + content_popup_shadowSize;
	content_popupShadow.style.left = shadowLeft + 'px';
	content_popupShadow.style.top = shadowTop + 'px';

	//if(content_popup.offsetWidth>content_popupMaxWidth){	// Exceeding max width of tooltip?
	//	content_popup.style.width = content_popupMaxWidth + 'px';
	//}

	//var tooltipWidth = content_popup.offsetWidth;
	//if(tooltipWidth<content_popupMinWidth)tooltipWidth = content_popupMinWidth;

	content_popup.style.width = computedWidth + 'px';
	content_popup.style.height = computedHeight + 'px';
	content_popupShadow.style.width = content_popup.offsetWidth + 'px';
	content_popupShadow.style.height = content_popup.offsetHeight + 'px';

	content_popup.innerHTML = contentHtml;

	var tooltipHeight = content_popup.offsetHeight;

	//if((leftPos + tooltipWidth) > bodyWidth){
	//	content_popup.style.left = (content_popupShadow.style.left.replace('px','') - ((leftPos + tooltipWidth)-bodyWidth)) + 'px';
	//	content_popupShadow.style.left = (content_popupShadow.style.left.replace('px','') - ((leftPos + tooltipWidth)-bodyWidth) + content_popup_shadowSize) + 'px';
	//}

	//bodyBottom = bodyHeight + st;
	//if((topPos + tooltipHeight) > bodyBottom){
	//	//alert("topPos=" + topPos + ", tooltipHeight=" + tooltipHeight + ", bodyBottom=" + bodyBottom + ", e.clientY=" + e.clientY + ", st=" + st);
	//	content_popup.style.top = (content_popupShadow.style.top.replace('px','') - ((topPos + tooltipHeight)-bodyBottom)) + 'px';
	//	content_popupShadow.style.top = (content_popupShadow.style.top.replace('px','') - ((topPos + tooltipHeight)-bodyBottom) + content_popup_shadowSize) + 'px';
	//}

	if(tooltip_is_msie){
		content_iframe.style.left = content_popup.style.left;
		content_iframe.style.top = content_popup.style.top;
		content_iframe.style.width = content_popup.offsetWidth + 'px';
		content_iframe.style.height = content_popup.offsetHeight + 'px';

	}
}

function hideContentPopup()
{
	content_popup.style.display='none';
	content_popupShadow.style.display='none';
	if(tooltip_is_msie) content_iframe.style.display='none';
}
*/



//0 means disabled (hidden); 1 means enabled (shown);
var constPopupHidden = 0;
var constPopupShown = 1;
var popupStatus = constPopupHidden;

$(document).ready(function(){
	//This didn't work here, so added background_popup.onclick below when creating the DIV
	//Close the popup if the user clicks on the darkened background behind the popup
	//$("#background_popup").click(function(){
	//	hideContentPopupFading();
	//});

	//Close the popup if the user presses Escape
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==constPopupShown){
			hideContentPopupFading();
		}
	});
});

//If width or height are <0 then size them at 80% of the client window.
function showContentPopupFading(contentHtml, left, top, width, height)
{
	var bodyWidth = Math.max(document.body.clientWidth,document.documentElement.clientWidth) - 20;
	var bodyHeight = Math.min(document.body.clientHeight,document.documentElement.clientHeight) - 5;

	if(!content_popup){
		content_popup = document.createElement('DIV');
		content_popup.id = 'content_popup';
		//content_popup.style.display="none";		//added for testing fade-in
		//content_popup.style.overflow = 'auto';	//set in CSS

		background_popup = document.createElement('DIV');
		background_popup.id = 'background_popup';
		background_popup.onclick = hideContentPopupFading; //Close the popup if the user clicks on the darkened background behind the popup

		document.body.appendChild(content_popup);
		document.body.appendChild(background_popup);

		/*
		if(tooltip_is_msie){
			content_iframe = document.createElement('IFRAME');
			content_iframe.frameborder='5';
			content_iframe.style.backgroundColor='#FFFFFF';
			content_iframe.src = '#';
			content_iframe.style.zIndex = 100;
			content_iframe.style.position = 'absolute';
			document.body.appendChild(content_iframe);
		}
		*/
	}

	//if(tooltip_is_msie) content_iframe.style.display='block';

	//Chrome uses document.body.scrollTop
	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	//if(navigator.userAgent.toLowerCase().indexOf('safari')>=0) st=0;

	var computedWidth = bodyWidth * 0.8;
	var computedHeight = bodyHeight * 0.85;
	var computedLeft = Math.round((bodyWidth - computedWidth) / 2);
	var computedTop = Math.round((bodyHeight - computedHeight) / 2);
	if (computedTop > 10) {
		computedTop = 20;
	}
	computedTop += st;

	content_popup.style.left = computedLeft + 'px';
	content_popup.style.top = computedTop + 'px';

	//if(content_popup.offsetWidth>content_popupMaxWidth){	// Exceeding max width of tooltip?
	//	content_popup.style.width = content_popupMaxWidth + 'px';
	//}

	//var tooltipWidth = content_popup.offsetWidth;
	//if(tooltipWidth<content_popupMinWidth)tooltipWidth = content_popupMinWidth;

	content_popup.style.width = computedWidth + 'px';
	content_popup.style.height = computedHeight + 'px';

	//background_popup.style.width = bodyWidth + 'px';
	//background_popup.style.height = bodyHeight + 'px';  //possibly need this for IE6

	content_popup.innerHTML = contentHtml;

	/*
	if(tooltip_is_msie) {
		content_iframe.style.left = content_popup.style.left;
		content_iframe.style.top = content_popup.style.top;
		content_iframe.style.width = content_popup.offsetWidth + 'px';
		content_iframe.style.height = content_popup.offsetHeight + 'px';

	}
	*/

	//$('#content_popup').fadeIn(750);
	/*
	$('#content_popup').fadeIn(750, function() {
		//animation complete, so change the opacity of the main page
		var wrapperDiv = document.getElementById("wrapperHome");
		if (wrapperDiv) {
			//alert("setting filter");
			wrapperDiv.style.filter = "alpha(opacity=30)";
			wrapperDiv.style.opacity = "0.3";
		}
	});
	*/
	
	
	//loads popup only if it is disabled
	if(popupStatus==constPopupHidden){
		$("#background_popup").css({
			"opacity":"0.7", "filter":"alpha(opacity=70)"
		});
		$("#background_popup").fadeIn(750);
		$("#content_popup").fadeIn(750);
		popupStatus = constPopupShown;
	}
}

function hideContentPopupFading()
{
	/*
	var wrapperDiv = document.getElementById("wrapperHome");
	if (wrapperDiv) {
		wrapperDiv.style.filter = "alpha(opacity=100)";
		wrapperDiv.style.opacity = "1.0";
	}
	*/

	//$('#content_popup').fadeOut(500);
	//content_popup.style.display='none';
	//if(tooltip_is_msie) content_iframe.style.display='none';
	
	//disables popup only if it is enabled  
	if(popupStatus==constPopupShown){  
		$("#background_popup").fadeOut(750);  
		$("#content_popup").fadeOut(750);  
		popupStatus = constPopupHidden;  
	}	
}







/************************************************************************************************************

Functions to fade the content DIV in and out.

************************************************************************************************************/

/* Not being used at this time

var TimeToFade = 750.0;
var const_ElementOpaque = 2;
var const_ElementTransparent = -2;
var const_FadingTransparentToOpaque = 1;
var const_FadingOpaqueToTransparent = -1;

function fade(eid)
{
	var element = document.getElementById(eid);
	if(element == null)
		return;

	if(element.FadeState == null) {
		if(element.style.opacity == null
		|| element.style.opacity == ''
		|| element.style.opacity == '1') {
			element.FadeState = const_ElementTransparent;
		}
		else {
			element.FadeState = const_ElementOpaque;
		}
	}

	if(element.FadeState == const_FadingTransparentToOpaque || element.FadeState == const_FadingOpaqueToTransparent) {
		element.FadeState = element.FadeState == const_FadingTransparentToOpaque ? const_FadingOpaqueToTransparent : const_FadingTransparentToOpaque;
		element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
	}
	else {
		element.FadeState = element.FadeState == const_ElementOpaque ? const_FadingOpaqueToTransparent : const_FadingTransparentToOpaque;
		element.FadeTimeLeft = TimeToFade;
		element.style.display = element.FadeState == const_ElementOpaque ? 'none' : 'block';
		setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33);
	}
}


function animateFade(lastTick, eid)
{
	var curTick = new Date().getTime();
	var elapsedTicks = curTick - lastTick;

	var element = document.getElementById(eid);

	if(element.FadeTimeLeft <= elapsedTicks)
	{
		element.style.display = element.FadeState == const_FadingTransparentToOpaque ? 'block' : 'none';
		element.style.opacity = element.FadeState == const_FadingTransparentToOpaque ? '1' : '0';
		element.style.filter = 'alpha(opacity = ' + (element.FadeState == const_FadingTransparentToOpaque ? '100' : '0') + ')';
		element.FadeState = element.FadeState == const_FadingTransparentToOpaque ? const_ElementOpaque : const_ElementTransparent;
		return;
	}

	element.FadeTimeLeft -= elapsedTicks;
	var newOpVal = element.FadeTimeLeft/TimeToFade;
	if(element.FadeState == const_FadingTransparentToOpaque)
		newOpVal = 1 - newOpVal;

	element.style.opacity = newOpVal;
	element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';

	setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}
*/
