
	var finalWindowWidthPercent  = 90;
	var finalWindowHeightPercent = 90;
	var unwrapTimeStep = 10;

	//--------------------------------------------------------------------
	var windowObject = null;
	var windowConent = "";


	var deltaHeightPercent = finalWindowHeightPercent/unwrapTimeStep;
	var thisWindowHeightPercent = 1;

	var deltaWidthPercent = finalWindowWidthPercent/unwrapTimeStep;
	var thisWindowWidthPercent = 5;			

	var widthUnwrappingTimer;
	
	var appearanceHTMLCode = 
		'<div class="fader" id="fader" onmouseDown="closePopupWindow()"></div>'+
		'<div class="splash" id="splash" onmouseDown="closePopupWindow()">'+
			'<nobr><img src="/ajaxWindows/loading.gif">&nbsp;&nbsp;Загрузка...</nobr>'+
		'</div>'+
		'<div class="pWindow" id="pWindow" >'+
			'<div class="header">'+
				'&nbsp;'+
				'<a href="#" onmouseDown="closePopupWindow()">'+
					'<img src="/ajaxWindows/close.png" >'+
				'</a>'+
			'</div>'+
			'<div class="windowContent" id="windowContent"></div>'+
		'</div>';

	function getXmlHttp()
	{
		var xmlhttp;
		try 
		{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e) 
		{
			try 
			{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (E) 
			{
				xmlhttp = false;
			}
		}
			if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
				xmlhttp = new XMLHttpRequest();
		
		return xmlhttp;
	}

	function affectVisibility(window, value)
	{
		document.getElementById(window).style.display = value;
	}

	function heightUnwrapStep()
	{
		thisWindowHeightPercent += deltaHeightPercent;
		document.getElementById("pWindow").style.height = thisWindowHeightPercent+"%";
		document.getElementById("pWindow").style.top = ((100 - thisWindowHeightPercent)/2)+"%";
		
		if (!(thisWindowHeightPercent >= finalWindowHeightPercent))
		{
			setTimeout("heightUnwrapStep()", unwrapTimeStep);
		}
		else
		{
			widthUnwrapStep();
		}
	}

	function widthUnwrapStep()
	{
		thisWindowWidthPercent += deltaWidthPercent;
		document.getElementById("pWindow").style.width = thisWindowWidthPercent +"%";
		document.getElementById("pWindow").style.left = ((100 - thisWindowWidthPercent )/2)+"%";
		
		if (!(thisWindowWidthPercent  >= finalWindowWidthPercent))
		{
			setTimeout("widthUnwrapStep()", unwrapTimeStep);
		}
		else
		{
			document.getElementById("windowContent").innerHTML = windowConent;
		}
	}			

	function popup( reference )
	{
		document.getElementById("windowContent").innerHTML = "";
		affectVisibility("fader","block");
		affectVisibility("splash", "block");
		
		
		thisWindowHeightPercent =1;
		document.getElementById("pWindow").style.height = "1%";
		document.getElementById("pWindow").style.top = "50%";
					
		thisWindowWidthPercent =5;
		document.getElementById("pWindow").style.width="5%";
		document.getElementById("pWindow").style.left="45%";
		
		loadContent(reference);
		
		return false;

	}

	function loadContent(reference)
	{
		var xmlhttp = getXmlHttp();

		
		
		xmlhttp.open('GET', "/ajaxServerPart.php?page="+reference.href, true);
		
		xmlhttp.onreadystatechange = function() 
		{
			if (xmlhttp.readyState == 4)
			{
				if(xmlhttp.status == 200)
				{
					affectVisibility("splash", "none");
					
					windowConent = xmlhttp.responseText;
					affectVisibility("pWindow","block");
					heightUnwrapStep();
				}
				else
				{
					closePopupWindow();
				}
			}
		};
		xmlhttp.send(null);
		return false;
	}


	function closePopupWindow()
	{
		affectVisibility("fader", "none");
		affectVisibility("pWindow","none");	
		affectVisibility("splash","none");					
	}

	
	document.write( appearanceHTMLCode );

