
var PAGESLIDER = new PageSlider( .15, 30 ) ;

function setScrollNavi( )
{

}

function PageSlider( percent, step )
{
	this.lastPageScrollX = null ;
	this.lastPageScrollY = null ;

	this.percent     = Number( percent ) ;
	this.action      = null ;
	this.step        = Number( step ) ;

	this.targetPosX  = Number( 0 ) ;
	this.targetPosY  = Number( 0 ) ;
	this.currentPosX = Number( 0 ) ;
	this.currentPosY = Number( 0 ) ;
}

PageSlider.prototype.versionCheck = function( )
{
	var flag = ( ( NN4 && getBrowserVersion( ).substr( 0, 3 ).toString( ) != '4.0' ) || IE4 || IE5 || NN6 ) ? true : false ;

	return flag ;
}

PageSlider.prototype.setAnchor = function( id )
{
	this.anchor = id ;
}

PageSlider.prototype.getAnchor = function( id )
{
	return this.anchor ;
}

PageSlider.prototype.slideTop = function( )
{
	this.targetPosY   = Number( 0 ) ;

	this.targetPosX   = Number( 0 ) ;
	this.currentPosX  = Number( getPageOffset( 'left' ) ) ;
	this.currentPosY  = Number( getPageOffset( 'top' ) ) ;

	if ( this.action )
	{
		this.clearTimer( ) ;
	}
	else
	{
		// ---------------------------------------------------
		// ■スライドナビをOFFにする
		// ---------------------------------------------------
		setScrollNavi( false ) ;
		this.action = setInterval( "PAGESLIDER.slide( )", this.step ) ;
	}
}

PageSlider.prototype.slideAnchor = function( id )
{
	if ( !this.versionCheck( ) )
	{
		location.hash = id ;
	}
	else
	{
		var anchorObj = getAnchorObj( id ) ;
		this.targetPosY   = anchorObj.y ;
		this.targetPosX   = Number( getPageOffset( 'left' ) ) ; // ■X座標の移動を回避
		this.currentPosX  = Number( getPageOffset( 'left' ) ) ;
		this.currentPosY  = Number( getPageOffset( 'top' ) ) ;

		// 高さを補正
		// Mac + IE の場合、getPageHeight( ) で正しい値を取得できないため、非対応
		// alert( getPageHeight( ) + " : " + getWinSize( 'height' ) + " : " + document.body.offsetHeight)
		var maxScrollHeight = getPageHeight( ) - getWinSize( 'height' ) ;
		if ( maxScrollHeight != 0 && this.targetPosY > maxScrollHeight )
		{
			this.targetPosY = maxScrollHeight ;
		}

		if ( this.action )
		{
			this.clearTimer( ) ;
		}
		else
		{
			// ---------------------------------------------------
			// ■スライドナビをOFFにする
			// ---------------------------------------------------
			setScrollNavi( false ) ;
			this.action = setInterval( "PAGESLIDER.slide( )", this.step ) ;
		}
	}
}

/* -----------------------------------------------------------------
【 アンカーの中にイメージを挿入するときの注意事項 】
 ・ hspace や vspace を指定すると、IEとNNとの間で、解釈が異なる
    → これらの属性の指定は避ける
----------------------------------------------------------------- */
function getAnchorObj( id, dc, lyr )
{
	var layerObj  = refLayer( id ) ;
	var anchorObj = new Object( ) ;
	var tempObj   = null ;
	var anc       = null ;

	if ( IE4 || IE5 || NN6 )
	{
		tempObj     = layerObj ;
		anchorObj.x = tempObj.offsetLeft ;
		anchorObj.y = tempObj.offsetTop ;

		while ( (tempObj = tempObj.offsetParent ) != null )
		{
			anchorObj.x += tempObj.offsetLeft ;
			anchorObj.y += tempObj.offsetTop ;
		}
	}
	else if ( NN4 )
	{
		if ( !dc )
		{
			dc = document ;
		}

		if ( ! ( anc = dc.anchors[ id ] ) && dc.layers.length >= 1 )
		{
			for( i=0; !anc && i<dc.layers.length; i++ )
			{
				anc = getAnchorObj( id, dc.layers[i].document, dc.layers[i] ) ;
			}
		}

		if ( anc )
		{
			var bufX = ( lyr ) ? lyr.left : 0 ;
			var bufY = ( lyr ) ? lyr.top  : 0 ;

			anchorObj.x = anc.x + bufX ;
			anchorObj.y = anc.y + bufY ;
		}
		else
		{
			return anc ;
		}
	}
	else
	{
		anchorObj.x = 0 ;
		anchorObj.y = 0 ;
	}

	return anchorObj ;
}

PageSlider.prototype.slide = function( )
{
	var nextX = Number( 0 ) ;
	var nextY = Number( 0 ) ;

	if ( this.currentPosX == this.targetPosX && this.currentPosY == this.targetPosY )
	{
		// ---------------------------------------------------
		// ■スライドナビをONにする
		// ---------------------------------------------------
		setScrollNavi( true ) ;

		this.clearTimer( ) ;
	}
	else
	{
		nextX = ( this.targetPosX - this.currentPosX ) * this.percent ;
		nextY = ( this.targetPosY - this.currentPosY ) * this.percent ;

		nextX = ( nextX > 0 ) ? Math.ceil( nextX ) : Math.floor( nextX ) ;
		nextY = ( nextY > 0 ) ? Math.ceil( nextY ) : Math.floor( nextY ) ;

		this.currentPosX += nextX ;
		this.currentPosY += nextY ;

		window.scrollTo( this.currentPosX, this.currentPosY ) ;

		this.lastPageScrollX = this.currentPosX ;
		this.lastPageScrollY = this.currentPosY ;
	}
}

PageSlider.prototype.clearTimer = function( )
{
	clearInterval( this.action ) ;
	this.action   = null ;
	this.lastPageScrollX = null ;
	this.lastPageScrollY = null ;
}
