var version=parseFloat(jQuery.browser.version);

$(document).ready(function() {

  imageOpener();
  
  var arr = $("#snippet img");
  for (i = 0; i < arr.length; i++)
  {
    resizeImage(arr[i], 355, 300);
  }
  
  var pictureTdImgs = $("#picture_td img");
  for (i = 0; i < pictureTdImgs.length; i++)
  {
    resizeImage(pictureTdImgs[i], 200, 1000);
  }

  var descriptionTdTables = $("#description_td table");
  for (i = 0; i < descriptionTdTables.length; i++)
  {
    resizeTable(descriptionTdTables[i], 240);
  }
  
  $("#text_left").pngFix();

});



function imageOpener()
{
        $('img.opener').mouseover(function(e){
          
          $(this).css('cursor', 'pointer');
        
        });
        
        $('img.opener').mouseout(function(e){
          
          $(this).css('cursor', 'auto');
        
        });


      $('img.opener').click(function(e){

        var src = '';
        
        if (jQuery.browser.msie && version < 7)
        {
          if ($(this).css('filter') == '')
          {
            src = this.src;
          }
          else
          {
            //var firstIndex =  "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='".length; 
            var firstIndex =  56;
            var secondIndex = jQuery(this).css('filter').indexOf("',sizingMethod");
            src = jQuery(this).css('filter').substring(firstIndex, secondIndex);
          }
        }
        else
        {
          src = this.src;
        }
        myWindowOpen(src);
        return false;
      
      
      });
      
}

function myWindowOpen(src)
{
      var width;
      var height;
      
      var imgOriginal = new Image();
      imgOriginal.src = src;
      
      width = imgOriginal.width + 40;
      height = imgOriginal.height + 40;
      
      if (width > screen.width - 150)
      {
        width = screen.width - 150;
      }
      if (height > screen.height -200)
      {
        height = screen.height - 200;
      }
      
      var prefs = 'resizable=yes, scrollbars=yes, top=100, left=100, width=' + width + ', height=' + height;
      
      var win = window.open(src, '', prefs);

      return false;
}

function resizeImage(image, width, height)
{
  var imgR = ($(image).height() / $(image).width());
  var containerWidth = width;
  var containerHeight =  height;
  
  if ($(image).width() > containerWidth)
  { 
    $(image).width(containerWidth);
    $(image).height(containerWidth * imgR)
  }

  if ($(image).height() > containerHeight)
  { 
    $(image).height(containerHeight);
    $(image).width(containerHeight / imgR)
  }
}

function resizeTable(table, width)
{
  var containerWidth = width;
  
  if ($(table).width() > containerWidth)
  { 
    $(table).width(containerWidth);
  }
}

