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 ) {
		if( window.event ) {
			e = window.event;
		} else {
			return;
		}
	}

	if(e && e.pageX) {
		ex = e.pageX;
		ey = e.pageY;
	} else if(e) {
	 	ex = document.documentElement.scrollLeft + e.clientX - document.documentElement.clientLeft;
		ey = document.documentElement.scrollTop + e.clientY - document.documentElement.clientTop;
		if (document.documentElement.parentElement && document.documentElement.parentElement.clientLeft) {
			var bodyParent = document.documentElement.parentElement;
			ex += bodyParent.scrollLeft - bodyParent.clientLeft;
			ey += bodyParent.scrollTop - bodyParent.clientTop;
		}
	} else {
		return;
	}
 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.documentElement.scrollLeft;
		var sh = document.documentElement.scrollTop;
	}
	var ww = document.documentElement.clientWidth - (document.documentElement.clientLeft ? document.documentElement.clientLeft : 0);
	var wh = document.documentElement.clientHeight - (document.documentElement.clientTop ? document.documentElement.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 +"px";
	definition_box.style.top = y +"px";
}
//
