/***************************************************************\
 magnifier functions 
\***************************************************************/
<!--

var imgbase;
var magimg;
var magt;
var magr;

var magnifierwidth = 285;
var magnifierheight = 100;

var shiftx=0;
var shifty=0;

var scalex;
var scaley;

var magimgw;
var magimgh;

function loadMagnifierTool() {
  imgbase = xGetElementById('image_basic');
  magt = xGetElementById('magnify');
  magr = xGetElementById('magnifier');
  magimg = xGetElementById('magnified-image');

  magimgw = xWidth(magimg);
  magimgh = xHeight(magimg);

  scalex = (xWidth(magimg)-magnifierwidth)/(xWidth(imgbase)-magnifierwidth);
  scaley = (xHeight(magimg)-magnifierheight)/(xHeight(imgbase)-magnifierheight);

  xClip(magr,0,magnifierwidth,magnifierheight,0);
  xMoveTo(magr,xLeft(imgbase),xTop(imgbase));
  magr.totalx=0;
  magr.totaly=0;
  xEnableDrag(magr,null,onMagrDrag,null);

  xShow(magt);
}

function showElement(name) {
  ele = xGetElementById(name);
  xShow(ele);
	
}
function hideElement(name) {
  ele = xGetElementById(name);
  xHide(ele);
	
}


function onMagrDrag(ele,mdx,mdy) {
  var clipx; var clipy; var movex; var movey;

  //clip window is set with respect to ele's coordinate system
  clipx=(mdx*scalex)-(xLeft(ele)-ele.totalx); //xLeft(ele) is always a number less than or equal to zero
  clipy=(mdy*scaley)-(xTop(ele)-ele.totaly);  //xTop(ele) is always a number less than or equal to zero
  // constrain values so that they lie within the big image
  if(clipx < 0) { clipx = 0; }
  if(clipx+magnifierwidth > magimgw) { clipx = magimgw-magnifierwidth; }
  if(clipy < 0) { clipy = 0; }
  if(clipy+magnifierheight > magimgh) { clipy = magimgh-magnifierheight; }
  xClip(ele,clipy,magnifierwidth+clipx,magnifierheight+clipy,clipx);

  //keep track of total x y displacement so that we can offset ele's x y position corresponding to mouse movement.
  ele.totalx+=mdx;
  ele.totaly+=mdy;
  //constrain values so that they lie within the small image
  if(ele.totalx > xWidth(imgbase)-magnifierwidth) { ele.totalx = xWidth(imgbase)-magnifierwidth; }
  if(ele.totalx < 0) { ele.totalx = 0; }
  if(ele.totaly > xHeight(imgbase)-magnifierheight) { ele.totaly = xHeight(imgbase)-magnifierheight; }
  if(ele.totaly < 0) { ele.totaly = 0; }

  // ele is positioned with respect to its parent's coordinate system
  movex=-clipx+ele.totalx;
  movey=-clipy+ele.totaly;
  xMoveTo(ele,movex,movey); 
	
}

//-->

