$(document).ready(function() {
  $('body.photo #photograph img').each(function(){
      $(this).load(function(){
        var p = $(this);
        var w = p.width();
        var h = p.height();

        var t = '';
        t += '<table border="0" cellspacing="0" cellpadding="0" width="' + (w + 20 * 2) + '">';
        t += '  <tr>';
        t += '    <td><img src="/themes/sistrall.it/images/frame_1.gif" width="20" height="23"/></td>';
        t += '    <td><img src="/themes/sistrall.it/images/frame_2.gif" width="' + w + '" height="23"/></td>';
        t += '    <td><img src="/themes/sistrall.it/images/frame_3.gif" width="20" height="23"/></td>';
        t += '  </tr>';
        t += '  <tr>';
        t += '    <td><img src="/themes/sistrall.it/images/frame_4.gif" width="20" height="' + h + '" /></td>';
        t += '    <td id="center">' + $(this).parent().parent().html() + '</td>';
        t += '    <td><img src="/themes/sistrall.it/images/frame_6.gif" width="20" height="' + h + '" /></td>';
        t += '  </tr>';
        t += '  <tr>';
        t += '    <td><img src="/themes/sistrall.it/images/frame_7.gif" width="20" height="25"/></td>';
        t += '    <td><img src="/themes/sistrall.it/images/frame_8.gif" width="' + w + '" height="23"/></td>';
        t += '    <td><img src="/themes/sistrall.it/images/frame_9.gif" width="20" height="25"/></td>';
        t += '  </tr>';
        t += '</table>';
      
        $(this).parent().replaceWith(t);

//      if($(this).next('.frame').length < 1) {
//        var p = $(this);
//        var h = '';
//        h += '<div class="frame">';
//        h += '<img src="/themes/sistrall.it/images/frame-photograph-top.gif"    width="' + (p.width() + 40) + '" height="13"/>';
//        h += '<img src="/themes/sistrall.it/images/frame-photograph-middle.gif" width="' + (p.width() + 40) + '" height="' + (p.height() + 10 * 2) + '"/>';
//        h += '<img src="/themes/sistrall.it/images/frame-photograph-bottom.gif" width="' + (p.width() + 40) + '" height="13"/>';
//        h += '</div>';
//        p.after(h);
//        
//        var f = $('body.photo #photograph');
//        var pb = Math.ceil(f.height() / 21) * 21 - f.height() + 1;
//        f.css('padding-bottom', pb);
//      }
    });
  });
  
  // Ah, the old fucking IE...
  // if($.browser.msie)  { $('body.photograph #photograph img').each(function() { $(this).trigger('load'); } ); }
  $('body.photo #photograph img').each(function(){ 
    $(this).trigger('load');
  });
});