function CmsPopupWindow() {
	var isVisible = false;
	this.Init = function() {
		if(jQuery('#cmsPopupWindow').length==0) {
			jQuery('body').append('<div id="cmsPopupWindow" style="display: none;"></div>');
		}
	};
	
	this.OpenWindow = function(page_id) {
		jQuery(this).openOverlay({sColor:'#000',iOpacity:70});
		_cpw.isVisible = true;
		

		
		jQuery('#cmsPopupWindow').load('?m=pages&a=ajax&pid='+page_id, function() {
			_cpw.RePosition();
			jQuery('#cmsPopupWindow').show();
		});
		
		jQuery(window).scroll(_cpw.RePosition).resize(_cpw.RePosition);
	};
	
	this.CloseWindow = function() {
		_cpw.isVisible = false;
		jQuery('#cmsPopupWindow').hide();
		
		jQuery(this).openOverlay('close');
		
	};
	
	this.RePosition = function() {
		if(_cpw.isVisible) {
			var w = jQuery(window).width();
			var left = (w - jQuery('#cmsPopupWindow').width())/2;
			var h = jQuery(window).height();
			var top = (h - jQuery('#cmsPopupWindow').height())/2 + jQuery(window).scrollTop();
			jQuery('#cmsPopupWindow').attr('style', 'left:'+left+'px; top:'+top+'px;');
		}
	};
}

var _cpw = new CmsPopupWindow();

jQuery().ready(function() {
	_cpw.Init();
});
