jQuery(document).ready
(function($) {
 var firstimg=$('.whgallery:first').attr('href');
 $('.ngg-galleryoverview').prepend('<div id="ngg-fullsize"><img src="'+firstimg+'"></div>');
 $('.whgallery').click(function() {
  var data=$(this).attr('href');
  $('#ngg-fullsize').html('<img src="'+data+'">');
  return false;
 });
});

function doresize(data,maxWidth,maxHeight) {
 jQuery(document).ready(function($) {
  $(data).each(function() {
   var ratio = 0;          // Used for aspect ratio
   var width = $(this).width();    // Current image width
   var height = $(this).height();  // Current image height

   var newWidth = width;
   var newHeight = height;

   // Check if the current width is larger than the max
   if(width > maxWidth){
    ratio = maxWidth / width;   // get ratio for scaling image
    newWidth=maxWidth;
    newHeight=height * ratio;
    height = height * ratio;    // Reset height to match scaled image
    width = width * ratio;    // Reset width to match scaled image
   }

   // Check if current height is larger than max
   if(height > maxHeight){
    ratio = maxHeight / height; // get ratio for scaling image
    newWidth=width * ratio;
    newHeight=maxHeight;
    height = height * ratio;    // Reset height to match scaled image
    width = width * ratio;    // Reset width to match scaled image
   }
   $(this).css("height", newHeight);
   $(this).css("width", newWidth);
   $(this).parent().css("height", newHeight);
   $(this).parent().css("width", newWidth);
  });
 });
}

jQuery(document).ready
(function($) {
 var maxWidth=400;
 var maxHeight=400;
 var firstimg=$('.gallery-icon a:first').attr('href');
 $('.gallery').prepend('<div id="gallery-fullsize"><img src=""></div>');
 $('#gallery-fullsize').css({'margin' : "0 auto", 'overflow' : "hidden"});
 $('#gallery-fullsize img').attr("src",firstimg);
 $('.gallery-icon a').click(function() {
  var data=$(this).attr('href');
  $('#gallery-fullsize img').attr("src",data);
  $('#gallery-fullsize img').css({'height' : '', 'width' : ''});
  return false;
 });
 $('#gallery-fullsize').hover(function () {
  var data=$('#gallery-fullsize img').attr('src');
  $('#gallery-fullsize img').css({'position' : 'relative', 'width' : '', 'height' : ''});
  $('#gallery-fullsize img').addClass('noresize');
 },
 function () {
  var data=$('#gallery-fullsize img').attr('src');
  $('#gallery-fullsize img').attr("src",data);
  $('#gallery-fullsize img').css({'position' : ''});
  $('#gallery-fullsize img').removeClass('noresize');
 });
 $('#gallery-fullsize').mousemove(function(e){
  var divWidth = $('#gallery-fullsize').width();
  var divHeight = $('#gallery-fullsize').height();
  var imW = $('#gallery-fullsize img').width();
  var imH =  $('#gallery-fullsize img').height();
  var dOs =  $('#gallery-fullsize').offset();
  var leftPan = (e.pageX - dOs.left) * (divWidth - imW) / divWidth;
  var topPan =  (e.pageY - dOs.top) * (divHeight - imH) / divHeight;
  $('#gallery-fullsize img').css({'left' : leftPan, 'top' : topPan});
 });
  $('#gallery-fullsize img').load(function() {
  doresize('#gallery-fullsize img',maxWidth,maxHeight);
 });
});

