function createGalleryThumbs(containerid, classname, W, H)
{
  $(document).ready(function()
  {
    $('#'+containerid+' .'+classname).each(function()
    {
      var imgsrc = $(this).attr('src');
      var rootwidth = parseInt( $(this).css('width') );
      var rootheight = parseInt( $(this).css('height') );

      var wfac = rootwidth / W;
      var hfac = rootheight / H;

      if(wfac < hfac)
      {
        cwidth = Math.round( rootwidth / wfac );
        cheight = Math.round( rootheight / wfac );
      }
      else
      {
        cwidth = Math.round( rootwidth / hfac );
        cheight = Math.round( rootheight / hfac );
      }

      var corleft = -1 * Math.round( ( cwidth - W ) / 2 );
      var cortop = -1 * Math.round( ( cheight - H ) / 2 );

      var thumb = $('<a></a>')
                  .attr('class', 'thumb')
                  .attr('href', 'javascript:viewGalleryPic(\''+imgsrc+'\')')
                  .css('position', 'relative')
                  .css('display', 'block')
                  .css('width', W+'px')
                  .css('height', H+'px')
                  .css('overflow', 'hidden');

      $('<img>')
      .attr('class', 'thumbimage')
      .attr('src', imgsrc)
      .attr('width', cwidth)
      .attr('height', cheight)
      .attr('border', '0')
      .css('position', 'absolute')
      .css('left', corleft+'px')
      .css('top', cortop+'px')
      .appendTo(thumb);

      $(this).parent().append(thumb);
      $(this).remove();
    });
  });
}

function adjustThumbs()
{
  $(document).ready(function()
  {
    $('.thumbimage').each(function()
    {
      var rootwidth = parseInt( $(this).css('width') );
      var rootheight = parseInt( $(this).css('height') );

      if(rootwidth == 0) rootwidth = 200;
      if(rootheight == 0) rootheight = 200;

      var wfac = rootwidth / 50;
      var hfac = rootheight / 50;

      if(wfac < hfac)
      {
        cwidth = Math.round( rootwidth / wfac );
        cheight = Math.round( rootheight / wfac );
      }
      else
      {
        cwidth = Math.round( rootwidth / hfac );
        cheight = Math.round( rootheight / hfac );
      }

      var corleft = -1 * Math.round( ( cwidth - 50 ) / 2 );
      var cortop = -1 * Math.round( ( cheight - 50 ) / 2 );


      $('.thumbimage')
      .attr('width', cwidth)
      .attr('height', cheight)
      .css('left', corleft+'px')
      .css('top', cortop+'px');
    });
  });
}
