$(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 (ie6) {
    $('select').css({visibility: 'hidden'});
    $("body, html").css({height: "100%", width: "100%", overflow: "hidden"});
  };
  $('#myFotoGround').addClass('superModalGround').css({display: 'block'});
  $('#myFotoOverlay').addClass('superModalOverlay').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>'
  );
  var border=0;
  if (ie6) {
    border=parseInt($('#myFotoOverlay').css('border-width'));
    var top=$('body').scrollTop();
    var w=$('body').width();
    $('#myFotoGround').css({top: top+'px', width: w+'px'});
    $('#myFotoOverlay').css({
      marginTop: -parseInt(height/2, 10)+top+'px',
      width: (x+border*2)+'px',
      height: (y+border*2)+'px'
    });
  };
  $(document).keydown(function(e){
    if (e.keyCode==27) { myFotoClose(); };
  });
  return false;
};



function myFotoClose () {
  $(document).unbind('keydown');
  $('#myFotoOverlay').removeClass('superModalOverlay').hide().html();
  $('#myFotoGround').removeClass('superModalGround').hide().html('');
  $('#myMedia, div.myMedia').css({visibility: 'visible'});
  if (ie6) {
    $('select').css({visibility: 'visible'});
    $("body,html").css({height: "auto", width: "auto", overflow: ""});
  };
};


