			var my_page_size, my_page_scroll, popup_size, open_url, new_height;
		$(function(){
		//ищем ссылки на popup окна
		$('a.popup').click(function (e) {
			e.stopPropagation();
			my_page_size = my_getPageSize();
			my_page_scroll = my_getPageScroll();
			popup_size = $(this).attr('rel').split('x');
			open_url = $(this).attr('href');
			popup_size[0] = parseInt(popup_size[0]);
			popup_size[1] = parseInt(popup_size[1]);
			if(popup_size[0]<1) popup_size[0] = 500;
			if(popup_size[1]<1) popup_size[1] = 400;
			
			$('embed, object, select').css( {
				'visibility' :'hidden'
			});
			
			$('body')
					.append(
							'<div class="black_display" id="black_display"></div><div class="box_popup" id="box_popup"><div id="box_popup_inner"><div id="box_loading"><img src="'+images_folder+'lightbox-ico-loading.gif" /></div></div><a id="CloseLinkPopup" href="#"/></div>');
			$('#black_display').css( {
				display :'block',
				opacity :0.7,
				width :my_page_size[0],
				height :my_page_size[1]
			}).fadeIn();
			
			$('#box_loading').css( {
				width: popup_size[0],
				top: popup_size[1]/2-16
			});
			$('#box_popup_inner').css( {
				opacity: 0
			});
			$('#CloseLinkPopup').css( {
				display: 'none'
			});
			
			$('#box_popup').css( {
				display :'block',
				opacity :0,
				width : 10,
				height :10,
				top: e.pageY,
				left: e.pageX 
			}).animate({
				opacity: 1,
				width : popup_size[0],
				height :popup_size[1],
				top: (my_page_scroll[1]+my_page_size[3]/2-popup_size[1]/2),
				left: (my_page_scroll[0]+my_page_size[2]/2-popup_size[0]/2)
			  }, 500, function() {
				  	if(open_url!='') {
						$('#box_popup_inner').load(open_url, {is_ajax: 1}, function() {afterLoad();});
					}
					$('#CloseLinkPopup').css( {
						display: 'block'
					});
					$('#box_popup_inner').css({
							opacity: 1
					}).fadeIn();
			  });
			
			$('#black_display,#CloseLinkPopup').click( function() {
				$('#box_popup').remove();
				$('#black_display').fadeOut( function() {
					$('#black_display').remove();
				});
				$('embed, object, select').css( {
					'visibility' :'visible'
				});
			});
			
			
			return false;
		});
		
		function afterLoad () {		
				$('#box_popup_inner').find('form').submit(function(e) {
					e.stopPropagation();
					var url;
					if($(this).attr('action')!='') url = $(this).attr('action');
					else url = open_url;
					$('#box_popup_inner').html('<div id="box_loading"><img src="'+images_folder+'lightbox-ico-loading.gif" /></div>');
					$.post(url, $(this).serialize()+'&is_ajax=1',function(data) {
										  $('#box_popup_inner').html(data);
										  afterLoad();
										});
					return false;
				});
		}
		
		function my_getPageSize() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight) {
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else {
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {
				if (document.documentElement.clientWidth) {
					windowWidth = document.documentElement.clientWidth;
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement
					&& document.documentElement.clientHeight) {
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) {
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}
			if (yScroll < windowHeight) {
				pageHeight = windowHeight;
			} else {
				pageHeight = yScroll;
			}
			if (xScroll < windowWidth) {
				pageWidth = xScroll;
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth, pageHeight, windowWidth,	windowHeight);
			return arrayPageSize;
		}
 
		function my_getPageScroll() {
			var xScroll, yScroll;
			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
				xScroll = self.pageXOffset;
			} else if (document.documentElement
					&& document.documentElement.scrollTop) {
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;
			}
			arrayPageScroll = new Array(xScroll, yScroll);
			return arrayPageScroll;
		}

});