﻿// 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=20; //duration in seconds image should remain visible. 0 for always.
var maxImageWidth = 500; //max image display width
var maxImageHeight = 500;  //max image display height
var showtime //imageWidth, imageHeight;

function init() {
    document.onmouseover=followmouse;
    followmouse();
}

function enlarge_image (image_name, title, width, height) {

    if (document.getElementById || document.all) {
        // make sure that the width and height variables are set
        document.onmousemove=followmouse;
        imageWidth = (width == 0 ) ? maxImageWidth: width;
        imageHeight = (height == 0) ? maxImageHeight: height;
        
        // make sure that height and width inputs don't exceed the max defaults above
        imageWidth = (imageWidth>maxImageWidth) ? maxImageWidth:imageWidth;
        imageHeight = (imageHeight>maxImageHeight) ? maxImageHeight:imageHeight;


        gettrailobj().innerHTML = '<div style="border: 2px solid #005244;padding: 10px;background:white;overflow:visible"><h2 style="text-align:center">' + title + '</h2><img src="'+ image_name +'" border="0" width="'+ imageWidth+'px" height="'+ imageHeight +'px"></div>'; 

        gettrailobj().style.display = "block"; //make trailimageid layer visible
    }
    if (displayduration>0) //limit time to show ltrailimageid 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";
    clearTimeout(showtime);
}

function followmouse(e){
    var xOff = 0; //  left edge of display
    var yOff = 0; //  right edge of display
    var yOffset = 10;
    var xOffset = 10; // x spacing from cursor
    var PageX, PageY;
    var xNew = 0;
    var yNew = 0;
    var winWidth; //assume horizontal scroll bar is present
    var docWidth;
    var docHeight;

    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
        xOff = e.pageX - xOffset- docWidth; //left edge offset from cursor
        yOff = e.pageY - docHeight - yOffset; //position middle of image on cursor

        // show to left if it fits otherwise flip to right side
        xNew = (xOff > window.pageXOffset ) ?  xOff  : ( e.pageX + xOffset + docWidth < winWidth) ? e.pageX + xOffset + docWidth : window.pageXOffset;
        yNew = (yOff > window.pageYOffset ) ?  yOff : ((e.pageY + docHeight + yOffset) > winHeight) ? yOff : e.pageY + yOffset;

    }
    else {
        if (typeof window.event !="undefined"){ //for IE
            e=window.event;
            xOff = e.clientX - docWidth - xOffset;
            yOff = e.clientY - docHeight - yOffset // yOffset adds clearance above or below cursor

            xNew = truebody().scrollLeft + (xOff > 0 ) ?  xOff : ( e.clientX + docWidth + xOffset < winWidth) ? winWidth + docWidth + xOffset : 0;
            yNew = truebody().scrollTop + ((yOff > 0 ) ?  yOff : ( e.clientY + docHeight + yOffset > winHeight - truebody().scrollTop) ? 0 : e.clientY + yOffset);
        }
    }
//    PageX = (typeof e != "undefined")? e.clientX : e.PageX ;
//    PageY = (typeof e != "undefined") ? e.clientY : e.PageY ;

    //gettrailobj().innerHTML = '<div style="margin:0px;border: 2px solid #005244;padding: 10px;background:white; overflow:visible; width:' + (imageWidth-24) + 'px; height:' + (imageHeight-24) + 'px;"><h2 style="text-align:center">Coordinates</h2><p>x:y ' + xNew +':' + yNew + '<br>Image Dimensions(w:h) ' + imageWidth + "x" + imageHeight + '<br>Current Cursor Position (PageX:PageY) ' + PageX + ':' + PageY + '<br>offset x:y ' + xOff + ':' + yOff + '<br>window dimensions x:y ' + winWidth + ':' + winHeight + '</p></div>'
    gettrailobj().style.left=xNew+"px";
    gettrailobj().style.top=yNew+"px";
}
