var offsetfrommouse = [20,0]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset 50,-25 default
var displayduration = 2; //duration in seconds image should remain visible. 0 for always.
var prev_h;
var prev_w;

function _cls () {window.status = ''; return true}

function getprevobj(o){

    if (document.getElementById)
        return document.getElementById(o).style
    else if (document.all)
        return document.all.o.style
}

function getprevobjnostyle(o){

    if (document.getElementById)
        return document.getElementById(o)
    else if (document.all)
        return document.all.o
}

function getObjectByName(n){
    alert(n);

    return(document.getElementsByTagName(n)[0].firstChild);
}

function truebody(){
   return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function showprev(imagesrc, w, h){

        prev_h = Math.round(h * 0.66);
        prev_w = Math.round(w * 0.66);

        newHTML = '<div style="padding: 0; background-color: transparent; width: ' + prev_w + 'px;">';
        newHTML = newHTML + '<div align="center" style="padding: 0;"><img src="' + imagesrc + '"' + '" width="' + prev_h + '" border="0" style="border: 2px solid White"></div>';
        newHTML = newHTML + '</div>';

        getprevobjnostyle("previewcontainer").innerHTML = newHTML;
        setTimeout('getprevobj("previewcontainer").visibility="visible"',400);
        document.onmousemove=followmouse;
}

function hideprev(){
        getprevobj("previewcontainer").visibility="hidden";
        getprevobj("previewcontainer").left="-1500px";
        document.onmousemove="";
}

function followmouse(e){

    var xcoord=offsetfrommouse[0]
    var ycoord=offsetfrommouse[1]

    var flip_loc_x = 0
    var flip_loc_y = 0
    var scrolltop = 0

    if(getprevobjnostyle('bodyContent').scrollTop)
        scrolltop=getprevobjnostyle('bodyContent').scrollTop
    else
        scrolltop=truebody().scrollTop

    var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
    var docheight=document.all? truebody().clientHeight : window.innerHeight

    if (typeof e != "undefined"){
        if (docwidth - e.pageX < flip_loc_x){
            xcoord = e.pageX - flip_loc_x - offsetfrommouse[0];
        } else {
            xcoord += e.pageX;
        }
        if (docheight - e.pageY < (prev_h + flip_loc_y)){
            ycoord += e.pageY - Math.max(0,(flip_loc_y + prev_h + e.pageY - docheight - scrolltop));
        } else {
            ycoord += e.pageY;
        }

    } else if (typeof window.event != "undefined"){
        if (docwidth - event.clientX < flip_loc_x){ // changed from 300
            xcoord = event.clientX + truebody().scrollLeft - flip_loc_x;
        } else {
            xcoord += truebody().scrollLeft+event.clientX
        }
        if (docheight - event.clientY < (prev_h + flip_loc_y)){
            ycoord += event.clientY + scrolltop - Math.max(0,(flip_loc_y + prev_h + event.clientY - docheight));
        } else {
            ycoord += scrolltop + event.clientY;
    }
    }

    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)

    getprevobj("previewcontainer").left=xcoord+"px"
    getprevobj("previewcontainer").top=ycoord+"px"
}
