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

// $B%0%m!<%P%kJQ?t(B

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

var gDivName;         // $B%l%$%d!<(B

var gObject;          // $B%*%V%8%'%/%H(B

var gMgnTop;          // $B>e%^!<%8%s(B

var gMgnBtm;          // $B2<%^!<%8%s(B

var gCurrentY;        // $B8=:_$N0LCV(B

var gTop;             // $B=i4|0LCV(B

var gExY = cExY = 10; // $BM>J,$J5wN%(B

var gTurn = 0;        // 0:$BDL>o0\F0(B,1:$B@^$jJV$7(B,2:$BDd;_(B



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

// $B%V%i%&%6%A%'%C%/(B

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

function fCheckBrowser() {

	this.ver   = navigator.appVersion;

	this.agent = navigator.userAgent;

	this.dom   = document.getElementById ? 1 : 0;

	this.mac   = (this.agent.indexOf("Mac") > -1) ? 1 : 0;

	this.op6   = ((this.agent.indexOf("Opera 6") > -1) && this.dom) ? 1 : 0;

	this.ie5   = ((this.ver.indexOf("MSIE 5") > -1) && this.dom && !this.op6) ? 1 : 0;

	this.ie6r  = ((this.ver.indexOf("MSIE 6") > -1) && this.dom && (document.compatMode == "BackCompat")) ? 1 : 0;

	this.ie6s  = ((this.ver.indexOf("MSIE 6") > -1) && this.dom && (document.compatMode == "CSS1Compat")) ? 1 : 0;

	this.ie4   = (document.all && !this.dom) ? 1 : 0;

	this.ie    = (this.ie4 || this.ie5 || this.ie6r || this.ie6s) ? 1 : 0;

	this.ns6   = (this.dom && (parseInt(this.ver) >= 5)) ? 1 : 0;

	this.ns4   = (document.layers && !this.dom) ? 1 : 0;

	this.ns    = (this.ns4 || this.ns6) ? 1 : 0;

	this.bw5   = (this.ie5 || this.ie6r) ? 1 : 0;

	this.bw6   = (this.ie6s || this.ns6 || this.op6) ? 1 : 0;

	this.bw    = (this.ie6r || this.ie6s || this.ie5 || this.ns6 || this.op6) ? 1 : 0;

	return this;

}



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

// $B%l%$%d!<0\F0=`Hw(B

// $B0z?t(Bid:$B%l%$%d!<(BID

// $B!!!!(Bmt:$B>e%^!<%8%s(B

// $B!!!!(Bmb:$B2<%^!<%8%s(B

// $B!!!!(Btp:$B=i4|0LCV(B

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

function ENInit(id, mt, mb, tp) {

	oBw = new fCheckBrowser;

	if (oBw.bw) {

		gDivName         = oBw.bw5 ? document.all(id) : oBw.bw6 ? document.getElementById(id) : 0;

		gObject          = gDivName.style;

		gObject.position = 'relative';

		gMgnTop          = mt ? mt : 0;

		gMgnBtm          = mb ? mb : 0;

		gCurrentY = gTop = tp ? tp : gDivName.offsetTop;

		fMoveLayer();

	}

}



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

// $B%l%$%d!<0\F0(B

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

function fMoveLayer() {

	var lWinH = 0;  // $B%&%#%s%I%&$N=DI}(B

	var lDivH = 0;  // $B%l%$%d!<$N=DI}(B

	var lTgtY   = 0;  // $B0\F0L\I8(B

	var lTgtY1  = 0;  // $B0\F0L\I8!J2<J}0\F0!K(B

	var lTgtY2  = 0;  // $B0\F0L\I8!J>eJ}0\F0!K(B

	var lDtcY   = 0;  // $B0\F05wN%(B



	lDivH = gDivName.offsetHeight;



	if (oBw.ie6s) {

		lWinH = document.documentElement.clientHeight;

	} else if (oBw.ns6 || oBw.op6) {

		lWinH = innerHeight;

	} else if (oBw.bw5) {

		lWinH = document.body.clientHeight;

	} else {

		lWinH = 0;

	}



	if (oBw.ie6s) {

		lTgtY = document.documentElement.scrollTop;

	} else if (oBw.bw5) {

		lTgtY = document.body.scrollTop;

	} else if (oBw.ns6 || oBw.op6) {

		lTgtY = window.pageYOffset;

	} else {

		lTgtY = 0;

	}



	if (lWinH >= gMgnTop + lDivH + gMgnBtm) {

		lTgtY = Math.max(lTgtY + gMgnTop, gTop);

	} else {

		lTgtY1 = Math.max(lTgtY + gMgnTop, gTop);

		lTgtY2 = Math.max(lTgtY - (lDivH + gMgnBtm - lWinH), gTop);

		if (lTgtY1 > gCurrentY && lTgtY2 < gCurrentY) {

			lTgtY = gCurrentY;

		} else if (lTgtY2 < gCurrentY) {

			lTgtY = Math.max(lTgtY1, lTgtY2);

		} else {

			lTgtY = Math.min(lTgtY1, lTgtY2);

		}

	}

	lTgtY += gExY;



	if (lTgtY != gCurrentY) {

		lDtcY = (lTgtY - gCurrentY) * 0.25;

		if (Math.abs(lDtcY) < 1 || (Math.abs(lTgtY - gCurrentY) <= cExY && gTurn == 1)) {

			lDtcY = (lDtcY > 0) ? 1 : (lDtcY < 0) ? -1 : 0;

		}

		gCurrentY   += Math.round(lDtcY);

		gObject.top =  gCurrentY + 'px';

		if (Math.abs(lTgtY - gCurrentY) <= cExY && gTurn == 1) {

			gExY  = 0;

		} else {

			gExY  = (lDtcY > 0) ? cExY : (lDtcY < 0) ? -cExY : 0;

			gTurn = 0;

		}

	} else {

		if (gTurn == 0) {

			gTurn = 1;

			gExY  = 0;

		} else {

			gTurn = 2;

		}

	}



	setTimeout('fMoveLayer()', 16);

}


