/*
tip_followscroll.js	v. 1.11

The latest version is available at
http://www.walterzorn.com
or http://www.devira.com
or http://www.walterzorn.de

Initial author: Walter Zorn
Last modified: 3.6.2008

Extension for the tooltip library wz_tooltip.js.
Lets a "sticky" tooltip keep its position inside the clientarea if the window
is scrolled.
*/

// Make sure that the core file wz_tooltip.js is included first
if(typeof config == "undefined")
	alert("Error:\nThe core tooltip script file 'wz_tooltip.js' must be included first, before the plugin files!");

// 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 TagToTip() 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 TOOLTIP CONFIGURATION	======================//
config. MouseSticky = false		// true or false - set to true if you 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 fscrl, is unique amongst the extensions available for
// wz_tooltips.js):
var msticky = new tt_Extension();

// Implement extension eventhandlers on which our extension should react
msticky.OnLoadConfig = function() 
{
	if(tt_aV[MOUSESTICKY]) {
		tt_aV[EXCLUSIVE] = true;
	}
};
msticky.OnSubDivsCreated = function()
{
	if(tt_aV[MOUSESTICKY])
	{
		tt_AddEvtFnc(tt_aElt[0], "mouseout", UnTipSticky);
	}
};
msticky.OnShow = function()
{
	if(tt_aV[MOUSESTICKY])
	{
		tt_iState = 0;
	}
};

UnTipSticky = function(event) { 
	
	if(!event) return;
	
	// using balloon? look at stem? 
	var stemT = 0;
	var stemB = 0;
	if(balloon) {
		if(balloon.iStem == 1) {
			stemB = 2;
			stemT = -tt_aV[BALLOONSTEMHEIGHT];
		} else {
			stemT = 2;
			stemB = -tt_aV[BALLOONSTEMHEIGHT];
		}
	}
	
	var x = event.clientX;
	var y = event.clientY;
	
	var ulx = tt_x + 6;
	var uly = tt_y - stemT;
	
	var lrx = tt_x + tt_w - 6; 
	var lry = tt_y + tt_h + stemB;
	
	var hide = false;
	if(x <= ulx) hide = true;
	if(y <= uly) hide = true;
	if(x >= lrx) hide = true;
	if(y >= lry) hide = true;
	
	if(hide) tt_HideInit();
}
