//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//	AJAX Framework / Window
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//	cheltenham software
//	http://cheltenham-software.com/
//	無断配布や二次利用を禁止します。
//	最終更新：2010/11/8 16:00
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// ウィンドウの表示領域をチェック
function cheltenhamWindow_getSizeDisplay()
{
	var result = { "width" : 0, "height" : 0 };
	// Safari, FireFox, Opera
	if( window.innerWidth )
	{ 
		result.width = window.innerWidth;
		result.height = window.innerHeight;
	}
	// IE
	else if( document.documentElement.clientWidth )
	{
		result.width = document.documentElement.clientWidth;
		result.height = document.documentElement.clientHeight;
	}
	else if( window.self && self.innerHTML )
	{
		result.width = self.innerWidth();
		result.height = self.innerHeight();
	}
	else	
	{
		result.width = document.body.clientWidth;
		result.height = document.body.clientHeight;
	}
	return( result );
}

// ウィンドウのトップまでスクロールする
function cheltenhamWindow_scrollToTop()
{
	window.scrollTo( 0, 0 );
}

// DIVのスクロール
function cheltenhamWindow_scrollPanel( idPanel, idAnchor )
{
	if( document.getElementById( idPanel ) && document.getElementById( idAnchor ) )
	{
		document.getElementById( idPanel ).scrollTop = document.getElementById( idAnchor ).offsetTop;
	}
}

// ウィンドウのスクロールにより要素を移動
function cheltenhamWindow_moveObjectByScroll( idTarget, rateFrame )
{
	if( !document.getElementById( idTarget ) )
	{
		alert( idTarget + ' is not defined.' );
	}
	if( !rateFrame )
	{
		rateFrame = 30;
	}
	var objectTarget = document.getElementById( idTarget );
	if( !objectTarget.style.top )
	{
		objectTarget.style.top = '0px';
	}
	var positionTop = eval( objectTarget.style.top.replace( 'px', '' ) );
	var scrollTop = ( document.body.scrollTop || document.documentElement.scrollTop );
	var gap = positionTop - scrollTop
	var d;
	var functionRefference = function(){ cheltenhamWindow_moveObjectByScroll( idTarget, rateFrame ); };

	if( gap > 0 )
	{
		d = Math.ceil( gap / 2 );
		objectTarget.style.top = ( positionTop - d ) + 'px';
		setTimeout( functionRefference, rateFrame );
	}
	else if( gap < 0 )
	{
		d = Math.ceil( Math.abs( gap ) / 2 );
		objectTarget.style.top = ( positionTop + d ) + 'px';
		setTimeout( functionRefference, rateFrame );
	}
}

