FSite2._helperInitClose = function()
{
	if (!this._timeout)
		this._timeout = setTimeout(FSite2._callRef(FSite2._helperClose, this), 100);
}

FSite2._helperCancelClose = function(helper)
{
	if (this && !helper)
		helper = this;
	if (helper._timeout)
	{
		clearTimeout(helper._timeout);
		helper._timeout = null;
	}
}

FSite2._helperClose = function(helper)
{
	if (!helper)
		helper = this;
	helper.style.display = 'none';
	helper.style.visibility = 'hidden';
	if (helper.parentNode)
		helper.parentNode.removeChild(helper);
	helper._element._helpBox = null;
}

FSite2.extendHelpers = function(node, params)
{
	if (!node)
		node = document.body;
	var bd = FSite2.getElementsByClassName(params.helperClass, node);
	if (!params.helperElementId)
		params.helperElementId = 'FSite2_helper';
	for (var i = 0, a = [], d; d = bd[i++];)
	{
		if (d._helper) continue;
		FSite2.extendHelper(d, params);
	}
}

FSite2.extendHelper = function(d, params)
{
	d._helper=true;
	if (d.getAttribute('title'))
	{
		d._helpText = d.getAttribute('title');
/*		d.setAttribute('alt', d.getAttribute('title'));*/
		d.removeAttribute('title');
	}
	else if (d.getAttribute('alt'))
	{
		d._helpText = d.getAttribute('alt');
		d.removeAttribute('alt');
	}
	if (params.helperTrackClass && RegExp('\\b' + params.helperTrackClass + '\\b', 'gi').test(d.className))
	{
		d._helperTrack = true;
		d.onmousemove = function(event) {
			if (this._helpBox)
			{
				widthScreen = window.getWindowWidth()-22;
				widthBox = window.getObjectWidth(this._helpBox);
				maxR = Math.round(widthBox/2)+getMouseXY(event)[0];
				minR = getMouseXY(event)[0]-Math.round(widthBox/2);
				if (minR<0)
					var posLeft=Math.round(widthBox/2);
				else if (maxR>widthScreen)
					var posLeft=widthScreen-Math.round(widthBox/2)+window.getScrollX();
				else
					var posLeft=getMouseXY(event)[0];
				this._helpBox.style.left = posLeft+'px';
				//this._helpBox.style.left=(posLeft+(this._helpBox.offsetLeft-posLeft))+'px';
				this._helpBox.style.top = getMouseXY(event)[1] + 'px';
				
			}
		}
	}
	if (typeof d.onmouseover == 'function')
		d._onmouseover_helper = d.onmouseover;
	d.onmouseover = function (event) {
		if (!this._helpText)
			return;
		if (!event)
			event = window.event;
		var res;
		if (this._onmouseover_helper) res = this._onmouseover_helper(event);
		if (res === false)
			return res;
		var box;
		if (!(box = document.getElementById(params.helperElementId)))
		{
			box = document.createElement('div');
			document.body.appendChild(box);
			box._helperInitClose = FSite2._helperInitClose;
			box._helperInitCancelClose = FSite2._helperInitCancelClose;
			box._helperCancelClose = FSite2._helperCancelClose;
			box._helperClose = FSite2._helperClose;
			box.id = params.helperElementId;
			box.style.position = 'absolute';
			if (!this._helperTrack)
			{
				box.onmouseover = function()
				{
					this._helperCancelClose();
				}
				box.onmouseout = function()
				{
					this._helperInitClose();
				}
			}
		}
		posBox_x = getMouseXY(event)[0];
		posBox_y = getMouseXY(event)[1];
		box.style.left = posBox_x + 'px';
		box.style.top = posBox_y + 'px';
		if (params.helperElementClass)
			box.className = params.helperElementClass;
		this._helpBox=box;
		box._element = this;
		box.innerHTML = this._helpText;
		this._helper = box;
		this._helper._helperCancelClose();
	}
	if (d.onclick)
		d._onclick_helper=d.onclick;
		
	d.onclick = function (ev) {
		var res;
		if (!ev) ev = window.event;
		if (this._onclick_helper) res = this._onclick_helper(ev);
		if (this._helpBox) this._helpBox._helperClose();
		if (res!=null)
			return res;
	}
	if (typeof d.onmouseout == 'function')
		d._onmouseout_helper = d.onmouseout;
	d.onmouseout = function (event) {
		var res;
		if (this._onmouseout_helper) res = this._onmouseout_helper(event);
		if (res === false)
			return res;
		if (this._helper && (typeof this._helper == 'object'))
			this._helper._helperInitClose();
	}
	//if(window.addEventListener)
	//  d.addEventListener('click', d.onmouseout, false);
	//else if(window.attachEvent)
	//  d.attachEvent('onclick', d.onmouseout);
}

