//
// PukiWiki - Yet another WikiWikiWeb clone.
// $Id: glossary.js,v 1.1 2005/05/26 02:43:27 miko Exp $
// Copyright (C)
//   2005      PukiWiki Plus! Team
//
// Glossary Popup function
// Usage: onmouseover="showGlossaryPopup(url,event)" onmouseout="hideGlossaryPopup()"

popupDiv = false;
tUrl = "";	// temporary URL
gUrl = "";	// global URL
egX = 0;
egY = 0;
ecX = 0;
ecY = 0;

// add
function showGlossarygetWindowSize()
{
	var window_width, window_height;
	if (self.innerHeight) {	
		window_width = self.innerWidth;
		window_height = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { 
		window_width = document.documentElement.clientWidth;
		window_height = document.documentElement.clientHeight;
	} else if (document.body) { 
		window_width = document.body.clientWidth;
		window_height = document.body.clientHeight;
	}	
	return [window_width, window_height];
}

///////////////////////////////////////
// Show Popup Glossary
function showGlossaryPopup(url,ev)
{
	// DOM Not Implemented
	if (!document.createElement) { return; }
	// Page Not Loaded
	if (!document.getElementById('popUpContainer')) {
		return;
	}
	
	if (!popupDiv || url != gUrl) {
		tUrl = url;
		if (document.all) {
			ecX = event.clientX;
			ecY = event.clientY;
		} else {
			// add
			if( ev.ctrlKey ){
				hideGlossaryPopup();
				return;	// Cool Previews の設定対応
			}
			if( ev.shiftKey ){
//				return GB_show('GB_show', url, 800, 1280, ev );	// GB_show 対応
			}
			if( ev.altKey ){
//				return;	// ポップアップを継続
			}
//			var array_page_size = showGlossarygetWindowSize();
//			// 小さいときは下に標示
//			if( ( array_page_size[1] + ev.pageY ) <  ( parent.innerHeight + parent.pageYOffset ) ){
				egX = 0;	// ev.pageX;
				egY = ev.pageY;
//			}
//			// 大きい時は右に標示
//			else{
//				egX = Math.round( parent.innerWidth / 2 ) - 60;	// 860; // ev.pageX;
//				egY = parent.pageYOffset; // 0;	ev.pageY;
//			}
		}
		popup_onload = function(htmldoc) {
			if( ! ev.shiftKey ){
				hideGlossaryPopup();
			}
			gUrl = tUrl;
			var x_adjust = 30;
			var y_adjust = 30;
			if (!popupDiv) {
				popupDiv = document.createElement('div');
				popupDiv.setAttribute('id', 'ajaxpopup');
				if (document.all) {
					var body = (document.compatMode=='CSS1Compat') ? document.documentElement : document.body;
					popupDiv.style.pixelLeft = body.scrollLeft + ecX + x_adjust;
					popupDiv.style.pixelTop = body.scrollTop + ecY + y_adjust;
				} else if (document.getElementById) {
					popupDiv.style.left = egX + x_adjust + "px";
					popupDiv.style.top = egY + y_adjust + "px";
				}
				popupDiv.innerHTML = htmldoc.responseText;
				var popUpContainer = document.getElementById("popUpContainer");
				if (popUpContainer) {
					popUpContainer.appendChild(popupDiv);
				} else {
					document.body.appendChild(popupDiv);
				}
			}
		}
		var html = new TextLoader(popup_onload,null);
		html.load(url,null);
	}
}

///////////////////////////////////////
// Hide Popup Glossary
function hideGlossaryPopup(ev)
{
//	if( event.altKey ){
//		return;	// ポップアップを継続
//	}
	// DOM Not Implemented
	if (!document.createElement) { return; }

	if (popupDiv) {
		popupDiv.style.visibility = "hidden";
		popupDiv.parentNode.removeChild(popupDiv);
		popupDiv = false;
	}
}

popupDiv2 = false;
tUrl2 = "";	// temporary URL
tUrl2 = "";	// global URL
egX2 = 0;
egY2 = 0;
ecX2 = 0;
ecY2 = 0;

///////////////////////////////////////
// Show Popup Glossary
function showGlossaryPopup_2(url,ev)
{
	// DOM Not Implemented
	if (!document.createElement) { return; }
	// Page Not Loaded
	if (!document.getElementById('popUpContainer')) {
		return;
	}
	
	if (!popupDiv2 || url != tUrl2) {
		tUrl2 = url;
		if (document.all) {
			ecX2 = event.clientX;
			ecY2 = event.clientY;
		} else {
			// add
			if( ev.ctrlKey ){
				hideGlossaryPopup_2();
				return;	// Cool Previews の設定対応
			}
			if( ev.shiftKey ){
//				return GB_show('GB_show', url, 800, 1280, ev );	// GB_show 対応
			}
			if( ev.altKey ){
//				return;	// ポップアップを継続
			}
//			var array_page_size = showGlossarygetWindowSize();
//			// 小さいときは下に標示
//			if( ( array_page_size[1] + ev.pageY ) <  ( parent.innerHeight + parent.pageYOffset ) ){
//				egX2 = ev.pageX;
//				egY2 = ev.pageY;
//			}
//			// 大きい時は右に標示
//			else{
				egX2 = Math.round( parent.innerWidth / 2 ) - 60;	// 860; // ev.pageX;
				egY2 = parent.pageYOffset; // 0;	ev.pageY;
//			}
		}
		popup_onload = function(htmldoc) {
			if( ! ev.shiftKey ){
				hideGlossaryPopup_2();
			}
			tUrl2 = tUrl2;
			var x_adjust = 0;	// 30;
			var y_adjust = 0;	// 30;
			if (!popupDiv2) {
				popupDiv2 = document.createElement('div');
				popupDiv2.setAttribute('id', 'ajaxpopup');
				if (document.all) {
					var body = (document.compatMode=='CSS1Compat') ? document.documentElement : document.body;
					popupDiv2.style.pixelLeft = body.scrollLeft + ecX2 + x_adjust;
					popupDiv2.style.pixelTop = body.scrollTop + ecY2 + y_adjust;
				} else if (document.getElementById) {
					popupDiv2.style.left = egX2 + x_adjust + "px";
					popupDiv2.style.top = egY2 + y_adjust + "px";
				}
				popupDiv2.innerHTML = htmldoc.responseText;
				var popUpContainer = document.getElementById("popUpContainer");
				if (popUpContainer) {
					popUpContainer.appendChild(popupDiv2);
				} else {
					document.body.appendChild(popupDiv2);
				}
			}
		}
		var html = new TextLoader(popup_onload,null);
		html.load(url,null);
	}
}

///////////////////////////////////////
// Hide Popup Glossary
function hideGlossaryPopup_2(ev)
{
//	if( event.altKey ){
//		return;	// ポップアップを継続
//	}
	// DOM Not Implemented
	if (!document.createElement) { return; }

	if (popupDiv2) {
		popupDiv2.style.visibility = "hidden";
		popupDiv2.parentNode.removeChild(popupDiv2);
		popupDiv2 = false;
	}
}


