var offsetfrommouse=[50,-25]; //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 currentimageheight = 120; // maximum image size.
var previewwidth = currentimageheight + 25;
var prev_h;
var prev_w;

var dnd_thm_loc;
var dnd_big_thm_loc;
var dnd_hoid;

var lbx_items = [];
var num_lbx_items = 0;
var last_lbx_item = null;
var start_lbx_item = null;

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 add_to_lbx(n,tloc,btloc,hoid){

    var lbxfloater = window.frames['lbxframe'];
    var list = lbxfloater.document.forms.lightbox.lbx;

    if(n == "undefined") return;

    if(lbxfloater.document.forms.lightbox.lightbox_total.value >= 48){
        alert("Your light box is full. No more items can be added.");
        return;
    }


    lbxfloater.document.forms.lightbox.action.value = 'add';
    lbxfloater.document.forms.lightbox.OBJECT_ID.value = n;
    lbxfloater.document.forms.lightbox.THM_URI_1.value = tloc;
    lbxfloater.document.forms.lightbox.THM_URI_2.value = btloc;
    lbxfloater.document.forms.lightbox.lastitemadded.value = n;
    //lbxfloater.document.forms.lightbox.lbxpage.value = lbxfloater.document.forms.lightbox.lbxlastpage.value;
    lbxfloater.document.forms.lightbox.submit();
}

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, preview){
  var newHTML = "";
  if (imagesrc.substr(imagesrc.length-3, 3) == "swf") {
    newHTML += AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0', 'src', imagesrc , 'quality','high','pluginspage','http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash', 'movie', imagesrc );
    
  } else { 
    newHTML += '<div style="padding: 5px;">';
    newHTML += '<div align="left" style="padding: 8px 2px 8px 2px;"><img src="' + imagesrc + '" border="0"></div>';
    newHTML += '</div>';
  }
  document.getElementById(preview).innerHTML = newHTML;

}


function hideprev(){
  document.onmousemove="";
}

function followmouse(e){
    var xcoord=offsetfrommouse[0]
    var ycoord=offsetfrommouse[1]

    var flip_loc_x = 145 // 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

//    if(document.advsearch.dragging.value == "0") return;

    if(getprevobjnostyle('bodycontent').scrollTop)
        scrolltop=getprevobjnostyle('bodycontent').scrollTop
    else
        scrolltop=truebody().scrollTop
/*
    if (document.forms.advsearch.toggle_lightbox.value == 1)
        flip_loc_y = 100
    else
        flip_loc_y = 200
*/

        flip_loc_y = 200;
    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)
//prev_h = -200;

    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));
            //ycoord += scrolltop + event.clientY;
        } else {
            //ycoord += event.clientY + scrolltop - Math.max(0,(flip_loc_y + prev_h + event.clientY - docheight));
			ycoord += scrolltop + event.clientY;
        }
    }

	ycoord = 106;
//getprevobjnostyle('copyrightcontent').innerHTML = ycoord + "px";
//getprevobjnostyle('copyrightcontent').innerHTML = (ycoord);

//	alert(getprevobjnostyle('copyrightcontent').innerHTML);

    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"
}


function changePict(e) {
        newHTML = "<img src='" + e + "' class='imgthumb'>";
		document.getElementById("modeldisplay").innerHTML = newHTML;
}
function changeMovie(e) {
		var so = new SWFObject("../video/play.swf", "video", "320", "276", "7");
		so.write("modeldisplay");
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
