var MaxPicWidth = 750;

var ThumbsPerRow = 1;
var ThumbsColCount = 0;
var ThumbsArray = new InitThumbs();
var ThumbsCount = 0;
var CurrentThumbIDX = 0;
var ThumsContent = '';
function ThumbsStart(max_thumb_width)
{
  ThumsContent = '';
  ThumbsCount = 0;
  ThumbsColCount = 0;
  
  ThumbsPerRow = Math.floor((MaxPicWidth-2) / (max_thumb_width + 2)); // ie 2 x (cellpadding + tableborder) + 2 for highlighted image's border
  if (ThumbsPerRow <= 0)
    ThumbsPerRow = 1;
  
  ThumsContent += '<center>';  
  ThumsContent += '<table cellspacing="0" cellpadding="0" border="1" style="margin-bottom:2px;">';
  ThumsContent += '<tr>';
};
function AddThumb(thumb_url, thumb_w, thumb_h, img_url, img_w, img_h, caption)
{
  ThumbsArray[ThumbsCount++] = new NewThumb(thumb_url, thumb_w, thumb_h, img_url, img_w, img_h, caption);
  
  ThumbsColCount++;
  if (ThumbsColCount > ThumbsPerRow)
  {
    ThumbsColCount = 1;
    ThumsContent += '<\/tr>';
    
    ThumsContent += '<tr>';
  };
    
  var border = '0';
  if (ThumbsCount == 1)
  {
    border = '1';
  };
  
  var style_string = '';
  if (ThumbsCount == 1)
  {
    style_string = ' style="cursor:hand;border: 1px solid black;" ';
  }
  else
  {
    style_string = ' style="cursor:hand;border: 0px solid black;" ';
  };
  
  ThumsContent += '<td align="center" valign="top"><a href="javascript:DoThumbClick(' + (ThumbsCount-1) + ')">'
    + '<img src="' + thumb_url + '" width="' + thumb_w + '" height="' + thumb_h 
    + '" border="' + border + '" '
    + style_string + ' name="thumb_' + (ThumbsCount-1) + '" id="thumb_' + (ThumbsCount-1) + '"'
    + ' alt="' + caption + '"><\/a><\/td>';
};
function ThumbsEnd()
{
  var i;
  
  if (ThumbsCount > ThumbsPerRow)
  {
    for (i = ThumbsColCount+1; i <= ThumbsPerRow; i++)
    {
      ThumsContent += '<td>&nbsp;<\/td>';
    };
  };
  ThumsContent += '<\/tr>';
  ThumsContent += '<\/table>';
    
  if (ThumbsCount > 0)
  {
    var actual_width = ThumbsArray[0].img_w;
    var actual_height = ThumbsArray[0].img_h;
    if ((actual_width <= 1) || (actual_height <= 1) || (actual_width > MaxPicWidth))
    {
      // Needs to be scaled - retaining original aspect ratio!
      var tmp_double = 1.0 * actual_width / MaxPicWidth;
      var w = MaxPicWidth;
      var h = Math.floor(1.0 * actual_height / tmp_double);
    }
    else
    {
      var w = actual_width;
      var h = actual_height;
    };
    
    CurrentThumbIDX = 0;
    
    var alt_string = '';
    var style_string = '';
    var onclick_string = '';
    var href_string1 = '';
    var href_string2 = '';
    if (actual_width > MaxPicWidth)
    {
      //alt_string = ' alt="Click to view full-size." ';
      style_string = ' style="cursor:hand;" ';
      onclick_string = ' onclick="EnlargeCurrentImg()" ';
      href_string1 = '<a href="javascript:EnlargeCurrentImg()">';
      href_string2 = '<\/a>';
    }
    else
    {
      style_string = ' style="cursor:default; filter:progid:DXImageTransform.Microsoft.Slide(duration=1, bands=\'1\', slideStyle=\'PUSH\');" ';
    };
    
    
    
    if (!IsIE)
    {
      alt_string = ThumbsArray[CurrentThumbIDX].caption;
    };
    
    //ThumsContent += '<input type="image" name="main_img" id="main_img" border="0" src="'
    //  + ThumbsArray[CurrentThumbIDX].img_url + '" '
    //  + 'width="' + w + '" '
    //  + 'height="' + h + '" '
    //  + style_string + alt_string + 'onclick="EnlargeCurrentImg()">';
    
    ThumsContent += '<table cellspacing="0" cellpadding="0" border="0">';
    if (ThumbsCount > 1)
    {
      ThumsContent += '  <tr>';
      ThumsContent += '    <td align="left" valign="center">';
      ThumsContent += '      <a href="javascript:DoThumbClick(CurrentThumbIDX-1)"><img src="_images\/Thumbs_back_button.gif" width="38" height="16" border="0" alt="Rotate Backward"><\/a>';
      ThumsContent += '    <\/td>';
            
      ThumsContent += '    <td align="right" valign="center">';
      ThumsContent += '      <a href="javascript:DoThumbClick(CurrentThumbIDX+1)"><img src="_images\/Thumbs_forward_button.gif" width="38" height="16" border="0" alt="Rotate Forward"><\/a>';
      ThumsContent += '    <\/td>';
      ThumsContent += '  <\/tr>';
    };
    ThumsContent += '  <tr>';
    ThumsContent += '    <td colspan="2">';
    
    ThumsContent += href_string1
      + '<img src="' + ThumbsArray[CurrentThumbIDX].img_url + '" '
      + 'name="main_img" id="main_img" border="0" '
      + 'width="' + w + '" '
      + 'height="' + h + '" '
      + style_string + alt_string 
      + href_string2;
    
    ThumsContent += '    <\/td>';
    ThumsContent += '  <\/tr>';
    
    if (ThumbsCount > 1)
    {
      ThumsContent += '  <tr>';
      ThumsContent += '    <td align="left" valign="center">';
      ThumsContent += '      <a href="javascript:DoThumbClick(CurrentThumbIDX-1)"><img src="_images\/Thumbs_back_button.gif" width="38" height="16" border="0" alt="Rotate Backward"><\/a>';
      ThumsContent += '    <\/td>';
            
      ThumsContent += '    <td align="right" valign="center">';
      ThumsContent += '      <a href="javascript:DoThumbClick(CurrentThumbIDX+1)"><img src="_images\/Thumbs_forward_button.gif" width="38" height="16" border="0" alt="Rotate Forward"><\/a>';
      ThumsContent += '    <\/td>';
      ThumsContent += '  <\/tr>';
    };
    
    ThumsContent += '<\/table>';
  };
  
  if (IsIE)
  {
    ThumsContent += '  <tr>';
    ThumsContent += '    <td colspan="2">';
    ThumsContent += '      <div name="img_caption_div" id="img_caption_div" class="imgcaption_div">';
    if (ThumbsArray[CurrentThumbIDX].caption == '')
    {
      ThumsContent += '        &nbsp;';
    }
    else
    {
      ThumsContent += ThumbsArray[CurrentThumbIDX].caption;
    };
    ThumsContent += '      <\/div>';
    ThumsContent += '    <\/td>';
    ThumsContent += '  <\/tr>';
  };
  
  ThumsContent += '<\/center>';
  ThumsContent += '<p>';
  
  document.writeln(ThumsContent); // commit
};
function InitThumbs()
{

};
function DoThumbClick(idx)
{
  if (CurrentThumbIDX != idx)
  {
  	if (IsIE)
    {
      img_caption_div.innerHTML = '&nbsp;';
    };
  	
  	if (idx < 0)
  	{
  	  idx = ThumbsCount-1;
    }
    else
    {
      if (idx >= ThumbsCount)
      {
        idx = 0;
      };
    };
    if (document.images)
    {
      var thumb_obj = document.images['thumb_' + CurrentThumbIDX];
    }
    else
    {
      var thumb_obj = eval('thumb_' + CurrentThumbIDX);
    };  
    thumb_obj.style.borderWidth = '0px';
    //thumb_obj.border = 0;
    
    
    if (document.images)
    {
      thumb_obj = document.images['thumb_' + idx];
    }
    else
    {
      thumb_obj = eval('thumb_' + idx);
    };  
    
    thumb_obj.style.borderWidth = '1px';
    //thumb_obj.border = 1;
  }
  else
  {
    
  };
  CurrentThumbIDX = idx;
  
  var actual_width = ThumbsArray[idx].img_w;
  var actual_height = ThumbsArray[idx].img_h;
  if ((actual_width <= 1) || (actual_height <= 1) || (actual_width > MaxPicWidth))
  {
    // Needs to be scaled - retaining original aspect ratio!
    var tmp_double = 1.0 * actual_width / MaxPicWidth;
    var w = MaxPicWidth;
    var h = Math.floor(1.0 * actual_height / tmp_double);
  }
  else
  {
    var w = actual_width;
    var h = actual_height;
  };
  
  if (document.images)
  {
    var img_obj = document.images['main_img'];
  }
  else
  {
    var img_obj = eval('main_img'); 
  };
  
  //if (IsIE)
  //{
  //  img_obj.filters[0].Apply();
  //};
  
  img_obj.width = w;
  img_obj.height = h;
  img_obj.src = ThumbsArray[idx].img_url;
  
  //if (IsIE)
  //{
  //  img_obj.filters[0].Play();
  //};
  
  if (!IsIE)
  {
    img_obj.alt = ThumbsArray[CurrentThumbIDX].caption;
  }
  else
  {
  	img_obj.alt = '';
  };
  
  if (IsIE)
  {
  	if (ThumbsArray[idx].caption != '')
  	{
  	  img_caption_div.innerHTML = ThumbsArray[idx].caption;
  	}
  	else
  	{
  	  img_caption_div.innerHTML = '&nbsp;';
  	};
  };
};
function NewThumb(thumb_url, thumb_w, thumb_h, img_url, img_w, img_h, caption)
{
  this.thumb_url = thumb_url;
  this.thumb_w = thumb_w;
  this.thumb_h = thumb_h;
  this.img_url = img_url;
  this.img_w = img_w;
  this.img_h = img_h;
  this.caption = caption;
};