$(document).ready(function(){
 $('a.poplight[href^=#]').click(function() {
 var popID = $(this).attr('rel'); //Get Popup Name
 var popURL = $(this).attr('href'); //Get Popup href to define size
 var query= popURL.split('?');
 var dim= query[1].split('&');
 var popWidth = dim[0].split('=')[1]; //Gets the first query string value
 $('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="http://romale80.ucoz.ru/close_pop.png" class="btn_close" title="Закрыть окно" alt="Закрыть" border="0"/></a>');
 var popMargTop = ($('#' + popID).height() + 370) / 2;
 var popMargLeft = ($('#' + popID).width() + 50) / 2;
 $('#' + popID).css({
 'margin-top' : -popMargTop,
 'margin-left' : -popMargLeft
 });
 $('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
 $('#fade').css({'filter' : 'alpha(opacity=0)'}).fadeIn(); //Fade in the fade layer
 return false;
 });
 $('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
 $('#fade , .popup_block').fadeOut(function() {
 $('#fade, a.close').remove();
 }); //fade them both out
 return false;
 });
});

