//

var timeout = null;
var ex = 0, ey = 0;

if(document.captureEvents) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = eventHandler;

function showDictionaryTip(obj, id) {
	if(word_definitions[id] != undefined) {
		definition_box_head.innerHTML = word_definitions[id]['name'];
		definition_box_content.innerHTML = word_definitions[id]['short'];
 	//timeout = window.setTimeout('_showTip()', 1000);
 	_showTip();
	}
}

function _showTip() {
	definition_box.style.display = 'block';
	positionTip();
}

function hideDictionaryTip() {
	if(timeout) window.clearTimeout(timeout);
	definition_box.style.display = "none";
}

function eventHandler(e) {
	if(e && e.pageX) {
		ex = e.pageX;
		ey = e.pageY;
	} else if(event) {
		ex = document.body.scrollLeft + event.clientX - document.body.clientLeft;
		ey = document.body.scrollTop + event.clientY - document.body.clientTop;
		if (document.body.parentElement && document.body.parentElement.clientLeft) {
        	var bodyParent = document.body.parentElement;
      		ex += bodyParent.scrollLeft - bodyParent.clientLeft;
      		ey += bodyParent.scrollTop - bodyParent.clientTop;
        }
	}
	positionTip();
}

function positionTip() {
	var ow = definition_box.scrollWidth;
	var oh = definition_box.scrollHeight;
	
	if(window.pageXOffset) {
		var sw = window.pageXOffset;
		var sh = window.pageYOffset;
	} else {
		var sw = document.body.scrollLeft;
		var sh = document.body.scrollTop;
	}
	var ww = document.body.clientWidth - (document.body.clientLeft ? document.body.clientLeft : 0);
	var wh = document.body.clientHeight - (document.body.clientTop ? document.body.clientTop : 0);
	
	var x = ex + 8;
	var y = ey - oh - 8;
	if(y < sh) y = sh;
	if(x < sw) x = sw;
	if(x + ow > sw + ww) x = sw + ww - ow;
	if(y + oh > sh + wh) y = sh + wh - oh;
	
	definition_box.style.left = x;
	definition_box.style.top = y;
}

//
