// JavaScript Document
function popupHilight(e, imgSrc, href) {
	hideHilight();
	var popupDiv = document.getElementById('hilightDiv');
	var popupImg = document.getElementById('hilightImg');
	popupImg.src = imgSrc;
	positionHilight(e);
	popupDiv.style.visibility = 'visible';
	popupDiv.href = href;
}

function hideHilight() {
	var popupDiv = document.getElementById('hilightDiv');
	popupDiv.style.visibility = 'hidden';
}

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

function positionHilight(e) {

  // Temporary variables to hold mouse x-y pos.s
  var tempX = 0
  var tempY = 0
  var popupDiv = document.getElementById('hilightDiv');
  var popupImg = document.getElementById('hilightImg');

  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  
  var yOffset = getScrollY()
  var xOffset = getScrollX()
  tempX = tempX - popupImg.width - 10 // 6 for 3 px border on each side
  tempY = tempY - (popupImg.height / 2) + yOffset
  
  // catch possible negative values in NS4
  if (tempX < xOffset){tempX = xOffset}
  if (tempY < yOffset){tempY = yOffset}  
  
  // catch possible negative values in NS4
  if (tempY > windowHeight() ){tempY = tempY - (popupImg.height / 2 ) - 10 }  
  
  // move hilight to the entry point
  popupDiv.style.left = tempX + 'px'
  popupDiv.style.top = tempY + 'px'
  
  return false
}

function getScrollX() {
  if (!IE) {
    return window.pageXOffset;
  }
  else {
    if (document.documentElement && document.documentElement.scrollLeft) {
      return document.documentElement.scrollLeft;
    }
    else if (document.body) {
      return document.body.scrollLeft;
    }
  }
  return 0;
}

function getScrollY() {
  if (!IE) {
    return window.pageYOffset;
  }
  else {
    if (document.documentElement && document.documentElement.scrollTop) {
      return document.documentElement.scrollTop;
    }
    else if (document.body) {
      return document.body.scrollTop;
    }
  }
  return 0;
}

function windowWidth() {
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && document.documentElement.clientWidth ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && document.body.clientWidth ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
  return myWidth;
}

function windowHeight() {
  var myHeight = 0;
  if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && document.documentElement.clientHeight ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && document.body.clientHeight ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  return myHeight;
}