
var m_blnWait = false;
var m_objTimeout;
var m_objExcerpt;
var m_objCursor;


document.onmousemove = TrackCursor;

function ShowExcerpt(intNewsId) {
	HideAllExcerpts();
	if (m_blnWait) {
		m_objTimeout = null;
		if (m_objExcerpt) m_objExcerpt.style.display = "none";
	}
	m_blnWait = true;
	m_objExcerpt = document.getElementById("News" + intNewsId);
	m_objTimeout = window.setTimeout("ShowExcerpt2(" + intNewsId + ")", 500);	
}

function ShowExcerpt2(intNewsId) {
	if (m_objExcerpt) {
		m_objExcerpt.style.visibility = "hidden";
		m_objExcerpt.style.display = "block";
		m_objExcerpt.style.top = GetVertOffset();
		m_objExcerpt.style.left = GetHorizOffset();
		m_objExcerpt.style.visibility = "visible";
	}
	m_blnWait = false;
}

function GetHorizOffset() {
	var intOffset = -3;
	var intCursorA = m_objCursor.x;
	var intPos = intCursorA + intOffset;
	
	var intCursorB = intPos + m_objExcerpt.offsetWidth;
    var de = document.documentElement;
    var b = document.body;
	var intWindow = (b.clientWidth || de.clientWidth) + (b.scrollLeft || de.scrollLeft);
	if (intWindow < intCursorB) {
		intOffset = m_objExcerpt.offsetWidth - 12;
		intPos -= intOffset;
	}
	return intPos;
}

function GetVertOffset() {
	var intOffset = 24;
	var intCursorA = m_objCursor.y;
	var intPos = intCursorA + intOffset;
	
	var intCursorB = intPos + m_objExcerpt.offsetHeight;
	
	var de = document.documentElement;
	var b = document.body;
	var intWindow = (b.clientHeight || de.clientHeight) + (b.scrollTop || de.scrollTop);
	if (intWindow < intCursorB) {
		intOffset = m_objExcerpt.offsetHeight + 30;
		intPos -= intOffset;
	}
	//Trace(intCursorA + " - " + intCursorB + " : " + intWindow);
	return intPos;
}

function HideExcerpt(intNewsId) {
	m_objExcerpt.style.display = "none";
	m_blnWait = false;
	m_objTimeout = null;
	m_objExcerpt = null;
}

function HideAllExcerpts() {
	var colExcerpts = document.getElementById("Excerpts").childNodes;
	var i;
	for (i=0; i<colExcerpts.length; i++) {
		colExcerpts[i].style.display = "none";
	}
	m_blnWait = false;
	m_objTimeout = null;
}

function TrackCursor(e) {
	m_objCursor = getPosition(e);
}


function getPosition(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
    return cursor;
}
