//------------------------------------------------------------------------------
//	Lay JavaScript File
//		レイヤースクリプト
//		v1.00	 by m	1999/12/28	新規
//------------------------------------------------------------------------------

//	！！！！！JavaScriptに詳しく無い方は、編集しないほうが賢明です！！！！！

//------------------------------------------------------------------------------
//	ローカル変数

var ie5 = (navigator.appVersion.indexOf('MSIE 5')>=0);
var nLay = 0;				// レイヤー数
var aLay = new Array();		// レイヤー配列

//------------------------------------------------------------------------------
//	オブジェクト定義

function Lay(nX,nY,nZ,nW,nH,sHtml)
{
	this.div = null;					// レイヤー
	this.divEv = null;					// イベント取得レイヤー
	this.sId = 'Lay' + nLay;			// レイヤーID
	this.nX = parseInt(nX);				// X座標
	this.nY = parseInt(nY);				// Y座標
	this.nZ = parseInt(nZ);				// Z座標
	this.nW = parseInt(nW);				// 幅
	this.nH = parseInt(nH);				// 高さ
	
	this.sHtml = sHtml;					// HTML
	this.bEnableDrag = false;			// ドラッグ動作許可
	this.bDrag = false;					// ドラッグフラグ
	this.offX = 0;						// ドラッグ開始時オフセットX
	this.offY = 0;						// ドラッグ開始時オフセットY
	
	this.Init = LayInit;				// 初期化
	this.IsVsbl = LayIsVsbl;			// 可視状態取得
	this.SetVsbl = LaySetVsbl;			// 可視状態設定
	this.WriteHtml = LayWriteHtml;		// HTML書き込み
	this.SetBgColor = LaySetBgColor;	// 背景色設定
	this.SetDrag = LaySetDrag;			// ドラッグ動作許可禁止処理
	this.MoveTo = LayMoveTo;			// 移動
	this.MDown = LayMDown;				// マウスダウン処理
	this.MMove = LayMMove;				// マウスムーブ処理
	this.MUp = LayMUp;					// マウスアップ処理
	
	aLay[nLay] = this;
	nLay++;
	this.Init();
}

//------------------------------------------------------------------------------
//	イニシャライズ

function LayInit()
{
	if(document.all){
		document.body.insertAdjacentHTML('BeforeEnd',
			'<div id="'+this.sId+
			'" style="position:absolute;left:'+this.nX+';top:'+this.nY+
			';width:'+this.nW+';height:'+this.nH+';z-index:'+this.nZ+';visibility:hidden;"></div>');
		document.body.insertAdjacentHTML('BeforeEnd',
			'<div id="'+this.sId+'Ev'+
			'" style="position:absolute;left:'+this.nX+';top:'+this.nY+
			';width:'+this.nW+';height:'+this.nH+';z-index:'+(this.nZ+1)+';visibility:hidden;"></div>');
		this.div = document.all(this.sId);
		this.divEv = document.all(this.sId+'Ev');
		this.WriteHtml();
	}
	else if(document.layers){
		this.div = new Layer(this.nW);
		this.divEv = new Layer(this.nW);
		this.sId = this.div.name;
		this.div.resizeTo(this.nW,this.nH);
		this.divEv.resizeTo(this.nW,this.nH);
		this.MoveTo();
		this.WriteHtml();
	}
}

//------------------------------------------------------------------------------
//	背景色
function LaySetBgColor(sBgc)
{
	if(document.all){
		this.div.style.backgroundColor = sBgc;
	}
	else if(document.layers){
		this.div.bgColor = sBgc;
	}
}

//------------------------------------------------------------------------------
//	HTML書き換え処理

function LayWriteHtml(sHtml)
{
	if(arguments.length>0)	this.sHtml = sHtml;
	if(document.all){
		this.div.innerHTML = this.sHtml;
	}
	else if(document.layers){
		this.div.document.open('text/html','replace');
		this.div.document.writeln(this.sHtml);
		this.div.document.close();
	}
}

//------------------------------------------------------------------------------
//	レイヤーの移動

function LayMoveTo(nX,nY,nZ)
{
	if(arguments.length>0){
		this.nX = nX;
		this.nY = nY;
		this.nZ = nZ;
	}
	
	if(document.all){
		this.div.style.posLeft = this.nX;
		this.div.style.posTop = this.nY;
		this.div.style.zIndex = this.nZ;
		this.divEv.style.posLeft = this.nX;
		this.divEv.style.posTop = this.nY;
		this.divEv.style.zIndex = this.nZ;
	}else if(document.layers){
		this.div.left = this.nX;
		this.div.top = this.nY;
		this.div.zIndex = this.nZ;
		this.divEv.left = this.nX;
		this.divEv.top = this.nY;
		this.divEv.zIndex = this.nZ+1;
	}
}

//------------------------------------------------------------------------------
//	可視状態取得処理

function LayIsVsbl()
{
	if(document.all){
		return (this.div.style.visibility == 'inherit') ? true : false;
	}
	else if(document.layers){
		return (this.div.visibility == 'inherit') ? true : false;
	}
}

//------------------------------------------------------------------------------
//	可視状態設定処理

function LaySetVsbl(bV)
{
	if(this.bEnableDrag){
		if(document.all){
			this.div.style.visibility = (bV) ? 'inherit' : 'hidden';
			this.divEv.style.visibility = (bV) ? 'inherit' : 'hidden';
		}
		else if(document.layers){
			this.div.visibility = (bV) ? 'inherit' : 'hidden';
			this.divEv.visibility = (bV) ? 'inherit' : 'hidden';
		}
	}
	else{
		if(document.all){
			this.div.style.visibility = (bV) ? 'inherit' : 'hidden';
			this.divEv.style.visibility = 'hidden';
		}
		else if(document.layers){
			this.div.visibility = (bV) ? 'inherit' : 'hidden';
			this.divEv.visibility = 'hidden';
		}
	}
}

//------------------------------------------------------------------------------
//	ドラッグ動作許可処理

function LaySetDrag(bEnable)
{
	if(bEnable){
		if(!this.bEnableDrag){
			this.bEnableDrag = true;
			if(document.all){
				this.divEv.style.cursor = 'move';
				this.divEv.onmousedown = LayComMDown;
				document.onmousemove = LayComMMove;
				document.onmouseup   = LayComMUp;
				this.divEv.style.visibility = 'inherit';
			}
			else if(document.layers){
				this.divEv.document.onmousedown = LayComMDown;
				document.onmousemove = LayComMMove;
				document.onmouseup   = LayComMUp;
				this.divEv.document.captureEvents(Event.MOUSEDOWN);
				document.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
				this.divEv.visibility = 'inherit';
			}
		}
	}
	else{
		if(this.bEnableDrag){
			this.bEnableDrag = false;
			if(document.all){
				this.divEv.style.visibility = 'hidden';
			}
			else if(document.layers){
				this.divEv.visibility = 'hidden';
			}
		}
	}
}

//------------------------------------------------------------------------------
//	共通マウスダウン

function LayComMDown(e)
{
	var i,pX,pY,oX,oY;
	
	if(document.all){
		pX = document.body.scrollLeft+window.event.clientX;
		pY = document.body.scrollTop+window.event.clientY;
		oX = window.event.offsetX;
		oY = window.event.offsetY;
	}
	else if(document.layers){
		pX = e.pageX;
		pY = e.pageY;
		oX = e.layerX;
		oY = e.layerY;
	}
	
	if(document.all){
		for(i=0;i<nLay;i++){
			if(aLay[i].sId+'Ev' == window.event.srcElement.id){
				aLay[i].MDown(pX,pY,oX,oY);
				break;
			}
		}
	}
	else if(document.layers){
		for(i=0;i<nLay;i++){
			var div = aLay[i].divEv;
			if((pX > div.left)
			&& (pX < div.left+div.clip.width)
			&& (pY > div.top)
			&& (pY < div.top+div.clip.height)){
				aLay[i].MDown(pX,pY,oX,oY);
				break;
			}
		}
	}
	
	/* falseを戻し、ブラウザにデフォルトの動作を禁止させる */
	return false;
}

//------------------------------------------------------------------------------
//	共通マウスムーブ

function LayComMMove(e)
{
	var i,pX,pY,oX,oY;
	var ret=true;
	
	if(document.all){
		pX = document.body.scrollLeft+window.event.clientX;
		pY = document.body.scrollTop+window.event.clientY;
		oX = window.event.offsetX;
		oY = window.event.offsetY;
	}
	else if(document.layers){
		pX = e.pageX;
		pY = e.pageY;
		oX = e.layerX;
		oY = e.layerY;
	}
	
	for(i=0;i<nLay;i++){
		if(!aLay[i].MMove(pX,pY,oX,oY)){
				ret = false;
		}
	}
	
	/* 処理を行った場合だけfalseを戻し、ブラウザにデフォルトの動作を禁止させる */
	return ret;
}

//------------------------------------------------------------------------------
//	共通マウスアップ

function LayComMUp(e)
{
	var i,pX,pY,oX,oY;
	
	if(document.all){
		pX = document.body.scrollLeft+window.event.clientX;
		pY = document.body.scrollTop+window.event.clientY;
		oX = window.event.offsetX;
		oY = window.event.offsetY;
	}
	else if(document.layers){
		pX = e.pageX;
		pY = e.pageY;
		oX = e.layerX;
		oY = e.layerY;
	}
	
	for(i=0;i<nLay;i++){
		aLay[i].MUp(pX,pY,oX,oY);
	}
	
	/* trueを戻し、ブラウザはデフォルトの動作可能 */
	return true;
}

//------------------------------------------------------------------------------
//	マウスダウンイベント

function LayMDown(pX,pY,oX,oY)
{
	if(this.bEnableDrag){
		this.offX = oX;
		this.offY = oY;
		this.bDrag = true;
		return false;
	}
	return true;
}

//------------------------------------------------------------------------------
//	マウスムーブイベント

function LayMMove(pX,pY,oX,oY)
{
	if(this.bEnableDrag && this.bDrag){
		this.nX = pX - this.offX;
		this.nY = pY - this.offY;
		this.MoveTo();
		return false;
	}
	return true;
}

//------------------------------------------------------------------------------
//	マウスアップイベント

function LayMUp(pX,pY,oX,oY)
{
	if(this.bDrag){
		this.bDrag = false;
	}
	return true;
}

//------------------------------------------------------------------------------
