
/* *******************************************
*	Copyright © 2002-2009 ExpoCharger International, Inc. All rights reserved
* ****************************************** */


//depends on mouseTrack.js, events.js [,ECI-util.js]

var tipContainer = null;
var tipFollowsMouse = true;
var TIP_OFFSET_X = 15;//formerly offsetX
var TIP_OFFSET_Y = 20;
var ZINDEX_TOOLTIP=2000;
var mt_mousemoveListenerId=null;

//doesTipFollowMouse can be omitted.
function initToolTips(myTipContainer,doesTipFollowMouse){
	if(!(document.getElementById || document.all))
		return;		

	tipContainer = myTipContainer;
	tipFollowsMouse = (doesTipFollowMouse==false)?false:true;
	mt_mousemoveListenerId = registerMouseMoveListener(moveTipToMouse);
	tipContainer.zIndex = ZINDEX_TOOLTIP;
	
}

//move tipcontainer to mouse postion
function moveTipToMouse(ev)
{
	if(!tipContainer)
		return;
	ev = ev || window.event;
	var mousePosition = currentMousePoint;//use mousetrack currentMousePoint field.
	var tipTopLeft = {x:mousePosition.x,y:mousePosition.y};//start at mouse cursor	
	tipTopLeft.x += TIP_OFFSET_X;//nudge away from from mousepos
	tipTopLeft.y -= TIP_OFFSET_Y;

	var tipWidth = tipContainer.scrollWidth;
	var tipHeight = tipContainer.scrollHeight;	
	var viewWidth = document.body.clientWidth + document.body.scrollLeft;
	var viewHeight = document.body.clientHeight + document.body.scrollTop;
	
	//if tip runs off the screen to the right,
	// then flip tip to left of mousepos
	if (tipTopLeft.x + tipWidth > viewWidth){
		tipTopLeft.x = (tipTopLeft.x - tipWidth) - TIP_OFFSET_X * 2;
	}
	if (tipTopLeft.y + tipHeight > viewHeight){
		tipTopLeft.y  = mousePosition.y - tipHeight;
	}	
	//if tip.x is off the view to the left, nudge it left
	if (tipTopLeft.x < document.body.scrollLeft){
		tipTopLeft.x = document.body.scrollLeft;
	}
	if (tipTopLeft.y < document.body.scrollTop){
		tipTopLeft.y = document.body.scrollTop;
	}
	//don't cover up the cursor (prevents clicking on the booth)
	if(tipTopLeft.x < mousePosition.x && (tipTopLeft.x + tipWidth) > mousePosition.x
		&& tipTopLeft.y < mousePosition.y && (tipTopLeft.y + viewHeight) > mousePosition.y){
		tipTopLeft.x = mousePosition.x + TIP_OFFSET_X;
	}
	
	//move tip to new position (Always move when not visible. Always move if tipFollowsMouse)(don't move if tip is visible and doesn't follow the mouse).
	if(tipFollowsMouse || !ECI.isItemVisible(tipContainer)){
		tipContainer.style.left = tipTopLeft.x + "px";
		tipContainer.style.top = tipTopLeft.y + "px";
	}
		
  return true;
}
//set tip content.  show or hide tip
function toolTip(msg)
{
	if(!tipContainer)
		return;
	if(!msg){ 
		// hide
		ECI.setItemVisible(tipContainer,false);
		return;
	}
	//show
	var content = '<table border="0" cellspacing="0" cellpadding="1" ><td align="left"  class="#0#" NOWRAP>#1#</td></table>';
	var className = tipContainer.className;
	content = content.replace(/#0#/g,className);
	content = content.replace(/#1#/g,msg);
	
	tipContainer.innerHTML = content;
	if(tipContainer.filters && tipContainer.filters.blendTrans) tipContainer.filters.blendTrans.Apply();
	if(tipContainer.filters && tipContainer.filters.revealTrans) tipContainer.filters.revealTrans.Apply();
	ECI.setItemVisible(tipContainer,true);
	if(tipContainer.filters && tipContainer.filters.blendTrans) tipContainer.filters.blendTrans.Play();
	if(tipContainer.filters && tipContainer.filters.revealTrans) tipContainer.filters.revealTrans.Play();
			
}
//
//tooltip for exhibitor list
function toolTipExhibList(imgFolderUrl,imgFileName,imgWidth,imgHeight,coName,coProfile,boothNumbers,productNames,pinToTop,targetItem)
{
	if(!tipContainer)
		return;
		
		
	var tipContent = "";
	var imgDimensionString = "";
	var tdWidth = imgWidth;
	if (imgFileName.length > 0)
	{
		if( (parseInt(imgWidth) > 150) || (parseInt(imgHeight) > 150) )
		{
			if( parseInt(imgWidth) > parseInt(imgHeight) )
			{
				imgDimensionString = "width=150";
				tdWidth = 150;
			}
			else {
				imgDimensionString = "height=150";
				tdWidth = Math.ceil(imgWidth/imgHeight * 150);
			}
		}
		//tooltip with image
		tipContent = "<table border=1 cellspacing=0 cellpadding=0 width=400>"
				+ "<tr><td class=#0#><table border=0 cellspacing=0 cellpadding=0 width=100%>"
				+ "<tr><td valign=middle width=#5#><img src=#1# #2# border=0 /></td>"
				+ "<td valign=top class=#6#><b>#3#</b><br /><br />#4#</td></tr><table>"
				+ "</td></tr></table>";
	} 
	else 
	{
		//no image
		tipContent = "<table border=1 cellspacing=0 cellpadding=0 width=400>"
				+ "<tr><td class=#0#><table border=0 cellspacing=0 cellpadding=0 width=100%>"
				+ "<tr><td class=#6#><b>#3#</b>"
				+ "<br /><br />#4#</td></tr><table>"
				+ "</td></tr></table>";
	}
	
	
	if(coProfile.length > 250)
	{
		//find a word break
		var cutoff = Math.max(coProfile.indexOf(" ",249),240);
		//trim the profile
		coProfile = coProfile.substr(0,cutoff) + " ...";
	}
	
	var classBg="attEcListBgFlyOver"; //background
	var classFg="attEcListFgFlyOver"; //foreground
	
	tipContent = tipContent.replace(/#0#/g,classBg);
	tipContent = tipContent.replace(/#6#/g,classFg);
	tipContent = tipContent.replace(/#1#/g,imgFolderUrl + imgFileName);
	tipContent = tipContent.replace(/#2#/g,imgDimensionString);
	tipContent = tipContent.replace(/#3#/g,coName);
	tipContent = tipContent.replace(/#4#/g,coProfile);
	tipContent = tipContent.replace(/#5#/g,tdWidth);

	tipContainer.innerHTML = tipContent;
	if(tipContainer.filters && tipContainer.filters.blendTrans) tipContainer.filters.blendTrans.Apply();
	if(tipContainer.filters && tipContainer.filters.revealTrans) tipContainer.filters.revealTrans.Apply();
	ECI.setItemVisible(tipContainer,true);	
	if(tipContainer.filters && tipContainer.filters.blendTrans) tipContainer.filters.blendTrans.Play();
	if(tipContainer.filters && tipContainer.filters.revealTrans) tipContainer.filters.revealTrans.Play();
	
	/* try to position the tip beyond the end of the company name */	
	if(!tipFollowsMouse && targetItem){
		tipContainer.style.left = (ECI.getOffsetLeft(targetItem) + targetItem.offsetWidth + 5) + "px";
		tipContainer.style.top = (ECI.getOffsetTop(targetItem) + 3) + "px";
		if (parseInt(tipContainer.style.top) + tipContainer.scrollHeight > document.body.clientHeight + document.body.scrollTop){
			tipContainer.style.top = parseInt(tipContainer.style.top) - tipContainer.scrollHeight - 2  + "px";
		}	
	}
}

var sessionTemplate = 
	"<div style=\"border: solid 1px black;\">"
	+ "<table width=\"450\" cellspacing=\"0\" cellpadding=\"5\" border=\"0\" style=\"border-bottom: solid 1px black;\" bgcolor=\"#bgcolor#\">"
	+ "<tr valign=\"middle\">"
	+	"	<td><span style=\"color: #fgcolor#\" class=\"infoTitle\">#title#</span></td>"
	+ "</tr>"
	+ "<tr valign=\"top\">"
	+	"	<td><span style=\"color: #fgcolor#\" class=\"infoTagline\" />#tagline#</td>"
	+ "</tr>"
	+ "<tr valign=\"top\">"
	+	"	<td ><span style=\"color: #fgcolor#\" class=\"infoValue\" >#date# <br/>#starttime# - #endtime#</span></td>"
	+ "</tr>"
	+ "<tr valign=\"top\">"
	+	"	<td ><span style=\"color: #fgcolor#\" class=\"infoValue\" >#location#</span></td>"
	+ "</tr>"
	+ "</table>"
	+ "<table width=\"450\" cellspacing=\"0\" cellpadding=\"5\" border=\"0\" >"
	+ "<tr>"
	+	"	<td class=\"ccListFlyBG\">"
	+	"		<span class=\"infoBlurb\">#description#</span>"
	+ "	</td>"
	+ "</tr>"
	+ "</table>"
	+ "</div>";
 
function toolTipSession(itemtype,title,tagline,description,date,starttime,endtime,location,colorText,colorBackground,targetItem)
{
	if(!tipContainer)
		return;
		
	if(description.length > 250)
	{
		//find a word break
		var cutoff = Math.max(description.indexOf(" ",249),240);
		//trim the description
		description = description.substr(0,cutoff) + " ...";
	}		
	if(!colorBackground){
		//Breaks need a background color.
		colorBackground = document.body.bgColor?document.body.bgColor:document.bgColor?document.bgColor:"white";		
	}

	var content=sessionTemplate.replace(/#itemtype#/g,itemtype);
	content=content.replace(/#title#/g,title);
	content=content.replace(/#tagline#/g,tagline);
	content=content.replace(/#description#/g,description);
	content=content.replace(/#date#/g,date);
	content=content.replace(/#starttime#/g,starttime);
	content=content.replace(/#endtime#/g,endtime);
	content=content.replace(/#location#/g,location);
	content=content.replace(/#fgcolor#/g,colorText);
	content=content.replace(/#bgcolor#/g,colorBackground);
		

	tipContainer.innerHTML = content;
	if(tipContainer.filters && tipContainer.filters.blendTrans) tipContainer.filters.blendTrans.Apply();
	if(tipContainer.filters && tipContainer.filters.revealTrans) tipContainer.filters.revealTrans.Apply();
	ECI.setItemVisible(tipContainer,true);
	if(tipContainer.filters && tipContainer.filters.blendTrans) tipContainer.filters.blendTrans.Play();
	if(tipContainer.filters && tipContainer.filters.revealTrans) tipContainer.filters.revealTrans.Play();
		
	/* position the tip beyond the end of the flyover hotspot */	
	if(!tipFollowsMouse && targetItem){
		tipContainer.style.left = (ECI.getOffsetLeft(targetItem) + targetItem.offsetWidth + 5) + "px";
		tipContainer.style.top = (ECI.getOffsetTop(targetItem) + 3) + "px";
		if (parseInt(tipContainer.style.top) + tipContainer.scrollHeight > document.body.clientHeight + document.body.scrollTop){
			tipContainer.style.top = parseInt(tipContainer.style.top) - tipContainer.scrollHeight - 2  + "px";
		}	
	}	
}

	
var speakerTemplate = 	
"<div style=\"border: solid 1px black;\">"
+ "<TABLE cellspacing=\"0\" cellpadding=\"5\" width=\"445\" border=\"0\" class=\"ccListFlyBG\">"
+ "<TR vAlign=top>"
+ "<TD align=left rowSpan=\"2\"><img src=\"#photoUrl#\" width=\"100\" style=\"display:#photoDisplay#\" /></TD>"
+ "<TD align=left><span class=\"infoTitle\">#salutation# #firstName# #middle# #lastName# #suffix#</span>"
+ "<BR><span class=\"infoTagline\">#title#</span>"
+ "<BR><span class=\"infoOrg\">#organization#</span>"
+ "</TD></TR>"
+ "<TR vAlign=top>"
+ "<TD><span class=\"infoBlurb\">#bio#</span></TD></TR>"
+ "</TABLE>"
+ "</div>";

function toolTipSpeaker(photoUrl,salutation,firstName,middle,lastName,suffix,title,organization,bio,targetItem)
{
	if(!tipContainer)
		return;
		
	if(bio.length > 250)
	{
		//find a word break
		var cutoff = Math.max(bio.indexOf(" ",249),240);
		//trim the description
		bio = bio.substr(0,cutoff) + " ...";
	}		

	var photoDisplay="inline;";
	if(!(photoUrl && photoUrl.length>0))
		photoDisplay="none;";
	var content=speakerTemplate.replace(/#photoUrl#/g,photoUrl);
	content=content.replace(/#photoDisplay#/g,photoDisplay);
	content=content.replace(/#salutation#/g,salutation);
	content=content.replace(/#firstName#/g,firstName);
	content=content.replace(/#middle#/g,middle);
	content=content.replace(/#lastName#/g,lastName);
	content=content.replace(/#suffix#/g,suffix);
	content=content.replace(/#title#/g,title);
	content=content.replace(/#organization#/g,organization);
	content=content.replace(/#bio#/g,bio);
		

	tipContainer.innerHTML = content;
	if(tipContainer.filters && tipContainer.filters.blendTrans) tipContainer.filters.blendTrans.Apply();
	if(tipContainer.filters && tipContainer.filters.revealTrans) tipContainer.filters.revealTrans.Apply();
	ECI.setItemVisible(tipContainer,true);
	if(tipContainer.filters && tipContainer.filters.blendTrans) tipContainer.filters.blendTrans.Play();
	if(tipContainer.filters && tipContainer.filters.revealTrans) tipContainer.filters.revealTrans.Play();
		
	/* position the tip beyond the end of the flyover hotspot */	
	if(!tipFollowsMouse && targetItem){
		tipContainer.style.left = (ECI.getOffsetLeft(targetItem) + targetItem.offsetWidth + 5) + "px";
		tipContainer.style.top = (ECI.getOffsetTop(targetItem) + 3) + "px";
		if (parseInt(tipContainer.style.top) + tipContainer.scrollHeight > document.body.clientHeight + document.body.scrollTop){
			tipContainer.style.top = parseInt(tipContainer.style.top) - tipContainer.scrollHeight - 2  + "px";
		}	
	}	
}

//tooltip for addins (AHA...)
function toolTipFgBg(msg,cssClassFg,cssClassBg,targetItem)
{
	if(!tipContainer)
		return;
				
		if(msg=="")
			msg = "&nbsp\;";
		var content;
		if(toolTipFgBg.arguments.length > 2)
		{
			content = '<table border="0" cellspacing="0" cellpadding="1" width="400">' + 
			'<td align="left"  class="' + cssClassBg + '"><div class="' + cssClassFg + '">' + msg +  '</div></td></table>';	
		} 
		else 
		{
			content = '<table border="0" cellspacing="0" cellpadding="1" >' + 
				'<td align="left"  class="' + CssClassName + '" >' + msg +  '</td></table>';
		}
		
	tipContainer.innerHTML = content;
	if(tipContainer.filters && tipContainer.filters.blendTrans) tipContainer.filters.blendTrans.Apply();
	if(tipContainer.filters && tipContainer.filters.revealTrans) tipContainer.filters.revealTrans.Apply();
	ECI.setItemVisible(tipContainer,true);
	if(tipContainer.filters && tipContainer.filters.blendTrans) tipContainer.filters.blendTrans.Play();
	if(tipContainer.filters && tipContainer.filters.revealTrans) tipContainer.filters.revealTrans.Play();
		
	/* position the tip beyond the end of the flyover hotspot */	
	if(!tipFollowsMouse && targetItem){
		tipContainer.style.left = (ECI.getOffsetLeft(targetItem) + targetItem.offsetWidth + 5) + "px";
		tipContainer.style.top = (ECI.getOffsetTop(targetItem) + 3) + "px";
		if (parseInt(tipContainer.style.top) + tipContainer.scrollHeight > document.body.clientHeight + document.body.scrollTop){
			tipContainer.style.top = parseInt(tipContainer.style.top) - tipContainer.scrollHeight - 2  + "px";
		}	
	}	
  
}
