var divPr;
var imgPr;
var divState;
function preview(address){
    wHeight = window.innerHeight;
    wWidth = window.innerWidth;
    if(imgPr){
	imgPr.attr("src",address);
    }else{//первая инициализация контейнера
	divState = 'Up';
	imgPr=$("<img id='imgPr' src='" + address + "'>");
	
    }
    if(!divPr){
	divPr = $("<div id='divPr'></div>");
	divPr.css({'text-align' : 'center', 'background-color' : 'black', 'width' : '100%', 'height' : '100%', 'position' : 'fixed', 'top' : '0px','left':'0px', 'opacity' : '0','vertical-align':'middle'});
	divPr.click(function(){
		imgPr.animate({
		'opacity': '0',
		'width':'0',
		'height':'0'
		},100); 
		divPr.animate({
		'opacity' : '0',
		'width'   : '0',
		'height'  : '0',
		'top' : '20px',
		'left': '30px'
		}, 500);
		});
		divPr.appendTo(document.body);
	}
    divPr.html('');
    divPr.append(imgPr);
    imgPr.css({'width':'auto','height':'auto'});
    jQuery.get(address, function(){
	if (wHeight > imgPr.height()){
    var img_top=Math.floor((((wHeight-imgPr.height())/2)/wHeight)*100);
    } else {
    //alert(img_top);
    var img_top = 0;
    }
    imgPr.css({'top' : img_top+"%",'position':'relative','margin':'0','opacity':'100'});
    });
    
    divPr.css({'width' : '100%', 'height' : '100%','top' : '0px','left':'0px'});
    divPr.animate({
    opacity : 0.9,
    }, 100);
//$("#imgshow").css({'color' : 'red', 'background-color' : 'black', 'position' : 'absolute', 'top' : '0px'});
     //mLeft = Math.floor($("#fullimg").width()/wWidth*50) + '%';
      //$("#fullimg").css({'margin-left' : mLeft});
     // $("#fullimg").hide();
    //$("#imgshow").fadeIn("slow");
    }