﻿   /*Small javascript program to zoom into an image that has a larger resolution in pixels than is currently being displayed in an image tag on an HTML page. A crude analogue of the Silverlight Deep Zoom functionality. Requires the entire full-resolution jpeg or png image to be already loaded in the browser. 
   */
   
   var inc = 40; // number of steps in zoom, duration msec
   var msec = 50; // length of time in milliseconds between each step in zoom
   var initial_width = 571; // initial pixel width of image, from HTML style   
   var final_width = 769; // final_width + initial width = actual width of image in pixels 
   var initial_height = 230; // initial pixel height of image, from HTML style
   var final_height = 310; // final_height + initial height = actual height of full-resolution image in pixels
   var initial_top = 0; // initial 'top' value of image, from HTML style
   var final_top = -305;
   var k = 0;
   var zoom_in_and_out;
   var priddy_rainbo;
   
function zoom_priddy_in()  {
   window.clearTimeout(zoom_in_and_out);
   
   if (k<inc) {
   k++;
   var mw = final_width*Math.sqrt(Math.sin(k*Math.PI/(2*inc)));
   var intermediate_width = initial_width + mw;
   var mh = final_height*Math.sqrt(Math.sin(k*Math.PI/(2*inc)));
   var intermediate_height = initial_height + mh;
   var mt = final_top*Math.sqrt(Math.sin(k*Math.PI/(2*inc)));
   var intermediate_top = initial_top + mt;
   //plug intermediate values into style
   priddy_rainbo = document.getElementById("priddy_rainbow");
   priddy_rainbo.style.width = Math.floor(intermediate_width) + "px";
   priddy_rainbo.style.height = Math.floor(intermediate_height) + "px";
   priddy_rainbo.style.top = Math.floor(intermediate_top) + "px";
   zoom_in_and_out = window.setTimeout("zoom_priddy_in()",msec);
   if(k>=inc) {
      window.clearTimeout(zoom_in_and_out);
      }
   }
   
   return false;
}


function zoom_priddy_out()  {
   window.clearTimeout(zoom_in_and_out);
   
   if (k>0) {
   k--;
   var mw = final_width*Math.sqrt(Math.sin(k*Math.PI/(2*inc)));
   var intermediate_width = initial_width + mw;
   var mh = final_height*Math.sqrt(Math.sin(k*Math.PI/(2*inc)));
   var intermediate_height = initial_height + mh;
   var mt = final_top*Math.sqrt(Math.sin(k*Math.PI/(2*inc)));
   var intermediate_top = initial_top + mt;
   //plug intermediate values into style
   priddy_rainbo.style.width = Math.floor(intermediate_width) + "px";
   priddy_rainbo.style.height = Math.floor(intermediate_height) + "px";
   priddy_rainbo.style.top = Math.floor(intermediate_top) + "px";
   zoom_in_and_out = window.setTimeout("zoom_priddy_out()",msec);
   if(k<=0) {
      window.clearTimeout(zoom_in_and_out);
      }
   }
   
   return false;
}

