//*******************************************************************************************
//****************************** ROLLOVER SCRIPTING: BEGIN **********************************
//*******************************************************************************************
var hintData = [];
var hintActive = false;
var hideTimer = null;

function delayedHide()
{
	hintActive = false;
	hobj = document.getElementById('rollover');
	lobj = document.getElementById('locker');
	if (!lobj) return;
	hobj.style.visibility = 'hidden';
	hobj.innerHTML = "";
	lobj.style.visibility = 'hidden';
	lobj.innerHTML = "";
	window.clearTimeout(hideTimer);
	hideTimer = null;
}

function cancelHide()
{
	window.clearTimeout(hideTimer);
	hideTimer = null;
}

function measureText(x, y, tit, cnt)
{
	mobj = document.getElementById('measurer');
	if (!mobj) return;
	mobj.style.left = ""+x+"px";
	mobj.style.top = ""+y+"px";
	innerStr = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' width='8' height='8' align='left'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='../swfs/measure.swf?tit="+tit+"&cnt="+cnt+"&w=150' /><param name='menu' value='false' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><param name='scale' value='noscale' /><param name='salign' value='lt' /><param name='bgcolor' value='#ffffff' /><embed src='../swfs/measure.swf?tit="+tit+"&cnt="+cnt+"&w=150' menu='false' quality='high' wmode='transparent' scale='noscale' salign='lt' bgcolor='#ffffff' width='8' height='8' align='left' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
	mobj.innerHTML = innerStr;
}

function onTextMeasured(w,h)
{
	mobj = document.getElementById('measurer');
	mobj.innerHTML = "";
	//alert("Text measured: ["+w+", "+h+"]");
	if (hintActive) finishHint(w, h);
}

function hint(e, tit, cnt, glossaryLink)
{
	if ((tit+cnt)=='')  
	{
		hideTimer = window.setTimeout("delayedHide()", 100);
		return;
	}
	//event page coordinates
	if (document.all)
	{
		rX = e.clientX + document.body.scrollLeft;
		rY = e.clientY + document.body.scrollTop;
	}
	else
	{
		rX = e.pageX;
		rY = e.pageY;
	}
	//store hint data
	hintData = [e.clientX, e.clientY, rX, rY, tit, cnt, glossaryLink];
	hintActive = true;
	measureText(rX+10, rY+10, tit, cnt);
}

function finishHint(w, h)
{
	hobj = document.getElementById('rollover');
	lobj = document.getElementById('locker');
	cX = hintData[0];
	cY = hintData[1];
	rX = hintData[2];
	rY = hintData[3];
	tit = hintData[4];
	cnt = hintData[5];
	
	dw = 20;//hint arrow offset 20, 16
	dh = 16;
	
	wmax = document.body.clientWidth;
	hmax = document.body.clientHeight;
	//default hint position -> right bottom
	if ((cX-dw+w)<=wmax)
	{
		ap = 1;
		ax = "r";
		rX += -dw;
	}
	else
	{
		ap = 2;
		ax = "l";
		rX += -w + dw;
	}
	
	if ((cY+dh+h)<=hmax)
	{
		ay = "b";
	}
	else
	{
		ap += 2;
		ay = "t";
		rY -= h + dh;
	}
	//make content
	innerStr = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' width='"+w+"' height='"+(h)+"' id='roswf' align='left'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='../swfs/rollover.swf?al="+(ax+ay)+"&h="+h+"&dh="+dh+"&w="+w+"&dw="+dw+"&tit="+tit+"&cnt="+cnt+"&ap="+ap+"' /><param name='menu' value='false' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><param name='scale' value='noscale' /><param name='salign' value='lt' /><param name='bgcolor' value='#ffffff' /><embed src='../swfs/rollover.swf?al="+(ax+ay)+"&h="+h+"&dh="+dh+"&w="+w+"&dw="+dw+"&tit="+tit+"&cnt="+cnt+"&ap="+ap+"' menu='false' quality='high' wmode='transparent' scale='noscale' salign='lt' bgcolor='#ffffff' width='"+(w+dw)+"' height='"+(h)+"' name='roswf' align='left' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object>";
	hobj.innerHTML = innerStr;
	//update event locker
	innerStr = "<img src='../images/tpixel.gif' width='"+(w+dw)+"' height='"+(h)+"' onClick='doTermClick()'>";
	lobj.innerHTML = innerStr;
	//ip = getPos(document.getElementById(id));
	ip = [rX, rY];
	//window.status = ""+ip;
	hobj.style.left = ""+ip[0]+"px";
	hobj.style.top = ""+ip[1]+"px";
	
	lobj.style.left = ""+ip[0]+"px";
	lobj.style.top = ""+ip[1]+"px";
	
	if ((tit+cnt)!='') 
	{
		hobj.style.visibility = 'visible';
		lobj.style.visibility = 'visible';
	}
}

function doTermClick()
{
	//alert(hintData[6]);
	//document.location.href = "glossary.html#"+hintData[6];
}

function getParamsString(in_width, in_height, in_xOffset, in_yOffset)
{	
	return "width=" + in_width + ",height=" + in_height + ",left=" + ((screen.width-16-in_width)/2 + in_xOffset) + ",top=" + ((screen.height-60-in_height)/2 + in_yOffset);
}

function pageInfo()
{
	s = ""+document.location.href;
	r = s.substring(Math.max(s.lastIndexOf('/'), s.lastIndexOf('\\'))+1, s.length);
	infowin = open("about:blank", "Info",  getParamsString(700, 100, 0, 0) + ",menubar=0,resizable=0,location=0,scrollbars=0,toolbar=0,status=0");
	infowin.document.open()
	infowin.document.write('saxon.exe -o html/'+r+' book.xml ../en/topicpage.xsl gpage='+gpage+' lang='+lang);
	infowin.document.close()
}

var intPage;

function page(s, t)
{
	var doc, opt;
	if(intPage) {
		intPage.close();
		intPage = null;
	}
	//"../activities/"+s
	if (s.substr(0,1)!=".") 
	{
		s = "../activities/"+s;
		opt = getParamsString(750, 494, 0, 0)+",menubar=0,resizable=0,location=0,scrollbars=0,toolbar=0,status=0";
	}
	else
	{
		opt = getParamsString(766, 494, 0, 0)+",menubar=0,resizable=1,location=0,scrollbars=1,toolbar=0,status=0";
	}
	intPage = open(s, "_blank",opt);
	intPage.name=t;

	intPage.focus();
}

//*******************************************************************************************
//****************************** ROLLOVER SCRIPTING: END ************************************
//*******************************************************************************************


