/*

Annotation mouseover script

(c) 2006 Cambridge Imaging Systems

*/

annotationRects = new Array();
annotationDivs = new Array();
annotationSpans = new Array();

function annotationMouseOver(i, colour) {
    var rect = annotationRects[i];
    var div = annotationDivs[i];
    var span = annotationSpans[i];

    if (rect) rect.style.borderColor = "#ffffff";
    if (div) {
        div.style.borderColor = "#ffffff";
        div.style.color = "#ffffff";
        div.style.backgroundColor = colour;
    }
    if (span) {
        span.style.borderColor = "#ffffff";
        span.style.color = "#ffffff";
        span.style.backgroundColor = colour;
    }
}

function annotationMouseOut(i, colour) {
    var rect = annotationRects[i];
    var div = annotationDivs[i];
    var span = annotationSpans[i];

    if (rect) rect.style.borderColor = colour;
    if (div) {
        div.style.borderColor = colour;
        div.style.color = colour;
        div.style.backgroundColor = "#ffffff";
    }
    if (span) {
        span.style.borderColor = colour;
        span.style.color = colour;
        span.style.backgroundColor = "#ffffff";
    }
}

function hideAnnotations() {
    for (i in annotationRects) {
        annotationRects[i].style.display = "none";
    }

    var show = document.getElementById("showannotations");
    var hide = document.getElementById("hideannotations");

    if (show) show.style.display = "inline";
    if (hide) hide.style.display = "none";

    document.cookie = "annotations=hidden";
    return true;
}

function showAnnotations() {
    for (i in annotationRects) {
        annotationRects[i].style.display = "inline";
    }

    var show = document.getElementById("showannotations");
    var hide = document.getElementById("hideannotations");

    if (show) show.style.display = "none";
    if (hide) hide.style.display = "inline";

    document.cookie = "annotations=shown";
    return true;
}

function startAnnotations(annotationCount) {
    var count = parseInt(annotationCount);
    
    for (i = 0; i < count; i++) {
        var rect = document.getElementById("annotationRect" + i);
        if (rect) annotationRects[i] = rect;
        
        var div = document.getElementById("annotationDiv" + i);
        if (div) annotationDivs[i] = div;
        
        var span = document.getElementById("annotationSpan" + i);
        if (span) annotationSpans[i] = span;
    }

    if ((annotationRects.length > 0) && (document.cookie.indexOf("annotations=hidden") >= 0)) {
        hideAnnotations();
    } else {
        showAnnotations();
    }
}
