var offsetfrommouse = [20, -100]; 			// 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.
var currentimagewidth = 368; 				// browser supoport: Firefox: width of the image
var previewwidth = currentimagewidth + 10;	// browser supoport: Firefox: additional right-side image padding
var prev_h;
var prev_w;

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, oid, brand, w, h){

        prev_h = h;
        prev_w = w;

        newHTML = '<div style="padding: 5px; background-color: #FFFFFF; border: 1px solid #949494; width: ' + previewwidth + 'px; background-image:url(../images/thumb_loading.jpg);">';
        newHTML = newHTML + '<div align="center" style="padding: 6px 2px 6px 2px;"><img src="' + imagesrc + '" border="0" width="' + w + '" height="' + h + '"></div>';
        //newHTML = newHTML + '<font style="color:#666" class="small"></b>' + brand + '</b></font><br>';
        //newHTML = newHTML + '<center><font style="color:#666" class="small">Image# ' + oid + '</font></center>';
        //newHTML = newHTML + '<center><font style="color:#666" class="small">Image# ' + brand + '</font></center>';
        newHTML = newHTML + '</div>';

        getprevobjnostyle("previewContainer").innerHTML = newHTML;
        setTimeout('getprevobj("previewContainer").visibility="visible"', 200);			// time in milli-sseconds until popup appears
        document.onmousemove=followmouse;

}

function hideprev(){

        getprevobj("previewContainer").visibility="hidden";
        getprevobj("previewContainer").left="-500px";
        document.onmousemove="";
}

function followmouse(e){

    var xcoord=offsetfrommouse[0]
    var ycoord=offsetfrommouse[1]

    var flip_loc_x = 450 	// when too close to the right, flip the position of the floating panel
	var flip_loc_y = 0		// when too close to the bottom within this range, stop moving
    var left_space = 60 	// close the gap when we move the preview to the left of the cursor
    var scrolltop

	// define a large page region that scrolls to which these floating windows should belong
	// this will be a div ID of some large page area
    if (getprevobjnostyle('pageCenter').scrollTop)
        scrolltop=getprevobjnostyle('pageCenter').scrollTop
    else
        scrolltop=truebody().scrollTop


    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)

    if (typeof e != "undefined"){
        if (docwidth - e.pageX < flip_loc_x){
            xcoord = e.pageX - xcoord - flip_loc_x + left_space; // Move to the left side of the cursor
        } 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 - xcoord - flip_loc_x + left_space; // changed from 286 Move to the left side of the cursor
        } 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"

}


