﻿/* This needs to go into the mouse move code to make zooming easier*/
/*
if(!document.attachEvent) // Only if not IE
	window.addEventListener('DOMMouseScroll', wheelThing, false);
function wheelThing(anEvent)
{
var ob = document.getElementById('lbPic');
 if ( !ob.style.zoom )
  ob.style.zoom = 1;

// (anEvent.wheelDelta?anEvent.wheelDelta:(-1*anEvent.detail))>0?ob.style.zoom/=1.1:ob.style.zoom*=1.1;
}
function zoomOn(event)
{
var ob = document.getElementById('lbPic');
 zoom_on(event, ob.width, ob.height, ob.src);
}
*/
var lightBox;
function lightBoxObject()
{
//public
if ( document.getElementById( "lbPic" ) ) return;
this.bod = document.getElementsByTagName('body')[0];
this.lbb=document.createElement("div");
this.lbb.id="lbb";
this.lbb.className="lightbox";
this.lbb.style.display="none";
this.lbb.setAttribute('onclick','lightBox.lbClose(event);');
if(navigator.userAgent.indexOf('MSIE')>-1)
  this.lbb.onclick = function() {lightBox.lbClose(event);}
if (this.bod.children)
 this.bod.insertBefore(this.lbb, this.bod.children[0]);
else
 this.bod.appendChild( this.lbb );
// <div class="lightbox" id="lbb" style="display:none; " onclick="lbClose();"></div>

this.lbp=document.createElement("div");
this.lbp.className="lbSubject ajaxLoading"
this.lbp.id = "lbp";
this.lbp.style.display="none";
this.lbp.setAttribute('onclick','lightBox.lbClose(event);');
if(navigator.userAgent.indexOf('MSIE')>-1)
  this.lbp.onclick = function() {lightBox.lbClose(event);}

this.leftDiv=document.createElement("div");
this.leftDiv.id="leftDiv";
this.leftDiv.style.cssFloat="left";
this.leftDiv.style.styleFloat="left";
this.left=document.createElement("img");
this.left.id="left";
this.left.alt="< prior";
this.left.src="/images/leftArrow.png";
this.left.style.cursor="pointer";
this.left.setAttribute('onclick','return lightBox.lbPrior(event);');
if(navigator.userAgent.indexOf('MSIE')>-1)
  this.left.onclick = function (){return lightBox.lbPrior(event);}
this.leftDiv.appendChild( this.left );
this.lbp.appendChild( this.leftDiv );

this.rightDiv=document.createElement("div");
this.rightDiv.id="rightDiv";
this.rightDiv.style.cssFloat="right";
this.rightDiv.style.styleFloat="right";
this.right=document.createElement("img");
this.right.id="right";
this.right.alt="next >";
this.right.src="/images/rightArrow.png";
this.right.style.cursor="pointer";
this.right.setAttribute('onclick','return lightBox.lbNext(event);');
if(navigator.userAgent.indexOf('MSIE')>-1)
  this.right.onclick = function (){return lightBox.lbNext(event);}
this.rightDiv.appendChild( this.right );
this.lbp.appendChild( this.rightDiv );

this.centre=document.createElement("center");
this.centreDiv=document.createElement("div");
this.lbPic=document.createElement("img");
this.lbPic.id="lbPic";
this.lbPic.src="";
this.lbPic.alt="";
this.lbPic.style.visibility = "hidden";
this.lbPic.setAttribute('onmouseover','Abs = true; lightBox.zoom(this, this.alt);');
this.lbPic.setAttribute('onload','return lightBox.doResize(event);');
if(navigator.userAgent.indexOf('MSIE')>-1)
  {
  this.lbPic.onmouseover = function (){Abs = true; lightBox.zoom(this, this.alt);}
  this.lbPic.onload= function (){return lightBox.doResize(event);}
  }

this.centreDiv.appendChild( this.lbPic );
this.centre.appendChild( this.centreDiv );
this.lbp.appendChild( this.centre );

this.bod.insertBefore(this.lbp, this.lbb.nextSibling);

this.bod.setAttribute('onresize','return lightBox.doResize();');
if(navigator.userAgent.indexOf('MSIE')>-1)
  this.bod.onresize = function (){return lightBox.doResize();}
/* Creates elements as follows :-
<div class="lbSubject ajaxLoading" id="lbp" style="display:none;" onclick="lbClose();">
<div id="leftDiv" style="float:left;"><img id="left" alt="< prior" src="/images/leftArrow.png" style="cursor:pointer;" onclick="return lbPrior(event);"></div>
<div id="rightDiv" style="float:right;"><img id="right" alt="next >" src="/images/rightArrow.png" style="cursor:pointer;" onclick="return lbNext(event);"></div>
<center>
<div>
<img id="lbPic" src="" alt="" onmouseover="Abs = true; lightBox.zoom(this, this.alt);" onload="return doResize(event);">
</div>
</center>
</div>
*/
this.adjustX = 0;
this.adjustY = 0;
this.mouse=0;
this.mouseY = 0;
this.mouseX = 0;
this.loading='<div style="background-color: #ffeb77; color: #333333; padding:2px; font-family: verdana,arial,helvetica; font-size: 10px;">Loading...</div>';
this.zoomWidth=320;
this.zoomHeight=240;
this.zoomRatio;
this.zoomWindowLock=0;
this.zoomOffsetX=.5;
this.zoomOffsetY=.5;
this.zoomOffset='smart';
this.zoomAmount=2;
this.zoomAmountMax=12;
this.zoomAmountMin=1;
//this.borderThick = 2;
this.borderThick = 0;
//this.shadowThick=8;
this.shadowThick=0;
this.borderColour='#888888';
this.borderColour='#cccccc'; // Goes with the smart scrolling.
 if(navigator.userAgent.indexOf('MSIE')>-1) {this.adjustX=2; this.adjustY=2;}
 if(navigator.userAgent.indexOf('Opera')>-1) {this.adjustX=0; this.adjustY=0;}
 if(navigator.userAgent.indexOf('Safari')>-1) {this.adjustX=1; this.adjustY=2;}
}

lightBoxObject.prototype.lbClose = function (e)
{
var mediaPlayer = document.getElementById( "MediaPlayer1" );
if ( mediaPlayer )
 mediaPlayer.style.visibility="visible";
Hide('lbb');
Hide('lbp');
this.lbPic.src="";
this.lbPic.priorElement=null;
this.lbPic.nextElement=null;
return stopBubble(e);
}

lightBoxObject.prototype.show = function ( srcPath, srcName, container )
{
var mediaPlayer = document.getElementById( "MediaPlayer1" );
// this ob and its siblings. container is the anchor, its parent is a div, its parent contains all divs
var cp = container.parentNode;
var elements = container.parentNode.parentNode.children;
var priorContainer = null;
var nextContainer = null;
this.lbPic.style.visibility="hidden";
this.rightDiv.style.visibility="hidden";
this.leftDiv.style.visibility="hidden";
if ( mediaPlayer )
 mediaPlayer.style.visibility="hidden";
Show('lbb');Show('lbp');
this.lbPic.src = "/cgi_bin/image.pl?width=" + this.cWidth() + "&height=" + this.cHeight() + "&path="+ srcPath + "&src=" + srcName;
this.lbPic.alt = srcPath + "/" + srcName;
 for (var i = 0; i < elements.length; i++ )
 {
  if ( elements[i].id == cp.id )
   {
   if ( i > 0 )
    {
	priorContainer = elements[i-1];
    }
   if ( (i + 1) < elements.length )
    {
	nextContainer = elements[i+1];
    }
   }
 }
 if ( priorContainer != null )
  {
  this.lbPic.priorElement=priorContainer.children[0];
  this.leftDiv.style.filter="alpha(opacity=95)";
  this.leftDiv.style.opacity="1.0";
  }
 else
  {
  this.lbPic.priorElement=null;
  this.leftDiv.style.filter="alpha(opacity=40)";
  this.leftDiv.style.opacity="0.4";
  }
 if ( nextContainer != null )
  {
  this.lbPic.nextElement=nextContainer.children[0];
  this.rightDiv.style.filter="alpha(opacity=95)";
  this.rightDiv.style.opacity="1.0";
  }
 else
  {
  this.lbPic.nextElement=null;
  this.rightDiv.style.filter="alpha(opacity=40)";
  this.rightDiv.style.opacity="0.4";
  }
}

lightBoxObject.prototype.cHeight = function ()
{
return this.lbb.offsetHeight - (2 * ( this.lbp.offsetTop ));
}
 
lightBoxObject.prototype.cWidth = function ()
{
return parseInt( this.lbp.offsetWidth * 0.95 )-( 2 * this.left.offsetWidth ) - 12;
}

lightBoxObject.prototype.doResize = function ( e )
{
if ( this.lbp.style.display != "none" )
 {
 if ( !this.lbPic.bResizing )
  {
  this.lbPic.bResizing = true;
  this.lbPic.height = this.cHeight();
  if ( this.lbPic.offsetWidth >= this.cWidth() )
   this.lbPic.height *= (this.cWidth() / this.lbPic.offsetWidth);

  var topPad = (this.lbPic.offsetHeight - this.left.offsetHeight ) / 2;

  this.leftDiv.style.height = this.lbPic.offsetHeight + "px";
  if ( this.leftDiv.offsetHeight > (2*this.left.offsetHeight) )
   {
   this.leftDiv.style.height = this.lbPic.offsetHeight-topPad + "px";
   this.leftDiv.style.paddingTop = topPad +"px";
   }

  this.rightDiv.style.height = this.lbPic.offsetHeight + "px";
  if ( this.rightDiv.offsetHeight > (2*this.right.offsetHeight) )
   {
   this.rightDiv.style.height = this.lbPic.offsetHeight-topPad + "px";
   this.rightDiv.style.paddingTop = topPad +"px";
   }
  
  this.lbPic.newHeight = this.lbPic.height;
  this.lbPic.bResizing = false;
  this.rightDiv.style.visibility="visible";
  this.leftDiv.style.visibility="visible";
  this.lbPic.style.visibility="visible";
  }
 }
return (e?stopBubble(e):false);
}

function stopBubble( e )
{
var evt = e?e:window.event?window.event:null;
 if(evt)
  {
  if ( evt.stopPropagation )
   evt.stopPropagation();
  else
   evt.cancelBubble = true;
  }
return false;
}

lightBoxObject.prototype.lbPrior = function ( e )
{
if ( this.lbPic.priorElement )
 if ( this.lbPic.priorElement.onclick )
  this.lbPic.priorElement.onclick();
 else
  if ( this.lbPic.priorElement.click )
   this.lbPic.priorElement.click();
  else
   if (this.lbPic.priorElement.fireEvent)
    this.lbPic.priorElement.fireEvent('onclick');

return stopBubble(e);
}

lightBoxObject.prototype.lbNext = function ( e )
{
if ( this.lbPic.nextElement )
 if ( this.lbPic.nextElement.onclick )
  this.lbPic.nextElement.onclick();
 else
  if ( this.lbPic.nextElement.click )
   this.lbPic.nextElement.click();
  else
   if (this.lbPic.nextElement.fireEvent)
    this.lbPic.nextElement.fireEvent('onclick');

return stopBubble(e);
}

lightBoxObject.prototype.zoom = function (obj, highRes)
{
 this.zoomRatio=this.zoomHeight/this.zoomWidth;
 if(this.zoomOffsetX > 1)
  {
  this.zoomOffset='dumb';
  this.zoomOffsetx=this.zoomOffsetX/this.zoomWidth;
  this.zoomOffsety=this.zoomOffsetY/this.zoomHeight;
 }

 if(typeof(highRes) != typeof('')) {highRes=obj.src}
 this.magDiv=document.createElement("div");
 this.magDiv.style.width=obj.width + "px";
 this.magDiv.style.height=obj.height + "px";
 this.magDiv.style.overflow='hidden';
 this.magDiv.id='magDiv';
 this.magDiv.style.margin='0px';
 this.magDiv.style.padding='0px';
 this.magDiv.style.position='absolute';
 //hi decent gentlemen
 this.magDiv.style.backgroundColor='transparent';

 if(typeof(this.magDiv.style.filter) != typeof(nosuchthing))
  {
  //hi IE
  if(navigator.appVersion.indexOf('Mac') == -1)
   { //hi Mac IE
   this.magDiv.style.filter='alpha(opacity=0)';
   if ( navigator.userAgent.indexOf('Opera') == -1 )
    this.magDiv.style.backgroundColor='#ffffff'; // without this, no glass appears in IE, but Opera works
   }
  }
 this.magDiv.setAttribute('onclick','if(this.stopClickEvent){ stopBubble(event); this.stopClickEvent = false;}');
 if(navigator.userAgent.indexOf('MSIE')>-1)
  this.magDiv.onclick = function() { if(this.stopClickEvent){ stopBubble(event); this.stopClickEvent = false;} }

 this.magDiv.setAttribute('onmousemove','lightBox.handleMouse(event,this);');
 this.magDiv.setAttribute('onmousedown','lightBox.handleMouse(event,this);');
 this.magDiv.setAttribute('onmouseup','lightBox.handleMouse(event,this);');
 this.magDiv.setAttribute('onmouseout','lightBox.handleMouse(event,this);');

 if(navigator.userAgent.indexOf('MSIE')>-1)
  {
  this.magDiv.onmousemove = function() {lightBox.handleMouse(event,this);}
  this.magDiv.onmousedown = function() {lightBox.handleMouse(event,this);}
  this.magDiv.onmouseup = function() {lightBox.handleMouse(event,this);}
  this.magDiv.onmouseout = function() {lightBox.handleMouse(event,this);}
  }
 obj.parentNode.insertBefore(this.magDiv,obj);
 this.magDiv.left=obj.offsetLeft;
 this.magDiv.style.left=obj.offsetLeft+"px"; // position of trick window, more left moves it away from mouse pointer etc...
 
 
 this.mag=document.createElement("div");
 this.mag.style.margin='0px 10px 10px 0px';
 this.mag.style.padding='0px';
// this.mag.className="dropshadow";
 this.mag.id='mag';
 this.mag.style.width='0px';
 this.mag.style.height='0px';
// this.mag.style.border="thin solid orange";
 this.mag.style.backgroundColor="transparent";
 this.mag.style.overflow='hidden';
 this.mag.style.position='absolute';
 this.mag.style.display='none';
 if ( this.shadowThick > 0 )
  {
  this.shadow=document.createElement("div");
  this.shadow.id="shadow";
  this.shadow.style.overflow='visible';
  this.shadow.style.position="absolute";

  this.shadow.style.top=this.shadowThick+"px";
  this.shadow.style.left=this.shadowThick+"px";

  this.shadow.style.width = (this.zoomAmount*parseInt(obj.width))+this.shadowThick+'px';
  this.shadow.style.height= (this.zoomAmount*parseInt(obj.height))+this.shadowThick+'px';

  this.shadow.style.background="url(/images/backgrounds/shadow-png.png) no-repeat bottom right";
  this.shadow.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale, src='/images/backgrounds/shadow-png.png')";
//  this.magDiv.appendChild( this.shadow );
  }

/*
.dropshadow{
	float:left;
	clear:left;	
	background: url(/images/backgrounds/shadow-png.png) no-repeat bottom right !important; /* nice browsers (e.g. Firefox/Opera/Safari) ONLY notice this line*/
/*	background: none no-repeat top left; /* we need to clear the background graphic for the alphaloader to work in IE5.5 and 6 */
/*	filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale, src='/images/backgrounds/shadow-png.png'); 
	margin: 10px 10px 10px 15px;
}
*/
 this.iMag = document.createElement("img");
 this.iMag.style.margin= '0px';
 this.iMag.style.padding= '0px';
 this.iMag.style.width = (this.zoomAmount*parseInt(obj.width))+'px';
 this.iMag.style.height= (this.zoomAmount*parseInt(obj.height))+'px';
// this.iMag.style.width = "100%";
// this.iMag.style.height= "100%";

 this.iMag.style.position="relative";
 this.iMag.alt="";
 this.iMag.title="Drag the mouse to resize and zoom.";
 this.iMag.id="iMag";
 this.iMag.setAttribute('onload',"if((!this.readyState || this.readyState=='complete')&&document.getElementById('loadingMsg')) {lightBox.magLoading.style.display='none';}");
 if(navigator.userAgent.indexOf('MSIE')>-1)
   this.iMag.onload = function ()
   {
   if ( (!this.readyState || this.readyState=='complete') && document.getElementById('loadingMsg') )
    {
    lightBox.magLoading.style.display='none';
    }
   }
// this.magD1.appendChild( this.iMag );
 this.mag.appendChild( this.iMag );
 if(highRes != obj.src)
  {
  this.magLoading=document.createElement("div");
  this.magLoading.id='loadingMsg';
  this.magLoading.style.margin= (this.shadowThick+this.borderThick)+'px 0px 0px '+(this.shadowThick+this.borderThick)+'px';
  this.magLoading.style.padding='0px';
  this.magLoading.style.position='absolute';
  this.magLoading.innerHTML = this.loading;
  this.mag.appendChild( this.magLoading );
  }

 //marker - zoomer
 obj.parentNode.insertBefore(this.mag, this.magDiv);
 this.mag.style.left=obj.offsetLeft+"px"; // position of trick window more left makes mouse more left in window.

 if (obj.src != highRes)
  {
  this.iMag.src = highRes;
  }
 else
  {
  this.iMag.src = obj.src;
  }
 this.resize(obj);
}

lightBoxObject.prototype.resize = function (obj)
{
 sbr=0; sbl=0;
 if(this.zoomWidth-2*this.borderThick-3*this.shadowThick < 22) {sbr=1}
 if(this.zoomHeight-2*this.borderThick-3*this.shadowThick < 22) {sbr=1}
 if(this.zoomWidth > parseFloat(obj.width)) {sbl=1;}
 if(this.zoomHeight > parseFloat(obj.height)) {sbl=1}
 
 if(sbr==1 && sbl == 1)
  {
  this.zoomWidth=parseFloat(obj.width)/2;
  this.zoomHeight=parseFloat(obj.height)/2;
  this.zoomRatio=this.zoomHeight/this.zoomWidth;
  }

 if(sbr==1)
  {
  if(this.zoomWidth<this.zoomHeight)
   {
   this.zoomHeight=this.zoomHeight/this.zoomWidth*(22+2*this.borderThick+3*this.shadowThick);
   this.zoomWidth=22+2*this.borderThick+3*this.shadowThick;
   }
  else
   {
   this.zoomWidth=this.zoomWidth/this.zoomHeight*(22+2*this.borderThick+3*this.shadowThick);
   this.zoomHeight=22+2*this.borderThick+3*this.shadowThick;
   }
  }

 if(sbl==1)
  {
  if(parseFloat(obj.width)/parseFloat(obj.height) > this.zoomWidth/this.zoomHeight)
   {
   this.zoomHeight=parseFloat(obj.height);
   this.zoomWidth=this.zoomHeight/this.zoomRatio;
   }
  else
   {
   this.zoomWidth=parseFloat(obj.width);
   this.zoomHeight=this.zoomRatio*this.zoomWidth;
   }
  }

 this.zoomWidth=Math.floor(this.zoomWidth/2)*2;
 this.zoomHeight=Math.floor(this.zoomHeight/2)*2;

 this.mag.style.width=this.zoomWidth+'px';
 this.mag.style.height=this.zoomHeight+'px';
}

lightBoxObject.prototype.yPos = function (obj)
{
var curtop = 0;
 if(!obj) {return 0;}
 if (obj.offsetParent)
  {
  while (obj)
   {
   curtop += obj.offsetTop;
   obj = obj.offsetParent;
   }
  }
 else
  if (obj.y)
   {   curtop += obj.y;   }
 return curtop;
}

lightBoxObject.prototype.xPos = function (obj)
{
var curleft = 0;
 if(!obj) {return 0;}
var txt="finding X ";
 if (obj.offsetParent)
  {
  while (obj)
   {
   curleft += obj.offsetLeft;
   obj = obj.offsetParent;
   }
  }
 else
  if (obj.x)
   {   curleft += obj.x;   }
 return curleft;
}

function getScrollWidth()
{
var w = window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft;
return w ? w : 0;
} 

function getScrollHeight()
{
var h = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
return h ? h : 0;
}

lightBoxObject.prototype.handleMouse = function (evt,obj)
{
var evt = evt?evt:window.event?window.event:null; if(!evt) { return false; }
 if ( !obj ) { return false; }
 if(evt.pageX)
  {
  nowx=evt.pageX-getScrollWidth()-this.xPos(obj)-this.adjustX;
  nowy=evt.pageY-getScrollHeight()-this.yPos(obj)-this.adjustY;
  }
 else
  {
  if(document.documentElement && document.documentElement.scrollTop)
   {
   nowx=evt.clientX+getScrollWidth()-this.xPos(obj)-this.adjustX;
   nowy=evt.clientY+(Abs?0:getScrollHeight())-this.yPos(obj)-this.adjustY;
   }
  else
   {
   nowx=evt.x+getScrollWidth()-this.xPos(obj)-this.adjustX;
   nowy=evt.y+(Abs?0:getScrollHeight())-this.yPos(obj)-this.adjustY;
   }
  }

 if(evt.type == 'mousemove')
  {
  this.setwin(obj,nowx,nowy);
  }
 else
  if(evt.type == 'mousedown')
   {
   this.mouse=1; //left: 1, middle: 2, right: 3
   this.mouseY=nowy;
   this.mouseX=nowx;
   }
  else
   if(evt.type =='mouseup')
    {
    this.mouse=2;
    }
   else
    if(evt.type =='mouseout')
     {
     this.mouse=0;
     if(navigator.appVersion.indexOf('Mac') == -1 || navigator.appVersion.indexOf('MSIE') == -1)
      { //hi Mac IE
      x=obj.parentNode;
      x.removeChild(x.getElementsByTagName('div')[0]);
      x.removeChild(x.getElementsByTagName('div')[0]);
      }
     }
}

lightBoxObject.prototype.setwin = function (obj,nowx,nowy)
{
 if ( ! this.mag )
  { return false; }
 if(this.zoomOffset=='smart')
  {
  this.zoomOffsetX=.1+.8*nowx/parseFloat(obj.style.width);
  this.zoomOffsetY=.1+.8*nowy/parseFloat(obj.style.height);
  }
var zoy = this.zoomOffsetY;
var zox = this.zoomOffsetX;
var zr = this.zoomRatio;
var bt = this.borderThick;
var st = this.shadowThick;
 this.mag.style.display='block'; /* make it visible */
 if(this.mouse == 1)
  {
  obj.stopClickEvent=true; /* This prevents the click event closing the magnifier immediately after a drag event */
  if(Math.abs(nowy-this.mouseY) >= 1) /* This bit does the hold-mouse-down-to-change-zoom-or-size thing */
   {
   this.zoomAmount *=((nowy>this.mouseY)?(0.909):(1.1));
   this.mouseY=nowy;
   if(this.zoomAmount < this.zoomAmountMin) {this.zoomAmount=this.zoomAmountMin;}
   if(this.zoomAmount > this.zoomAmountMax) {this.zoomAmount=this.zoomAmountMax;}
   this.iMag.style.width = (this.zoomAmount*parseInt(this.lbPic.offsetWidth))+'px';
   this.iMag.style.height= (this.zoomAmount*parseInt(this.lbPic.offsetHeight))+'px';
   }
  if(Math.abs(nowx-this.mouseX) >= 12 && this.zoomWindowLock==0)
   {
   this.zoomWidth*=((nowx>this.mouseX)?(1.1):(0.909));
   this.zoomHeight=this.zoomWidth*zr;
   this.mouseX=nowx;
   }
  this.resize(obj);
  }
var za = this.zoomAmount;
var zw = this.zoomWidth;
var zh = this.zoomHeight;

 this.mag.style.marginLeft=parseInt(nowx-(zw -2*bt-2*st)*zox-bt-st)+'px';
 this.mag.style.marginTop=parseInt( nowy-(zh-2*bt-2*st)*zoy-bt-st)+'px';

 clip1=0; clip2=zw; clip3=zh; clip4=0;
 nwidth=zw;
 nheight=zh;
 tmp=(1-2*zox)*(bt+st);
 
 if(nowx-zw*zox < tmp)
  {
  clip4=zw*zox-nowx + tmp;
  }
 else
  if(parseFloat(nowx-zw*zox+zw) > parseFloat(obj.style.width)+tmp)
   {
   clip2= zw*zox - nowx + parseFloat(obj.style.width) + tmp;
   nwidth=zw*zox - nowx + parseInt(obj.style.width) + bt + st;
   }
 
 tmp=(1-2*zoy)*(bt+st);
 
 if(nowy-zh*zoy < tmp)
  {
  clip1=zh*zoy-nowy+tmp;
  }
 else
  if(parseFloat(nowy-zh*zoy+zh) > parseFloat(obj.style.height)+tmp)
   {
   clip3= zh*zoy - nowy + parseFloat(obj.style.height)+tmp;
   nheight=zh*zoy - nowy + parseFloat(obj.style.height)+bt+st;
   }
 this.mag.style.width=nwidth+'px';
 this.mag.style.height=nheight+'px';
 if ( this.shadowThick )
  {
  this.shadow.style.width = nwidth+this.shadowThick+'px';
  this.shadow.style.height = nheight+this.shadowThick+'px';
  }

 this.mag.style.clip='rect('+clip1+'px,'+clip2+'px,'+clip3+'px,'+clip4+'px)'; // Stops trick window going outside subject photo.

 if(nowy-zoy*(zh-2*bt-2*st) < 0)
  {  t=-(nowy-zoy*(zh-2*bt-2*st))  } 
 else
  if(nowy-zoy*(zh-2*bt-2*st) > parseFloat(obj.style.height)-zh+bt*2+st*2)
   {   t=-za*parseFloat(obj.style.height)+zh-bt*2-st*2-((nowy-zoy*(zh-2*bt-2*st))-(parseFloat(obj.style.height)-zh+bt*2+st*2));   }
  else
   {   t=(-za*parseFloat(obj.style.height)+zh-bt*2-st*2)/(parseFloat(obj.style.height)-zh+bt*2+st*2)*(nowy-zoy*(zh-2*bt-2*st));   }

 this.iMag.style.marginTop=t+'px';

 if (nowx-zox*(zw-2*bt-2*st) < 0)
  {  t=-(nowx-zox*(zw-2*bt-2*st))  } 
 else
  if (nowx-zox*(zw-2*bt-2*st) > parseFloat(obj.style.width)-zw+bt*2+st*2)
   {   t=-za*parseFloat(obj.style.width)+zw-bt*2-st*2-((nowx-zox*(zw-2*bt-2*st))-(parseFloat(obj.style.width)-zw+bt*2+st*2));   }
  else
   {   t=(-za*parseFloat(obj.style.width)+zw-bt*2-st*2)/(parseFloat(obj.style.width)-zw+bt*2+st*2)*(nowx-zox*(zw-2*bt-2*st));   }

 this.iMag.style.marginLeft=t+'px';
}