var locked = false;
var hoover = false;

function lockPopup() {
    locked = true;
}

function unlockPopup() {
    locked = false;
}

function s(id) {
    var tooltipOBJ = (document.getElementById) ? document.getElementById("popup") : eval("document.all['popup']");
    if (tooltipOBJ != null) {
        tooltipOBJ.style.visibility = "visible";
        setPopupWidth();
        Effect.Appear('popup',{duration:0.5, to: 0.9});
    }
}

function h() {
    hoover = false;
//    var tooltipOBJ = (document.getElementById) ? document.getElementById('popup') : eval("document.all['popup']");
//    if (tooltipOBJ != null) {
//        tooltipOBJ.style.visibility = "hidden";
//        tooltipOBJ.innerHTML = 'loading...';
//    }
}

function o(areaId) {
    s(areaId);
    hoover = true;
    setTimeout('ao(' + areaId + ')',250);
}

function ao(areaId) {
    if (hoover)
        new Ajax.Updater('popup','/genomes/summary/' + areaId, {asynchronous:true, evalScripts:true, requestHeaders:['X-Update', 'popup']});
}

function e(areaId) {
    s(areaId);
    if (!locked){ /* locking itself is being done in epiInit and is only necessary when TinyMCE is loaded */
        hoover = true;
        setTimeout('ae(' + areaId + ')',250);
    }
}

function ae(areaId) {
    if (hoover)
        new Ajax.Updater('popup','/admin/genomes/summary/' + areaId, {asynchronous:true, evalScripts:true, requestHeaders:['X-Update', 'popup']});
}


//function assignEvents() {
//    var areas = document.getElementsByTagName('area');
//    for (var i = 0; i < areas.length; i++) {
//        var areaId = areas[i].id.substring(1);
//        Event.observe(
//            areas[i].id,
//            'mouseover', 
//            function(event){ 
//                o(areaId);
//            },
//            false
//        );
//    }
//}

function setPopupWidth() {
//    var maxWidth = document.clientWidth;
//    var phyloImageWidth = document.getElementById("phylo").clientWidth;
//    popupWidth = (maxWidth - phyloImageWidth - 30) / 2;
//    document.getElementById("popup").style.width = popupWidth;
}

Event.observe(window,"load", function() { setPopupWidth(); }, false);
