/* This notice must be untouched at all times.

tip_followscroll.js  v. 1.0

The latest version is available at
http://www.walterzorn.com
or http://www.devira.com
or http://www.walterzorn.de

Copyright (c) 2007 Walter Zorn. All rights reserved.
Last modified: 31.5.2007

Extension for the tooltip library wz_tooltip.js.
Lets a "sticky" tooltip keep its position inside the clientarea if the window
if being scrolled.

LICENSE: LGPL (see http://www.gnu.org/copyleft/lesser.html)
*/

// Here we define new global configuration variable(s) (as members of the
// predefined "config." class).
// From each of these config variables, wz_tooltip.js will automatically derive
// a command which can be passed to Tip() or Tag2Tip() in order to customize
// tooltips individually. These command names are just the config variable
// name(s) translated to uppercase,
// e.g. from config. FollowScroll a command FOLLOWSCROLL will automatically be
// created.

//===================  GLOBAL TOOPTIP CONFIGURATION  =========================//
config. FollowScroll = false    // true or false - default is false, as we don't want this to be the default behaviour
//=======  END OF TOOLTIP CONFIG, DO NOT CHANGE ANYTHING BELOW  ==============//


// Create a new tt_Extension object (make sure that the name of that object,
// here followscrl, is unique amongst the extensions available for
// wz_tooltips.js):
var followscrl = new tt_Extension();


function MoveOnScrl()
{
	var t_x = tt_GetScrollX(), t_y = tt_GetScrollY();

	tt_SetTipPos(tt_x + t_x - MoveOnScrl.xOld, tt_y + t_y - MoveOnScrl.yOld);
	MoveOnScrl.xOld = t_x;
	MoveOnScrl.yOld = t_y;
}

// Implement extension eventhandlers on which our extension should react
followscrl.OnShow = function()
{
	if(tt_aV[FOLLOWSCROLL])
	{
		// Permit FOLLOWSCROLL only if the tooltip is sticky
		if(tt_aV[STICKY])
		{
			MoveOnScrl.xOld = tt_GetScrollX();
			MoveOnScrl.yOld = tt_GetScrollY();
			tt_AddEvtFnc(window, "scroll", MoveOnScrl);
			return true;
		}
		tt_aV[FOLLOWSCROLL] = false;
	}
	return false;
}

followscrl.OnHide = function()
{
	if(tt_aV[FOLLOWSCROLL])
		tt_RemEvtFnc(window, "scroll", MoveOnScrl);
}
