﻿PopupWindow = function(wid,sid)
{
	var instance = this;
	
	this.shadowElement = document.getElementById(sid);
	this.windowElement = document.getElementById(wid);
	
	instance.init();
	instance.position();
}

PopupWindow.prototype.init = function()
{
	var instance = this;
	
	if (window.addEventListener)
	{
		window.addEventListener("resize", function(){instance.position()}, false);
		window.addEventListener("scroll", function(){instance.position()}, false);
	}
	else if (window.attachEvent)
	{
		window.attachEvent("onresize", function(){instance.position()});
		window.attachEvent("onscroll", function(){instance.position()});
	}
}

PopupWindow.prototype.position = function()
{
	var h = 0;
	var y = 0;

	if (document.all)
	{
		h = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
		y = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
	}
	else
	{
		h = window.innerHeight;
		y = window.pageYOffset;
	}

	if (this.shadowElement)
	{
		this.shadowElement.style.height = document.body.offsetHeight + "px";
	}
	
	if (this.windowElement)
	{
		this.windowElement.style.top = Math.max((h - this.windowElement.offsetHeight) / 2 + y, y) + "px";
	}
}

