var dropinwindow;
var dropinwindow_contents;

var contents_width = 460;

/**
 * ドロップインウィンドウ初期設定
 */
function init_dropinwindow() {
	/*
	 * ドロップインウィンドウ生成
	 */
	dropinwindow = document.createElement("div");
	dropinwindow.setAttribute("id", "dropinwindow");

	/*dropinwindow.style.backgroundImage = 'url(../image/black-70.png)';
    dropinwindow.style.backgroundRepeat = 'repeat';*/
    dropinwindow.style.filter = 'alpha(opacity=70)';

	/*
	 * コンテンツ表示部分取得
	 */
	dropinwindow_contents = document.getElementById("dropinwindow-contents");

	var body = document.getElementsByTagName('body')[0];
	body.appendChild(dropinwindow);
	body.appendChild(dropinwindow_contents);
}

function open_dropinwindow() {
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		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 (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;
	} else if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}

	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	dropinwindow.style.height = pageHeight+"px";
	dropinwindow.style.width = pageWidth+"px";

	if (pageWidth < contents_width) {
		dropinwindow_contents.style.left = 0;
		dropinwindow_contents.style.width = dropinwindow.style.width;
	} else {
		var left = (pageWidth - contents_width) / 2;
		dropinwindow_contents.style.left = left+"px";
		dropinwindow_contents.style.width = contents_width+"px";
	}
	
	// スクロール量を取得
	var scroll_x = document.documentElement.scrollLeft || document.body.scrollLeft;
	var scroll_y = document.documentElement.scrollTop  || document.body.scrollTop;
	
	// 表示位置 Y を設定
	dropinwindow_contents.style.top = parseInt( scroll_y + 50 ) + "px";
	
	dropinwindow.style.display = dropinwindow_contents.style.display = "block";
}

function close_dropinwindow() {
	document.getElementById("dropinwindow").style.display = document.getElementById("dropinwindow-contents").style.display = "none";
}
