﻿if (navigator.appName.indexOf("Microsoft")!=-1) {
var offsetfrommouse=[2,2];//ie, set sensitivity high, only 1px movement neeeded
}
else{
var offsetfrommouse=[5,5];//non ie browser, sensitivity 5px movement
}
var clickDispatched=false;
var currenty=0;
var currentx=0;
document.onmousemove=followmouseBatch;
document.onmousedown=checkClick || checkClick(event);
var moving=true;

function getWindowHeight(){
var winH = 400;
if (navigator.appName.indexOf("Microsoft")!=-1) {
  if (document.body !=null){
  //only check for the width if the body tag is rendered, else revert to legacy sizing
  winH = (document.body.offsetHeight-25);}
 }//IE
else{
  winH = (window.innerHeight-25);
 }//Not IE
return winH;
}

function getWindowWidth(){
var winW = 650;
if (navigator.appName.indexOf("Microsoft")!=-1) {
  if (document.body !=null){
  //only check for the width if the body tag is rendered, else revert to legacy sizing
  winW = (document.body.offsetWidth-25);}
 }//IE
else{
  winW = (window.innerWidth-25);
 }//Not IE
return winW;
}


function closehoverforced(){
//close the hover with no browser checks
if (document.getElementById("hoverdiv")!=null){
var newspan =  document.getElementById("hoverdiv");
newspan.innerHTML= '';
newspan.style.visibility="hidden";
moving=true;}
}




function closehover(){

if (navigator.appName.indexOf("Microsoft")!=-1) {
if (event.srcElement.id == "dataListWrapper") {
var newspan = document.getElementById('hoverdiv');
newspan.innerHTML= '&nbsp;';
newspan.style.visibility="hidden";
moving=true;}
else {
	//do nothing, this is a child object triggering
}
}//IE
else{
var newspan = document.getElementById('hoverdiv');
newspan.innerHTML= '';
newspan.style.visibility="hidden";
moving=true;
}//Not IE
}//closehover



function followmouseBatch(e){
	var xcoord=offsetfrommouse[0];
	var ycoord=offsetfrommouse[1];

	var docwidth=getWindowWidth();
	var docheight=getWindowHeight();

	var trailInnerDiv = ('hoverdiv');
	var currentimageheight = trailInnerDiv.offsetHeight;
	var currentimagewidth = trailInnerDiv.offsetWidth;

	
	if (typeof e != "undefined"){
		
			xcoord += e.pageX;
		
		if ((e.pageY ) + currentimageheight > docheight){
			ycoord = -ycoord + (e.pageY - currentimageheight);
		} else {
			ycoord += e.pageY;
		}
	} else if (typeof window.event != "undefined"){
		if (event.clientX + currentimagewidth > docwidth){
			xcoord = -xcoord + ((event.clientX) - currentimagewidth); 
		} else {
			xcoord += (event.clientX);
		}
		if (event.clientY + currentimageheight > docheight){
			ycoord = -ycoord + ((event.clientY) - currentimageheight);
		} else {
			ycoord += (event.clientY);
		}
	}

	if(ycoord < 0) { ycoord = ycoord*-1; }

if (navigator.appName.indexOf("Microsoft")!=-1) {
var scrollheight = getScrollXY();
xcoord+=scrollheight[0];
ycoord+=scrollheight[1];
}


	if(moving==true){

coords = getDivCoords("dataListWrapper");

if(xcoord<coords[0]||xcoord>coords[1]||ycoord<coords[2]||ycoord>coords[3]){
//then it's out of bounds, close the window
closehoverforced();}

//    var hovery = document.getElementById("hoverdiv").offsetTop;
//    var height = document.getElementById("hoverdiv").offsetHeight;

//    if((hovery+height)>docheight){
//      ycoord+=(docheight-(hovery+height));}

	gettrailobj().left=xcoord+"px";
	gettrailobj().top=ycoord+"px";
	currentx=xcoord;
	currenty=ycoord;}
	else{
	gettrailobj().left=currentx+"px";
	gettrailobj().top=currenty+"px";
	}

}

function checkClick(e) {
	var rightclick=false;
	if (!e) var e = window.event;
	if (e.which){//ie
		if(e.which == 3){ rightclick=true;}}
	else if (e.button){ //mozilla, safari etc.
		if(e.button == 2){
		rightclick=true;}
		}
if(rightclick==true){	
	if(moving==true){
		moving=false;
		clickDispatched=true;}
	else{
		moving=true;
		clickDispatched=false;}
  document.oncontextmenu=new Function("return false");
}//rightclick true
}//checkclick




function gettrailobj(){
if (document.getElementById("hoverdiv")!=null)
return document.getElementById("hoverdiv").style
else{
//loading is incomplete, or DOM unsupported, make a new temp object, and return it
return document.createElement("tempdiv");}
}

function freezeBox(){
//if(clickDispatched==false){
	moving=false;//}
}

function releaseBox(){
if (navigator.appName.indexOf("Microsoft")!=-1) {
if (event.srcElement.id == "hoverdiv") {

if(clickDispatched==false){
	moving=false;}
}}
else if(clickDispatched==false){

moving=true;
}//only if not dispatched by the click event
}//releaseBox


function hover(hoverID,caption,l,keywords,buttons){
//if(clickDispatched==false){

//put a border on the hovered box
var thumbnail = document.getElementById(hoverID);
thumbnail.className='whiteborder';

var offsetLeft = 0;
var offsetTop = 0;
var newspan = document.getElementById('hoverdiv');
newspan.style.position="absolute";
newspan.style.top=currenty+"px";
newspan.style.left=currentx+"px";
newspan.style.visibility="visible";
newspan.style.backgroundColor = "#ffffff";
newspan.style.border = "1px solid #02215f";
newspan.style.width = l;
newspan.style.padding = "0px 0px 0px 0px";
newspan.innerHTML= 
'<div style="background-color: #02215f; color: #ffffff; padding: 2px 6px 4px 6px;">'+caption+'</div><div style="padding: 5px;"><a href="Horse-Photo-Image-Details.aspx?FILE_NAME='
+hoverID+
'"><img style="border: 1px solid #000000; background-image: url(images/ProgressSpinner.gif); background-repeat:no-repeat;" src="images/hover/'
+hoverID+
'" alt="'
+caption+
'" id="hoverimg" /></a><div style="padding-top: 5px;">'+ buttons + 
'</div><br />'+keywords+'</div>';
moving=true;//}
}


function hoverAcct(hoverID,caption,l,keywords,buttons){
//if(clickDispatched==false){

//put a border on the hovered box
var thumbnail = document.getElementById(hoverID);
thumbnail.className='whiteborder';

var offsetLeft = 0;
var offsetTop = 0;
var newspan = document.getElementById('hoverdiv');
newspan.style.position="absolute";
newspan.style.top=currenty+"px";
newspan.style.left=currentx+"px";
newspan.style.visibility="visible";
newspan.style.backgroundColor = "#ffffff";
newspan.style.border = "1px solid #02215f";
newspan.style.width = l;
newspan.style.padding = "0px 0px 0px 0px";
newspan.innerHTML= 
'<div style="background-color: #02215f; color: #ffffff; padding: 2px 6px 4px 6px;">'+caption+'</div><div style="padding: 5px;"><a href="../Horse-Photo-Image-Details.aspx?FILE_NAME='
+hoverID+
'"><img style="border: 1px solid #000000; background-image: url(../images/ProgressSpinner.gif); background-repeat:no-repeat;" src="../images/hover/'
+hoverID+
'" alt="'
+hoverID+
'" id="hoverimg" /></a><div style="padding-top: 5px;">'+ buttons + 
'</div><br />'+keywords+'</div>';
moving=true;//}
}


function reOutline(hoverID){
//put a border on the hovered box
var thumbnail = document.getElementById(hoverID);
thumbnail.className='blackborder';
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  else{
  scrOfX=0;
  scrOfY=0;}
  return [ scrOfX, scrOfY ];
}

function getDivCoords(divname){
var div = document.getElementById(divname);
var x1=0;
var y1=0;
var x2=0;
var y2=0;
if(div!=null){
y2 = div.offsetHeight;
while(div.offsetParent)
{
x1 += div.offsetLeft;
y1 += div.offsetTop;
x2 = div.offsetWidth;
div=div.offsetParent;
}
x2 += (x1+5);
y2 += (y1+5);
//put in an extra 5px to compensate for borders
}
return [x1,x2,y1,y2];
}

/////////////////////////////////////////////////////////////////////////////

   function ReceiveServerDataCart(arg) 
        {                 
            var spanCart = document.getElementById("spanCart");
            if(spanCart!=null ) 
            
            {          
                var i2 = Number(spanCart.innerHTML); 
                i2++;
                spanCart.innerHTML = String(i2);   
           }//if SpanCart !=Null
        }//RecieveServerData

/////////////////////////////////////////////////////////////////////////////

   function ReceiveServerDataLightbox(arg) 
        {
                //make sure it's in the String type
                var arg = String(arg)       
                         
                if (arg.charAt(0)!="<")                                       
                    {                                                                                                                 
                        alert("This lightbox is full, please select another lightbox to include this photo.");                                                                                         
                    }     
                else
                    {
                        updateLB(arg)
                    } 
            }        
        

/////////////////////////////////////////////////////////////////////////////

 function updateLB(html){
        var spanner = document.getElementById("lightboxHolder");
        spanner.innerHTML = html;
}   

/////////////////////////////////////////////////////////////////////////////

// function updateLB2(arg, LightboxID){

//   var arg = String('Horse-Photo-Lightbox-Postback.aspx?PRODUCT_ID=' + arg + '&LightboxID=' + LightboxID)   
//   document.location.href(arg);   
//    
//}   

/////////////////////////////////////////////////////////////////////////////