var offsetfrommouse=[35,-200]; //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 = 200; // maximum image size.
var previewwidth = currentimageheight + 45;
var prev_h;
var prev_w;
var flip_loc_x = 200; // When we get to loc clientWidth - 445 then move the preview to the left of the cursor
var left_space = 100; // close the gap when we move the preview to the left of the cursor


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, catID){

   var subCat = catID.substring(0,2);
   var subSubCat = catID.substring(0,3);

   var match = /\.swf/.test(imagesrc);

        newHTML = '<div style="padding: 5px; background-color: #FFF; border: 1px solid #888; width:320px;">';
        newHTML = newHTML + '<div align="center" style="padding: 8px 2px 8px 2px;">';
        newHTML = newHTML + '<OBJECT width="304" height="304"><param name="movie" value="../../images/af_vid.swf"></param>';
        newHTML = newHTML + '<param name="flashvars" value="myURL=' + imagesrc + '"></param>';
        newHTML = newHTML + '<EMBED src="../../images/af_vid.swf" style="width:304px; height:304px" type="application/x-shockwave-flash" flashvars="myURL=' + imagesrc + '"></EMBED></OBJECT></div>';
        newHTML = newHTML + '</div>';
        flip_loc_x = 350;
        left_space = 150;

           
        getprevobjnostyle("previewcontainer").innerHTML = newHTML;
        setTimeout('getprevobj("previewcontainer").visibility="visible"',400);
        document.onmousemove=followmouse;
}

function hideprev(){

   // if(document.advsearch.showpreviews.selectedIndex == 0 && document.advsearch.dragging.value == 0){
         
        getprevobj("previewcontainer").visibility="hidden";
        getprevobj("previewcontainer").left="-1500px";
        newHTML = '<div></div>';
        getprevobjnostyle("previewcontainer").innerHTML = newHTML;
        document.onmousemove="";
   // }
}

function followmouse(e){

    var xcoord=offsetfrommouse[0]
    var ycoord=offsetfrommouse[1]
    var flip_loc_y
    var scrolltop=0

  if(getprevobjnostyle('bodyContent').scrollTop)
        scrolltop=getprevobjnostyle('bodyContent').scrollTop
    else
        scrolltop=truebody().scrollTop

        flip_loc_y = 0

    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] - 150 + 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 - flip_loc_x - 150 + 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"

}