/* 　　○ウィンドウ表示＆移動イベント○　　 */

var caption;
var explain;
var Drag = null;
var offsetX = 0;
var offsetY = 0;
document.onmousemove = windowmove;


// ---- 表示ウィンドウ作成 ---- //
function makewindow () {

	document.write("<div id=\"disp\">");
	document.write("<div id=\"header\"></div>");
	document.write("<div id=\"content\"></div>");
	document.write("</div>");

}


// ---- ウィンドウ表示 ---- //
function dispwindow (head, content, e, width) {

	var obj_d = document.getElementById('disp');
	var obj_h = document.getElementById('header');
	var obj_c = document.getElementById('content');

	// 現在地取得して代入
	var xcord = get_x_point(e) + 10;
	var ycord = get_y_point(e) + 5;
	obj_d.style.left = xcord + "px";
	obj_d.style.top = ycord + "px";

	// ウィンドウの大きさを取得して、右にはみ出るようなら補正
	var windowsize;
	if (document.all) { windowsize = document.body.clientWidth; }
	else { windowsize = window.innerWidth; }
	if (xcord + 200 > windowsize) {
		windowsize -= 200;
		obj_d.style.left = windowsize + "px";
	}

	obj_h.innerHTML = head;
	obj_c.innerHTML = content;
	obj_d.style.display = "block";
	if (width != "") { obj_d.style.width = width + "px"; }

	// ドラッグイベント開始用
	Drag = document.getElementById('disp');
	offsetX = get_x_point(e) - Drag.offsetLeft;
	offsetY = get_y_point(e) - Drag.offsetTop;

	this.onmouseover = null;
}


// ---- ウィンドウ消去 ----  //
function offwindow () {
	Drag = null;
	offsetX = 0;
	offsetY = 0;
	document.getElementById('disp').style.display = "none";
	document.getElementById('disp').style.width = "200px";
	this.onmouseover = "dispwindow('caption','explain')";
}


// ---- ウィンドウ移動 ---- //
function windowmove() {
	if (!Drag) { return true; }
	e = event;

	Drag.style.left = get_x_point(e) - offsetX;
	Drag.style.top = get_y_point(e) - offsetY;

	return false;
}




/* 　　○Utilities○　　 */

// ---- 現在位置取得（X座標） ---- //
function get_x_point(e) {
	// pageXはIE。clientXは現在地(X軸)をあらわしscrollLeftは横のスクロール数を示す
	return e.pageX || (e.clientX + document.body.scrollLeft);
}



// ---- 現在位置取得（Y座標） ---- //
function get_y_point(e) {
	// pageYはIE。clientYは現在地(Y軸)をあらわしscrollTopは縦のスクロール数を示す
	return e.pageY || (e.clientY + document.body.scrollTop);
}
