//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//	AJAX Framework / Window
//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//	無断配布や二次利用を禁止します。
//	最終更新：2011/3/13 2: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 );
}
function cheltenhamWindow_scrollToTopGradually( iMax )
{
	var positionStart = cheltenhamWindow_getScrollPosition();
	var positionEnd = { x: 0, y: 0 };
	var positionNow = { x: positionStart.x, y: positionStart.y };
	var i = 1;
	var tweenTimer = null;
	var tweenTime = 10;
	if( !iMax )
	{
		iMax = 1;
	}

	var functionRefference = function()
	{
		positionNow.x = positionStart.x + ( positionEnd.x - positionStart.x ) * ( i / iMax );
		positionNow.y = positionStart.y + ( positionEnd.y - positionStart.y ) * ( i / iMax );
		window.scrollTo( positionNow.x, positionNow.y );
		i++;
		if( i > iMax )
		{
			clearInterval( tweenTimer );
			tweenFlagLock = 0;
		}
	}
	tweenTimer = setInterval( functionRefference, tweenTime );
}
// ウィンドウのスクロール座標を取得
function cheltenhamWindow_getScrollPosition()
{
	var position = new Object();
	position.x = document.documentElement.scrollLeft || document.body.scrollLeft;
	position.y = document.documentElement.scrollTop || document.body.scrollTop;
	return( position );
}

// 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 );
	}
}

