﻿//ImageTrail start----------------
var offsetfrommouse = [5, 8] //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration = 0 //duration in seconds image should remain visible. 0 for always.

function InitImageTrail()
{
    if (document.getElementById || document.all)
        document.write('<div id="TrailImageId"></div>');
}

function GetTrailObjStyle()
{
    if (document.getElementById)
        return document.getElementById("TrailImageId").style
    else if (document.all)
        return document.all.TrailImageId.style
}

function GetTrailObj()
{
    if (document.getElementById)
        return document.getElementById("TrailImageId")
    else if (document.all)
        return document.all.TrailImageId
}

function truebody()
{
    return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function HideTrail()
{
    GetTrailObjStyle().visibility = "hidden";
    document.onmousemove = "";
    GetTrailObj().innerHTML = "";
}

function FollowMouse(e)
{
    var posx = 0;
    var posy = 0;
    var xcoord = 0;
    var ycoord = 0;
    var docwidth = document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15;
    var docheight = document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight);
    
    if (!e) var e = window.event;
    
    //posx and posy will get the mouse position relative to the document
    //found at http://www.quirksmode.org/js/events_properties.html
    if (e.pageX || e.pageY)
    {
      posx = e.pageX;
      posy = e.pageY;
    }
    else if (e.clientX || e.clientY)
    {
      posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
      posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
    }

    if ((posx + offsetfrommouse[0] + GetTrailObj().offsetWidth + 3 > docwidth) && (posy + offsetfrommouse[1] + GetTrailObj().offsetHeight > docheight))
    {
        xcoord = posx - offsetfrommouse[0] - GetTrailObj().offsetWidth;
        ycoord = posy - offsetfrommouse[1] - parseInt(GetTrailObj().offsetHeight / 2);
    }
    else if (posx + offsetfrommouse[0] + GetTrailObj().offsetWidth + 3 > docwidth)
    {
        xcoord = posx - offsetfrommouse[0] - GetTrailObj().offsetWidth;
        ycoord = posy + offsetfrommouse[1];
    }
    else if (posy + offsetfrommouse[1] + GetTrailObj().offsetHeight > docheight)
    {
        xcoord = posx + offsetfrommouse[0];
        ycoord = posy - offsetfrommouse[1] - parseInt(GetTrailObj().offsetHeight / 2);
    }
    else
    {
        xcoord = posx + offsetfrommouse[0];
        ycoord = posy + offsetfrommouse[1];
    }

    GetTrailObjStyle().left = xcoord + "px";
    GetTrailObjStyle().top = ycoord + "px";
    
    if (GetTrailObjStyle().visibility = "hidden")
    {
        GetTrailObjStyle().visibility = "visible";
    }
}

function ShowImageTrail(ImageURL, BranchName)
{
    //alert(ImageURL);
    var divHTML = '';
    
    divHTML = '<div style="background-image:url(App_Themes/Pictures/graphics/origin_downloadcombox.png);' +
               'background-repeat:no-repeat;border:0px;width:366px;height:220px;text-align:center;">' +
              '<h5 style="font-family:Trebuchet MS, Tahoma, sans-serif;color:#037DD3;font-size:13pt;font-weight:bold;margin-left:50px;margin-top:5px">' + BranchName + '</h5>' + 
              '<img src="' + ImageURL + '" border="0" style="margin-left:50px;" alt=" " height="150" >' +
              '</div>';
         
    GetTrailObj().innerHTML = divHTML;
    
    document.onmousemove = FollowMouse

    if (displayduration > 0)
        setTimeout("HideTrail()", displayduration*1000)
}
//ImageTrail end------------------