//var offsetfrommouse=[50,-25]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset 50,-25 default
var offsetfrommouse=[0,0]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset 50,-25 default
var displayduration=0; //duration in seconds image should remain visible. 0 for always.
//var currentimageheight = 220; // maximum image size.
var previewwidth =380;
var prev_h;
var prev_w;


function lbx_item(o,thm,thl,h,n,p) {
    this.oid = o;
    this.thmloc = thm;
    this.thlloc = thl;
    this.hoid = h;
    this.added = false;
    this.deleted = false;
    this.prev=p;
    this.next=n;
}

function js_add_to_lbx(n,tloc,btloc,hoid){

    var this_lbx_item=lbx_items.length;
    if(start_lbx_item == null) start_lbx_item=this_lbx_item;
    
    lbx_items[lbx_items.length++]= new lbx_item(n,tloc,btloc,hoid,last_lbx_item,null);
    if(last_lbx_item != null) lbx_items[last_lbx_item].next=this_lbx_item;
    last_lbx_item=this_lbx_item;
    return(lbx_items[this_lbx_item]);
}


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, imgtitle, w, h, hoid){
        prev_h = h;
        prev_w = w;

        newHTML = '<div style="padding:0px; background-color: #ffffff; border: 2px solid #C7CECC; width: ' + previewwidth + 'px;">';
        newHTML = newHTML + '<div align="center"><img src="' + imagesrc + '" border="0"></div>';
		newHTML = newHTML + '<center><font class="imgtlt">' + imgtitle + '</font></center>';
        newHTML = newHTML + '</div>';

        getprevobjnostyle("previewcontainer").innerHTML = newHTML;
        setTimeout('getprevobj("previewcontainer").visibility="visible"',400);
        document.onmousemove=followmouse;
 
}
        //
        //newHTML = newHTML + '<center><font style="color:#666" class="small">Image# ' + oid + '</font></center>';
        //newHTML = newHTML + '<center><font style="color:#666" class="small">Image# ' + imgtitle + '</font></center>';


function hideprev(){
        getprevobj("previewcontainer").visibility="hidden";
        getprevobj("previewcontainer").left="-1500px";
        document.onmousemove="";
}

function followmouse(e){

    var xcoord=offsetfrommouse[0]
    var ycoord=offsetfrommouse[1]

		//var x = e.pageX != undefined ? e.pageX : event.clientX
		//var y = e.pageY != undefined ? e.pageY : event.clientY

	var flip_loc_x = 390 // When we get to loc clientWidth - 445 then move the preview to the left of the cursor
	var left_space = 60 // close the gap when we move the preview to the left of the cursor
    var flip_loc_y
	var scrolltop=0


    if(getprevobjnostyle('bodyContent').scrollTop)
        scrolltop=getprevobjnostyle('bodyContent').scrollTop
    else
        scrolltop=truebody().scrollTop

    
        flip_loc_y = 100

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15

	//var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(document.body.offsetHeight, window.innerHeight)
    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] - 60 + left_space; // Move to the left side of the cursor
        } else {
            xcoord += (e.pageX + 10);
        }
        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 - 60 + left_space; // changed from 286 Move to the left side of the cursor
        } else {
            xcoord += truebody().scrollLeft+event.clientX + 10
        }
        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"
		//getprevobj("previewcontainer").left = x - 150
		//getprevobj("previewcontainer").top = y - 70
}