function Mask() {
	var overlay;
	this.init();
}

Mask.prototype = {
	opacity : 20,
	
	init : function() {
		this.overlay = document.getElementById('overlay');
		if (!this.overlay) {
			overlayObj = document.createElement("div");
			overlayObj.setAttribute('id', 'overlay');
			overlayObj.style.position = 'absolute';
			overlayObj.style.top = '0';
			overlayObj.style.left = '0';
			document.body.appendChild(overlayObj);
			this.overlay = overlayObj;
		}
	},

	show : function() {
		pageSize = this.getPageSize();
		this.overlay.style.width = pageSize.width + 'px';
		this.overlay.style.height = pageSize.height + 'px';
		this.overlay.style.zIndex = '999';
		this.overlay.style.background = 'rgb(0, 0, 0)';
		this.overlay.style.opacity = this.opacity / 100;
		if (document.all) {
			this.overlay.style.filter = 'alpha(opacity=' + this.opacity + ')';
		}
		this.overlay.style.display = 'block';
	},

	hide : function() {
		this.overlay.style.zIndex = '-9999';
		this.overlay.style.display = 'none';
	},

	unload : function() {
		this.overlay.remove();
	},

	getPageSize : function() {
		xScroll = Math.max(
				document.documentElement.clientWidth,
				document.body.scrollWidth, document.documentElement.scrollWidth,
				document.body.offsetWidth, document.documentElement.offsetWidth
			);
		yScroll = Math.max(
				document.documentElement.clientHeight,
				document.body.scrollHeight, document.documentElement.scrollHeight,
				document.body.offsetHeight, document.documentElement.offsetHeight
			);
	
		pageSize = {
			"width" : xScroll,
			"height" : yScroll
		};
		return pageSize;
	}
}

function addOnloadFunc(func) {
	if (window.addEventListener) {
		window.addEventListener('load', func, false);
	} else if (window.attachEvent) {
		window.attachEvent('onload', func);
	}
}

function calculateLeftTopPosition(leftOffset, topOffset) {
	if (document.all) { // IE用
		width = document.body.clientWidth;
		height = document.body.clientHeight;
	} else {
		width = window.innerWidth;
		height = window.innerHeight;
	}
	if (width <= 0 || height <= 0) {
		return null;
	}
	
	position = {
		"left" : Math.max(0, width / 2 + leftOffset),
		"top" : Math.max(0, height / 2 + topOffset)
	}
	return position;
}

//Popup画面の表示位置を算出するファンクション
//calculateLeftTopPositionがドキュメント領域全体から算出するのに対し、
//calculateLeftTopPosition2は以下の方法から位置算出を行います。
// 横位置…document領域の中心点からの相対位置
// 縦位置…スクロール位置からの相対位置
function calculateLeftTopPosition2(leftOffset, topOffset) {
	// スクロール位置の算出
	var view_pos = new Object();
	view_pos.x = document.documentElement.scrollLeft || document.body.scrollLeft;
	view_pos.y = document.documentElement.scrollTop || document.body.scrollTop;

	// document領域の算出
	if (document.all) { // IE用
		width = document.body.clientWidth;
		height = document.body.clientHeight;
	} else {
		width = window.innerWidth;
		height = window.innerHeight;
	}
	if (width <= 0 || height <= 0) {
		return null;
	}
	
	position = {
		"left" : Math.max(0, width / 2 + leftOffset),
		"top" : view_pos.y + topOffset
	}
	return position;
}

