//‰ü‘¢•s—v
// ---------------------------------------------------------------------------
// Fixed Layer Emurator for DHTML 1.00
// Copyright 2002 CHIKA Mizuki, Arcadia Software C.M. Applications
// mailto: elysium@nx.sakura.ne.jp
// WP URIs: http://www.nx.sakura.ne.jp/~elysium/software/
// ---------------------------------------------------------------------------

// Variable
var fixedIDs = new Array();
var fixedXOffsets = new Array();
var fixedYOffsets = new Array();
var fixedTimerPrecision = 10;
var fixedTimerID;

// Addition layer ID that fixed position
function addFixedLayer(id, xOffset, yOffset)
{
	var ns6 = document.getElementById ? 1 : 0;
	var nc = document.layers ? 1 : 0;
	var ie = document.all ? 1 : 0;
	var count = fixedIDs.length;
	var obj = null;
	if (ie) {
		// Internet Explorer
		obj = document.all[id];
		if (obj != null) {
			obj.style.pixelTop = document.body.scrollTop + yOffset;
			obj.style.pixelLeft = document.body.scrollLeft + xOffset;
		} else {
			return false;
		}
	} else if (nc) {
		// Netscape Communicator
		obj = document.layers[id];
		if (obj != null) {
			obj.top = pageYOffset + yOffset;
			obj.left = pageXOffset + xOffset;
		} else {
			return false;
		}
	} else if (ns6) {
		// Netscape6 or Netscape7, Mozilla, Opera
		obj = document.getElementById(id);
		if (obj != null) {
			obj.style.top = pageYOffset + yOffset;
			obj.style.left = pageXOffset + xOffset;
		} else {
			return false;
		}
	} else {
		return false;
	}
	fixedIDs[count] = id;
	fixedXOffsets[count] = xOffset;
	fixedYOffsets[count] = yOffset;
	return true;
}

// Main handling of fixed position.
function onFixedLayer()
{
	var ns6 = document.getElementById ? 1 : 0;
	var nc = document.layers ? 1 : 0;
	var ie = document.all ? 1 : 0;
	var count = fixedIDs.length;
	var nx;
	var yOffset;
	var xOffset;
	var obj;
	for (nx=0; nx < count; nx++) {
		obj = null;
		if (ie) {
			// Internet Explorer
			obj = document.all[fixedIDs[nx]];
			if (obj != null) {
				yOffset = document.body.scrollTop + fixedYOffsets[nx];
				xOffset = document.body.scrollLeft + fixedXOffsets[nx];
				if ((obj.style.pixelTop != yOffset)||(obj.style.pixelLeft != xOffset)) {
					obj.style.pixelTop = yOffset;
					obj.style.pixelLeft = xOffset;
				}
			}
		} else if (nc) {
			// Netscape Communicator
			obj = document.layers[fixedIDs[nx]];
			if (obj != null) {
				yOffset = pageYOffset + fixedYOffsets[nx];
				xOffset = pageXOffset + fixedXOffsets[nx];
				if ((obj.top != yOffset)||(obj.left != xOffset)) {
					obj.top = yOffset;
					obj.left = xOffset;
				}
			}
		} else if (ns6) {
			// Netscape6 or Netscape7, Mozilla, Opera
			obj = document.getElementById(fixedIDs[nx]);
			if (obj != null) {
				yOffset = pageYOffset + fixedYOffsets[nx];
				xOffset = pageXOffset + fixedXOffsets[nx];
				if ((obj.style.top.toString().replace(/^(\d+)(px)?$/,"$1") != yOffset)||
					(obj.style.left.toString().replace(/^(\d+)(px)?$/,"$1") != xOffset)) {
					obj.style.top = yOffset;
					obj.style.left = xOffset;
				}
			}
		}
	}
	if (! ie) {
		fixedTimerID = setTimeout("onFixedLayer()", fixedTimerPrecision);
	}
}

// Start fixed position
function startFixedLayer()
{
	var ns6 = document.getElementById ? 1 : 0;
	var nc = document.layers ? 1 : 0;
	var ie = document.all ? 1 : 0;
	if (ie) {
		window.onscroll = onFixedLayer;
	} else if (nc || ns6) {
		fixedTimerID = setTimeout("onFixedLayer()", fixedTimerPrecision);
	}
}

// End fixed position
function endFixedLayer()
{
	var ns6 = document.getElementById ? 1 : 0;
	var nc = document.layers ? 1 : 0;
	var ie = document.all ? 1 : 0;
	if (ie) {
		window.onscroll = null;
	} else if (nc || ns6) {
		clearTimeout(fixedTimerID);
	}
}

// Set layer visibility
function setLayerVisibled(id, flag)
{
	var ns6 = document.getElementById ? 1 : 0;
	var nc = document.layers ? 1 : 0;
	var ie = document.all ? 1 : 0;
	var obj;
	obj = null;
	if (ie) {
		// Internet Explorer
		obj = document.all[id];
		if (obj != null) {
			obj.style.visibility = flag ? "visible" : "hidden";
			return true;
		}
	} else if (nc) {
		// Netscape Communicator
		obj = document.layers[id];
		if (obj != null) {
			obj.visibility = flag ? "show" : "hide";
			return true;
		}
	} else if (ns6) {
		// Netscape6 or Netscape7, Mozilla, Opera
		obj = document.getElementById(id);
		if (obj != null) {
			obj.style.visibility = flag ? "visible" : "hidden";
			return true;
		}
	}
	return false;
}

