
/*

	===========================================

	[ dhtml-lib.js ] 2000/10/05更新

	Kenichi KAWAMURA
	kawamura@makaonet.com
	http://www.makaonet.com/kawamura/

	===========================================

	references
	・「JavaScriptクックブック」オライリー・ジャパン
	・「インサイドDynamicHTML」日経ＢＰソフトプレス
	・「CSSとDHTML」ピアソン・エデュケーション

	・ http://www5.airnet.ne.jp/martin/index.html
	 （ getWinSize,replaceContent,getClipValue,clipLayerTo,clipLayerBy ）

*/





//	::::::::::::::: 簡易・ブラウザチェック :::::::::::::::

var isNav	= ( document.layers ? true : false ) ;

var isIE	= ( document.all ? true : false ) ;

var isGecko	= ( document.getElementById ? true : false ) ;



//	:::::::::::::::::::: リンクの指定 ::::::::::::::::::::

//	JS
function setJsLink( which, URL )
{
	eval( which ).location = URL ;
}

//	HTML
function setHyperLink( linkName, which, URL )
{
	document.links[ linkName ].target = which ;
	document.links[ linkName ].href = URL ;
}





//	::::::::::::::: レイヤーを参照する関数 :::::::::::::::

function refLayer( layerName )
{
	if ( isNav )
	{
		return document.eval( layerName ) ;
	}
	if ( isIE )
	{
		return document.all[ layerName ].style ;
	}
	if ( isGecko )
	{
		return document.getElementById( layerName ).style ;
	}
}

function refFrameLayer( which, frameName, layerName )
{
	if ( isNav )
	{
		return eval( which + "." + frameName + ".document." + layerName ) ;
	}
	if ( isIE )
	{
		return eval( which + "." + frameName + "." + layerName + ".style" ) ;
	}
}





//	::::::::::::::: レイヤーの階層を変える :::::::::::::::

function setZindex( layerName, zOrder )
{
	refLayer( layerName ).zIndex = zOrder ;
}





//	::::::::::::::: レイヤーの表示・非表示 :::::::::::::::

function hideLayer( layerName )
{
	var hideName = ( isNav ) ? "hide" : "hidden" ;
	refLayer( layerName ).visibility = hideName ;
}

function showLayer( layerName )
{
	var showName = ( isNav ) ? "show" : "visible" ;
	refLayer( layerName ).visibility = showName ;
}

function hideFrameLayer( which, frameName, layerName )
{
	var hideName = ( isNav ) ? "hide" : "hidden" ;
	refFrameLayer( which, frameName, layerName ).visibility = hideName ;
}

function showFrameLayer( which, frameName, layerName )
{
	var showName = ( isNav ) ? "show" : "visible" ;
	refFrameLayer( which, frameName, layerName ).visibility = showName ;
}





//	:::::::::::::::::: レイヤーを動かす ::::::::::::::::::

function shiftLayerTo( layerName, x, y )
{

	refLayer( layerName ).left = x ;
	refLayer( layerName ).top  = y ;
}

function shiftLayerBy( layerName, x, y )
{
	if ( isIE )
	{
		refLayer( layerName ).pixelLeft += x ;
		refLayer( layerName ).pixelTop  += y ;
	}
	if ( isNav )
	{
		refLayer( layerName ).moveBy( x, y ) ;
	}
}

var x,y = 0 ;
function slideLayerTo( layerName, finalX, finalY )
{
	var currentX = getLayerSize( layerName, "left" ) ;
	var currentY = getLayerSize( layerName, "top" ) ;

	var diffX = finalX - currentX ;
	var diffY = finalY - currentY ;

	var percent = new Array( ) ;
	percent[ 0 ] = .1 * diffX ;
	percent[ 1 ] = .1 * diffY ;

	for ( var i in percent )
	{
		percent[i] = Math.round( percent[i] ) ;
	}

	if ( currentX != finalX )
		x = percent[0] ;

	if ( currentY != finalY )
		y = percent[1] ;

	if ( percent[ 0 ] == 0 && percent[ 1 ] == 0 )
		return ;

	shiftLayerBy( layerName, x, y ) ;

	setTimeout( 'slideLayerTo("' + layerName + '",' + finalX + ',' + finalY + ')', 1 ) ;
}





//	::::::::::::::: クリッピングの値を取得 :::::::::::::::

function getClipValue( layerName,value )
{
	if( isIE )
	{
		var cp = refLayer( layerName ).clip.split(" ") ;
		cp[0] = cp[0].slice(5) ;

		switch ( value )
		{
			case "top" :
				return parseInt( cp[0] ) ;
			case "right" :
				return parseInt( cp[1] ) ;
			case "bottom" :
				return parseInt( cp[2] ) ;
			case "left" :
				return parseInt( cp[3] ) ;
		}
	}
	if( isNav )
	{
		switch ( value )
		{
			case "top" :
				return ( refLayer( layerName ).clip.top ) ;
			case "right" :
				return ( refLayer( layerName ).clip.right ) ;
			case "bottom" :
				return ( refLayer( layerName ).clip.bottom ) ;
			case "left" :
				return ( refLayer( layerName ).clip.left ) ;
		}
	}
}





//	:::::::::::::::::::: クリッピング ::::::::::::::::::::

function clipLayerTo( layerName,t,r,b,l )
{
	if( isIE )
	{
		refLayer( layerName ).clip = "rect("+t+" "+r+" "+b+" "+l+")" ;
	}
	if ( isNav )
	{
		refLayer( layerName ).clip.top = t ;
		refLayer( layerName ).clip.right = r ;
		refLayer( layerName ).clip.bottom = b ;
		refLayer( layerName ).clip.left = l ;
	}
}

// clip layerBy
function clipLayerBy( layerName, t, r, b, l )
{
	if( isIE )
	{
		refLayer( layerName ).clip = "rect("+( getClipValue( layerName,'top'   )+t ) + " "
											+( getClipValue( layerName,'right' )+r ) + " "
											+( getClipValue( layerName,'bottom')+b ) + " "
											+( getClipValue( layerName,'left'  )+l ) + ")" ;
	}
	if( isNav )
	{
		refLayer( layerName ).clip.top    = ( getClipValue(layerName,'top'   ) ) + t ;
		refLayer( layerName ).clip.right  = ( getClipValue(layerName,'right' ) ) + r ;
		refLayer( layerName ).clip.bottom = ( getClipValue(layerName,'bottom') ) + b ;
		refLayer( layerName ).clip.left   = ( getClipValue(layerName,'left'  ) ) + l ;
	}
}






function wipeLayerBy( layerName, endPoint, direction, wipeType, step )
{
	var speed = 1 ;
	var t = r = b = l = 0 ;

	step += 1 ;

	if ( wipeType == "wipeIn" )
	{
		if ( direction == "fromLeft" )
		{
			if ( ( getClipValue(layerName,'right') + step ) < endPoint )
			{
				r = step ;
			}
			else if ( getClipValue(layerName,'right') < endPoint )
			{
				r = endPoint - getClipValue(layerName,'right') ;
			}
		}
		if ( direction == "fromRight" )
		{
			if ( ( getClipValue(layerName,'left') - step ) > endPoint )
			{
				l = -step ;
			}
			else if ( getClipValue(layerName,'left') > endPoint )
			{
				l = endPoint - getClipValue(layerName,'left') ;
			}
		}
		if ( direction == "fromTop" )
		{
			if ( ( getClipValue(layerName,'bottom') + step ) < endPoint )
			{
				b = step ;
			}
			else if ( getClipValue(layerName,'bottom') < endPoint )
			{
				b = endPoint - getClipValue(layerName,'bottom') ;
			}
		}
		if ( direction == "fromBottom" )
		{
			if ( ( getClipValue(layerName,'top') - step ) > endPoint )
			{
				t = -step ;
			}
			else if ( getClipValue(layerName,'top') > endPoint )
			{
				t = endPoint - getClipValue(layerName,'top') ;
			}
		}
		if ( direction == "fromCenterX" )
		{
			if ( ( getClipValue(layerName,'left') - step ) > endPoint )
			{
				r = step ;
				l = -step ;
			}
			else if ( getClipValue(layerName,'left') > endPoint )
			{
				r = ( endPoint - getClipValue(layerName,'left') ) * -1 ;
				l = endPoint - getClipValue(layerName,'left') ;
			}
		}
		if ( direction == "fromCenterY" )
		{
			if ( ( getClipValue(layerName,'top') - step ) > endPoint )
			{
				t = -step ;
				b = step ;
			}
			else if ( getClipValue(layerName,'top') > endPoint )
			{
				t = endPoint - getClipValue(layerName,'top') ;
				b = ( endPoint - getClipValue(layerName,'top') ) * -1 ;
			}
		}
	}

	if ( wipeType == "wipeOut" )
	{
		if ( direction == "fromLeft" )
		{
			if ( ( getClipValue(layerName,'left') + step ) < endPoint )
			{
				l = step ;
			}
			else if ( getClipValue(layerName,'left') < endPoint )
			{
				l = endPoint - getClipValue(layerName,'left') ;
			}
		}
		if ( direction == "fromRight" )
		{
			if ( ( getClipValue(layerName,'right') - step ) > endPoint )
			{
				r = -step ;
			}
			else if ( getClipValue(layerName,'right') > endPoint )
			{
				r = endPoint - getClipValue(layerName,'right') ;
			}
		}
		if ( direction == "fromTop" )
		{
			if ( ( getClipValue(layerName,'top') + step ) < endPoint )
			{
				t = step ;
			}
			else if ( getClipValue(layerName,'top') < endPoint )
			{
				t = endPoint - getClipValue(layerName,'top') ;
			}
		}
		if ( direction == "fromBottom" )
		{
			if ( ( getClipValue(layerName,'bottom') - step ) > endPoint )
			{
				b = -step ;
			}
			else if ( getClipValue(layerName,'bottom') > endPoint )
			{
				b = endPoint - getClipValue(layerName,'bottom') ;
			}
		}
		if ( direction == "fromCenterX" )
		{
			if ( ( getClipValue(layerName,'right') - step ) > endPoint )
			{
				r = -step ;
				l = step ;
			}
			else if ( getClipValue(layerName,'right') > endPoint )
			{
				r = endPoint - getClipValue(layerName,'right') ;
				l = ( endPoint - getClipValue(layerName,'right') ) * -1 ;
			}
		}
		if ( direction == "fromCenterY" )
		{
			if ( ( getClipValue(layerName,'bottom') - step ) > endPoint )
			{
				t = step ;
				b = -step ;
			}
			else if ( getClipValue(layerName,'bottom') > endPoint )
			{
				t = ( endPoint - getClipValue(layerName,'bottom') ) * -1 ;
				b = endPoint - getClipValue(layerName,'bottom') ;
			}
		}
	}

	clipLayerBy( layerName, t, r, b, l ) ;

	if ( ( t || r || b || l ) == 0 )
	{
		clearTimeout( ClipAction ) ;
		return false ;
	}
	else
		ClipAction = setTimeout( "wipeLayerBy('"+layerName+"',"+endPoint+",'"+direction+"','"+wipeType+"',"+step+")", speed);
}





//	:::::::::::::::: 表示領域を拡大させる ::::::::::::::::

function wipeLayerTo( layerName, direction, wipeType )
{
	var el = refLayer( layerName ) ;

	if ( null == el.init )
	{
		el.init = true ;
		el.fromTop    = 0 ;
		el.fromRight  = 0 ;
		el.fromBottom = 0 ;
		el.fromLeft   = 0 ;

		el.step = 5 ;
		el.endPoint = 0 ;

		if ( wipeType == "wipeIn" )
		{
			switch ( direction )
			{
				case "fromTop" :
					el.fromTop    = getLayerSize( layerName, "height" ) ;
					el.fromRight  = getLayerSize( layerName, "width" ) ;
					el.fromBottom = getLayerSize( layerName, "height" ) ;
					el.step *= -1 ;
					break ;
				case "fromRight" :
					el.fromBottom = getLayerSize( layerName, "height" ) ;
					el.endPoint   = getLayerSize( layerName, "width" ) ;
					break ;
				case "fromBottom" :
					el.fromRight  = getLayerSize( layerName, "width" ) ;
					el.endPoint   = getLayerSize( layerName, "height" ) ;
					break ;
				case "fromLeft" :
					el.fromRight  = getLayerSize( layerName, "width" ) ;
					el.fromBottom = getLayerSize( layerName, "height" ) ;
					el.fromLeft   = getLayerSize( layerName, "width" ) ;
					el.step *= -1 ;
					el.endPoint = 0 ;
					break ;
			}
		}

		if ( wipeType == "wipeOut" )
		{
			switch ( direction )
			{
				case "fromTop" :
					el.fromRight  = getLayerSize( layerName, "width" ) ;
					el.fromBottom = getLayerSize( layerName, "height" ) ;
					el.endPoint   = getLayerSize( layerName, "height" ) ;
					break ;
				case "fromRight" :
					el.fromRight  = getLayerSize( layerName, "width" ) ;
					el.fromBottom = getLayerSize( layerName, "height" ) ;
					el.step *= -1 ;
					break ;
				case "fromBottom" :
					el.fromRight  = getLayerSize( layerName, "width" ) ;
					el.fromBottom = getLayerSize( layerName, "height" ) ;
					el.step *= -1 ;
					break ;
				case "fromLeft" :
					el.fromRight  = getLayerSize( layerName, "width" ) ;
					el.fromBottom = getLayerSize( layerName, "height" ) ;
					el.endPoint   = getLayerSize( layerName, "width" ) ;
					break ;
			}
		}
	}

	el.step *= 1.2 ;

	if( el.step > 0 )
		el.step = Math.ceil( el.step ) ;
	else
		el.step = Math.floor( el.step ) ;

	el[ direction ] += el.step ;

// window.status = el[ direction ] + " " + el.fromLeft
	clipLayerTo( layerName, el.fromTop, el.fromRight, el.fromBottom, el.fromLeft ) ;

	if ( el.endPoint > el[ direction ] && el.step > 0 || el[ direction ] > 0 && el.step < 0 )
		setTimeout("wipeLayerTo('"+layerName+"','"+direction+"','"+wipeType+"')", 1 );
	else
		el.init = null ;

}





//	::::::::::::::: レイヤーの大きさを変更 :::::::::::::::

function resizeLayerTo( layerName, x, y )
{
	if ( isIE )
	{
		refLayer( layerName ).width  = x ;
		refLayer( layerName ).height = y ;
	}
	if ( isNav )
	{
		refLayer( layerName ).resizeTo( x, y ) ;
	}
}





//	::::::::::::::::: レイヤーの値を取得 :::::::::::::::::

function getLayerSize( layerName, value )
{
	layer = ( isIE ) ? document.all( layerName ) : document.eval( layerName ) ;

	if( value == "left" )
		return ( isIE ) ? layer.offsetLeft : layer.left ;
	if( value == "top" )
		return ( isIE ) ? layer.offsetTop : layer.top ;
	if( value == "width" )
		return ( isIE ) ? layer.offsetWidth : layer.document.width ;
	if( value == "height" )
		return ( isIE ) ? layer.offsetHeight : layer.document.height ;
}





//	::::::::::::: レイヤーの中央の座標を取得 :::::::::::::

function getCenterSize( layerName, which )
{
	return ( getWinSize( which ) - getLayerSize( layerName, which ) ) / 2 ;
}





function replaceContent( layerName, txt )
{
	if( isIE )
	{
		eval( layerName ).innerHTML = txt ;
	}
	if( isNav )
	{
		refLayer( layerName ).document.open( "text/html" ) ;
		refLayer( layerName ).document.write( txt ) ;
		refLayer( layerName ).document.close( ) ;
	}
	if( isGecko )
	{
		document.getElementById( layerName ).innerHTML = txt ;
	}
}


//	:::::::::::::: ページのオフセットを取得 ::::::::::::::

function getPageOffset( which )
{
	if ( which == "left" )
		return ( isIE ) ? document.body.scrollLeft : self.pageXOffset ;
	if ( which == "top" )
		return ( isIE ) ? document.body.scrollTop : self.pageYOffset ;
}





//	:::::::::::::::: windowの大きさを取得 ::::::::::::::::

function getWinSize( which )
{
	if ( which == "width" )
		return ( isIE ) ? document.body.clientWidth : window.innerWidth ;
	if ( which == "height" )
		return ( isIE ) ? document.body.clientHeight : window.innerHeight ;
}





//	:::::::::::::::::: 画面のスクロール ::::::::::::::::::

function doPageScroll( st_X,max_X,st_Y,max_Y )
{
	var diffX,diffY,stepX,stepY,moveX,moveY ;

	diffX = .1 * ( max_X - st_X ) ;
	if( diffX > 0 )
		stepX = Math.ceil( diffX ) ;
	else
		stepX = Math.floor( diffX ) ;

	diffY = .1 * ( max_Y - st_Y ) ;
	if( diffY > 0 )
		stepY = Math.ceil( diffY ) ;
	else
		stepY = Math.floor( diffY ) ;

	moveX = st_X + stepX ;
	moveY = st_Y + stepY ;
	
// window.status = "X is : " +moveX+ " Y is : " +moveY ;

	if ( stepX > 0 && moveX <= max_X || stepY > 0 && moveY <= max_Y ||
		 stepX < 0 && moveX >= max_X || stepY < 0 && moveY >= max_Y )
	{
		scroll( moveX,moveY )

		st_X += stepX ;
		st_Y += stepY ;

		setTimeout( "doPageScroll( " +st_X+ "," +max_X+ "," +st_Y+ "," +max_Y+ " )",1 ) ;
	}
	else return true ;
}

function pageScrollTo( max_X,max_Y )
{
	var st_X,st_Y ;

	st_X = getPageOffset( "left" ) ;
	st_Y = getPageOffset( "top" ) ;

	doPageScroll( st_X,max_X,st_Y,max_Y ) ;
}





//	::::::::::::::: 新しくwindowを開く関数 :::::::::::::::

function openWin( url, w, h, winName )
{
	var startWinX = ( screen.availWidth  - w ) / 2 ;
	var startWinY = ( screen.availHeight - h ) / 2 ;

	if ( arguments[4] == "no" )
		winOption = "directories=no,status=no,scrollbars=no,toolbar=no,location=no,menubar=no,resizable=yes,width=" + w + ",height=" + h + ",left=" + startWinX + ",top=" + startWinY ;

	if ( arguments[4] == "yes" )
		winOption = "directories=yes,status=yes,scrollbars=yes,toolbar=yes,location=yes,menubar=yes,resizable=yes,width=" + w + ",height=" + h + ",left=" + startWinX + ",top=" + startWinY ;

	winName = window.open( url, winName, winOption ) ;
	winName.focus( ) ;
}





//	:::::::::::::::::: サブ・ウィンドウ ::::::::::::::::::

function delayWin( url, winOption )
{
	var submenu = window.open ( url, "subwin", winOption ) ;

	if ( closetime )
		setTimeout("submenu.close( );", closetime * 1000 ) ;
}

function openSubWin( url,w,h,st,sc,t,l,m,r,x,y,ct,delay )
{
	closetime	= ct ;

	var winOption = "status=" + st + ",toolbar=" + t + ",location=" + l + ",menubar=" + m + ",scrollbars=" + sc + ",resizable=" + r + ",left=" + x + ",top=" + y + ",width=" + w + ",height=" + h ;

	setTimeout("delayWin( '" +url+ "','" +winOption+ "' )", delay * 1000 );
}





//	::::::::::::::: ステータス・メッセージ :::::::::::::::

function LaserWriter( msg )
{
	var endLoop	= 1 ;
	var changeTimer	= 1 ;
	var SGN = "___|" ;

	nowLoop = 0 ;
	nowCount = 0 ;
	LWActon = "" ;

	doLaserWriter( msg,endLoop,SGN,changeTimer ) ;
}

function doLaserWriter( msg,endLoop,SGN,changeTimer )
{
	random_number = "" ;

	nowMsg = msg.substring( 0, nowCount ) ;

	for( var i = nowCount ; i < msg.length ; i++ )
	{
		j = SGN.charAt( Math.floor( Math.random( ) * SGN.length ) );
		random_number += j ;
	}

	window.status = " " + nowMsg + random_number ;

	if ( nowLoop++ > endLoop )
	{
		nowLoop = 0 ;
		nowCount++ ;
	}

	if ( nowCount > msg.length )
	{
		clearTimeout( LWActon ) ;
	}
	else
	{
		LWActon = setTimeout( "doLaserWriter( '" +msg+ "','" +endLoop+ "','" +SGN+ "','" +changeTimer+ "' )", changeTimer ) ;
	}

}

function ClearLaserWriter( )
{
	clearTimeout( LWActon ) ;
	window.status = "" ;
}






