$(document).ready(function(){   
  $('body').append(
    '<div id="myFotoGround" style="display:none; "></div>'+
    '<div id="myFotoOverlay" style="display:none;width:100px;height:100px"></div>'
  );
});


function myFotoShow (url,width,height) {
  var x=width;
  var y=height;
//  $('#myMedia, div.myMedia').css({visibility: 'hidden'});
  if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
    $("body, html").css({height: "100%", width: "100%", overflow: "hidden"});
  };
  $('#myFotoGround').addClass('fotoGround').css({display: 'block'});
  $('#myFotoOverlay').addClass('fotoOverlay').css({
    display: 'block',
    width: x+'px',
    height: y+'px',
    marginTop: -parseInt(height/2, 10) +'px',
    marginLeft: -parseInt(width/2, 10) +'px'
  }).html(
    '<a href="javascript:" title="закрыть иллюстрацию" onclick="return myFotoClose()">'+
    '<img src="'+url+'" width="'+width+'" height="'+height+'" border="0">'+
    '</a>'
  );
  $(document).keydown(function(e){
    if (e.keyCode==27) { myFotoClose(); };
  });
  return false;
};



function myFotoClose () {
  $(document).unbind('keydown');
  $('#myFotoOverlay').removeClass('fotoOverlay').hide();
  $('#myFotoGround').removeClass('fotoGround').hide().html('');
//  $('#myMedia, div.myMedia').css({visibility: 'visible'});
  if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
    $("body,html").css({height: "auto", width: "auto", overflow: ""});
  };
};

