// ========= Контекстные подсказки ==========
// Показать контекстную подсказку
function contextArrowHelp(evt, elm, text, paramsObj) {
	cancelBubbling(evt);
	elm.blur();
	elm['timeout'] = setTimeout(contextArrowHelpHide, 5000); //initial timeout
	if (!$("helpDiv")){
		var div = document.createElement("div");
		div.id = "helpDiv";
		div.className = "infoWindow iWindowLayer";
		div.style.top = "0px";
		div.style.left = "-1000px";
		div.style.zIndex = "100000000";
		document.body.appendChild(div);
		addHandler(div, 'mouseover', function(){if(elm['timeout']) {clearTimeout(elm['timeout'])}});
		addHandler(div, 'mouseout', function(){elm['timeout'] = setTimeout(contextArrowHelpHide, 1000)});
	}
	var targetDiv = $("helpDiv");
	var div_html = '<div class="outLineTop"><div class="cellL"></div><div class="cellR"></div>';
	div_html	+= '<span id="arrowTop"><div class="arrow" id="arrow"></div></span></div>';
	div_html	+= '<div class="body"><div class="content">';
	div_html	+= '<a href="#" id="contextHelpCloseB"><img height="10" width="10" alt="' + t('TtlClose') + '" title="' + t('TtlClose') + '" src="http://img.imgsmail.ru/mail/ru/images/files/close_w.gif" class="flR"/></a>';
	div_html	+= text;
	div_html	+= '</div></div>';
	div_html	+= '<div class="outLineBottom"><div class="cellL"></div><div class="cellR"></div><span id="arrowBottom"></span></div>';
	targetDiv.innerHTML = div_html;
	addHandler($('contextHelpCloseB'), 'click', contextArrowHelpHide, false);

	var el = (document.documentElement) ? document.documentElement : (document.body) ? document.body: null;
	var screenWidth = el.offsetWidth;
	var screenHeight = el.offsetHeight;
	var arrow = $('arrow');
	var elm_point = absPosition(elm);
	var x_correction = arrow.offsetWidth;
	// Клик может быть сделан с клавиатуры
	var mouse_xy = eventMouseXY(evt);
	var point= {'x': (mouse_xy.x ? mouse_xy.x : elm_point.x),
				'y': (elm_point.y + elm.offsetHeight)}
	// Пробуем справа снизу, стрелка по умолчанию сверху
	targetDiv.style.top = point.y + 'px';
	targetDiv.style.left = point.x - x_correction + 'px';
	targetDiv.style.bottom = 'auto';
	targetDiv.onclick = cancelBubbling;
	arrow.style.left = '0px';
	/*!!!SHOULD BE MOVED TO THE PAGE*/
	var contextlink = $('smscontextlink');
	if (contextlink) {
		contextlink.onclick = cancelBubbling;
	}
	/*SHOULD BE MOVED TO THE PAGE!!!*/
	if(point.y + targetDiv.offsetHeight > screenHeight + document.documentElement.scrollTop) {
		// Если видимая область снизу меньше высоты контейнера - безусловно перемещаем контейнер наверх
		targetDiv.style.top = point.y - targetDiv.offsetHeight - arrow.offsetHeight - elm.offsetHeight + 'px';
		// Перемещаем стрелку вниз
		$('arrowBottom').appendChild(arrow);
	}
	if(point.x + targetDiv.offsetWidth > screenWidth + document.documentElement.scrollLeft) {
		// Если контейнер выходит за правый край - сдвигаем его влево
		var targetDiv_left = document.documentElement.scrollLeft + screenWidth - targetDiv.offsetWidth;
		// Если стрелка будет оторвана от контейнера - корректируем положение контейнера
		if(targetDiv_left + targetDiv.offsetWidth - x_correction < point.x) {
			targetDiv_left += x_correction;
		}
		targetDiv.style.left = targetDiv_left + 'px';
	}
	// Ставим стрелку на место
	arrow.style.left = Math.abs(point.x - absPosition(arrow).x) - arrow.offsetWidth/2 + 'px';

	return false;
}
function contextArrowHelpHide(e) {
	if ($("helpDiv")) $("helpDiv").style.left = "-1000px";
	if(e) {
		if(typeof e.preventDefault != 'undefined') e.preventDefault();
		e.returnValue = false;
	}
	return false;
}
//addHandler(document, 'click', contextArrowHelpHide);
// ========= /Контекстные подсказки ==========
