﻿// JScript File

/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var displayduration=0; //duration in seconds image should remain visible. 0 for always.
var maxImageWidth = 400; //max image display width
var showtime;


function init() {
    document.onmouseover=followmouse;
    followmouse();
}

function show_note ( title, note) {

    if (document.getElementById || document.all) {
        document.onmouseover=followmouse;
        gettrailobj().innerHTML = '<div style="width:' + maxImageWidth + 'px;border: 2px solid #0054A6;padding: 10px;background:white;overflow:visible" ><h2 style="text-align:center">' + title + '</h2><p>' + note + '</p></div>'; 
        gettrailobj().style.display = "block"; //make trailimageid layer visible

        if (displayduration>0) //limit time to show trailimageid layer
            showtime = setTimeout("hidetrail()", displayduration*1000);
    }
}

function gettrailobj(){
    if (document.getElementById) {
        return document.getElementById("trailimageid");
    } else { 
        if (document.all)
        return document.all.trailimagid; 
    }
}

function truebody(){
    return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function hidetrail(){
    gettrailobj().style.display="none";
    document.onmouseover="";
    clearTimeout(showtime);
}

function followmouse(e){
    var yOffset =20; // y offset
    var xOff, yOff;  // top left corner offset from relative cursor
    var PageX, PageY;  // top left corner relative coordinates
    var xNew =0
    var yNew=0
    var yNew1=0;
    var winWidth;
    var winHeight;
    var docWidth;
    var docHeight;

    oTrail = gettrailobj()
    winWidth = document.all? truebody().clientWidth : window.innerWidth-17;
    winHeight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight);
    docWidth = gettrailobj().clientWidth
    docHeight = gettrailobj().clientHeight

    if (typeof e != "undefined") { //for Firefox
        // show to left if it fits otherwise flip to right side
        xOff = e.pageX - docWidth/2;
        yOff = e.pageY - docHeight - yOffset; //add enough to clear cursor
        xNew = (xOff < window.pageXOffset ) ?  window.pageXOffset : ( e.pageX + docWidth/2 > winWidth) ? winWidth - docWidth : xOff;
        yNew = (yOff > window.pageYOffset ) ?  yOff : ((e.pageY + docHeight + yOffset) > winHeight) ? yOff : e.pageY + yOffset;
    }
    else { //for IE branch
        if (typeof window.event !="undefined"){ //for IE
            e=window.event;
            xOff = e.clientX - docWidth/2;
            yOff = e.clientY - docHeight - yOffset // yOffset adds clearance above/below cursor
            xNew = truebody().scrollLeft + (xOff < 0 ) ?  0 : ( e.clientX + docWidth/2 > winWidth) ? winWidth - docWidth : xOff;
            yNew = truebody().scrollTop + ((yOff > 0 ) ?  yOff : ( e.clientY + docHeight + yOffset > winHeight - truebody().scrollTop) ? yOff : e.clientY + yOffset);
        }
    }
//    PageX = e.clientX;
//    PageY = e.clientY;
    gettrailobj().style.top=yNew+"px";
    gettrailobj().style.left=xNew+"px";
//    gettrailobj().innerHTML = '<div style="margin:0px;border: 2px solid #0054A6;padding: 10px;background:white; overflow:visible; width:' + maxImageWidth + 'px;"><h2 style="text-align:center">Coordinates</h2><p>window dimensions x:y ' + winWidth + ':' + winHeight + '<br>Image Dimensions(w:h) ' + docWidth + "x" + docHeight + '<br>Cursor Position (relative) ' + PageX + ':' + PageY + '<br>top left corner offset from cursor x:y ' + xOff + ':' + yOff + '<br>Top corner (absolute) x:y ' + xNew +':' + yNew + '</p></div>'

}
//end JScript File


