// firefox doesn't always put the box in the right place when using async calls
// need to track this down

var pv_evt, pv_head, pv_path, req, pv_x, pv_y, pv_ok = false, pv_async = true;

function cancelPreview()
{
	try	{
        pv_ok = false;
        tt_Hide();
	}
	catch (ex) {
		//ignore ie error
	}
}

function showPreview(event, headline, path)
{
    pv_evt = event;
    pv_head = headline;
    pv_path = path;
    pv_ok   = true;

    try {
	    pv_x = tt_EvX(event);
        pv_y = tt_EvY(event);

//      alert("event at " + pv_x + ", " + pv_y);

        if (!pv_async)
        {
            tt_go(event, pv_head, req.responseText);
        }
        else
        {
            window.setTimeout('getOOTB()', 700);
        }
    }
    catch (ex) {
		// skip if ie error
    }
}

function onPreviewLoaded()
{
    if (pv_async && req.readyState == 4 && req.status == 200 && pv_ok)
    {
       tt_go(pv_evt, pv_head, req.responseText, pv_x, pv_y);
    }
}

function getOOTB()
{

   if (!pv_ok)
	return true;
   
   path = pv_path;

    url = "/v10/us/news/pages/homepage/ootb.php?u=" + path;

    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = onPreviewLoaded;
        req.open("GET", url, pv_async);
        req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = onPreviewLoaded;
            req.open("GET", url, pv_async);
            req.send();
        }
    }
}