$(document).ready(function() {
  var vdiv, hdiv, posiz;
  
  function reSize(vh, e) {
    var par = 0;
    var dx = 0;
    dx = (e.attr('class') != 'brd6') ? 11 : 17;
    switch(vh) {
      case 'w':
        par = e.width() + dx;
        break
      case 'h':
        par = e.height() + dx;
        break
      default:
        par = 0;
    }
    return par;
  }
  
  $('.brd3,.brd6').each(function() {
    switch($(this).attr('align')) {
      case 'left':
        posiz = 'imgl-shadow';
        $(this).removeAttr('align');
        break
      case 'right':
        posiz = 'imgr-shadow';
        $(this).attr('align');
        break
      default:
        posiz = 'img-shadow';
    }
    if($(this).parent().get(0).tagName == 'A') {
      vdiv = 6 + reSize('w', $(this));
      hdiv = reSize('h', $(this));
      $(this).parent().wrap('<div class="' + posiz + '" style="width:' + vdiv + 'px; height:' + hdiv + 'px;"></div>');
    } else {
      vdiv = 6 + reSize('w', $(this));
      hdiv = reSize('h', $(this));
      $(this).wrap('<div class="' + posiz + '" style="width:' + vdiv + 'px; height:' + hdiv + 'px;"></div>');
    }
  });
});
