

var PAGESLIDER = new PageSlider( .35, .65, 30 ) ;



function PageSlider( percent, percent2, step )

{

	this.lastPageScrollX = null ;

	this.lastPageScrollY = null ;



	this.percent     = Number( percent ) ;

	this.percent2    = Number( percent2 ) ;

	this.action      = null ;

	this.step        = Number( step ) ;



	this.targetPosX  = Number( ) ;

	this.targetPosY  = Number( ) ;

	this.currentPosX = Number( ) ;

	this.currentPosY = Number( ) ;

}



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

	{

		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   = anchorObj.x ;



		this.targetPosX   = Number( 0 ) ;



		this.currentPosX  = Number( getPageOffset( 'left' ) ) ;

		this.currentPosY  = Number( getPageOffset( 'top' ) ) ;

//window.status = ( this.currentPosY )

		if ( this.action )

		{

			this.clearTimer( ) ;

		}

		else

		{

			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( ) ;

	var nextY       = Number( ) ;



	if ( this.currentPosX == this.targetPosX && this.currentPosY == this.targetPosY )

	{

		this.clearTimer( ) ;

	}

	else

	{

		nextX = ( this.targetPosX - this.currentPosX ) * this.percent * this.percent2 ;

		nextY = ( this.targetPosY - this.currentPosY ) * this.percent * this.percent2 ;



		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 ;

}




