
function show_picture(img)
{
 var src = img.getAttribute('src');
 if(!src)
 {
  src = img.getAttribute('href');
 }
 var div = document.createElement('div');
 div.setAttribute('id','show_picture_div'); 
 div.setAttribute('onclick','document.body.removeChild(this)'); 
 var tpdiv = document.createElement('div');
 tpdiv.setAttribute('id','show_picture_tp'); 
 div.appendChild(tpdiv);
 var sp = document.createElement('img');
 timg = new Image();
 timg.src = src;
 sp.setAttribute('src',src);
 sp.setAttribute('id','show_picture');
 sp.setAttribute('alt','');
 div.appendChild(sp);
 var btns = document.createElement('div');
 btns.setAttribute('id','show_picture_buttons'); 
 btns.innerHTML = "X";
 div.appendChild(btns);
 document.body.appendChild(div);
 var dh = div.offsetHeight;
 var dw = div.offsetWidth;
 timg.onload = function ()
 {
  var ih = timg.height;
  var iw = timg.width;
  if(ih>dh)
  {
   var m = (dh-30)/ih;
   ih = dh-30;
   iw *= m;
  }
  if(iw>dw)
  {
   var m = (dw-30)/iw;
   ih *= m;
   iw = dw-30;
  }
  sp.style.height = Math.ceil(ih)+'px';
  sp.style.width = Math.ceil(iw)+'px';
  sp.style.top = Math.ceil((dh-ih)/2-5)+'px';
  sp.style.left = Math.ceil((dw-iw)/2-5)+'px';
  btns.style.top = Math.ceil((dh-ih)/2-5)+'px';
  btns.style.right = Math.ceil((dw-iw)/2-5)+'px';
 }
}

