// =============================================================================
// IFRAMEスクロールクラス
// =============================================================================
/*
   ScrollControl クラス

   最終更新日:2003年10月17日(金)
   -----------------------------------------------------------------------------

   依存
	sniffer.js

   -----------------------------------------------------------------------------

   コンストラクタの引数
	window targetIframe	- スクロールさせるIframeのウィンドウオブジェクト

   -----------------------------------------------------------------------------

   メソッド
	- init( targetIframe )
		初期化

	- setTarget( targetIframe )
		ターゲットとなるIframeウィンドウオブジェクトを設定する。

	- up()
		上にスクロールトリガー

	- scrollUp()
		上にスクロールループ

	- down()
		下にスクロールトリガー

	- scrollDown()
		下にスクロールループ

	- stop()
		スクロールを停止
*/
// =============================================================================
if(sniffer.DOMable()) {



// -----------------------------------------------------------------------------
/*
   オブジェクト準備
*/
function ScrollControl ( targetIframe, instanceName, direction, wheelable, delta, wheelDelta ) {
	this.target = null;
	this.timer = null;
	this.instanceName = ( typeof instanceName == "undefined" ) ? "scrollControl" : instanceName;
	this.direction = ( typeof direction == "undefined" ) ? "y" : direction;
	this.wheelable = ( typeof wheelable == "undefined" ) ? true : wheelable;
	
	if( typeof delta != "undefined" ) {
		this.delta = delta;
	}
	if( typeof wheelDelta != "undefined" ) {
		this.wheelDelta = wheelDelta;
	}

	if( typeof targetIframe != "undefined" ) this.init( targetIframe );
	else this.init();
}
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
/*
   共通プロパティ(デフォルト値)
*/
ScrollControl.prototype.delta = 10;
ScrollControl.prototype.wheelDelta = 20;
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
/*
   initメソッド
	Null scrollControl.init( targetIframe )

		Window targetIframe	-	スクロールさせるIframeのウィンドウオブジェクト
*/
ScrollControl.prototype.init = function( targetIframe ) {
	this.target = null;

	if( this.timer != null ) {
		clearTimeout(this.timer);
		this.timer = null;
	}

	if( typeof targetIframe != "undefined" ) this.setTarget( targetIframe );
}
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
/*
   setTargetメソッド
	Null scrollControl.setTarget( targetIframe )

		Window targetIframe	-	スクロールさせるIframeのウィンドウオブジェクト
*/
ScrollControl.prototype.setTarget = function( targetIframe ) {
	this.target = targetIframe;

	//WheelScroll For IE5-/Win
	if(document.all && document.getElementById && navigator.userAgent.toLowerCase().indexOf("mac") == -1)
	{
		var self = this;
		if(this.wheelable && this.target.document && this.target.document.getElementsByTagName && this.target.document.getElementsByTagName("BODY")[0])
		{
			this.target.document.getElementsByTagName("BODY")[0].onmousewheel = function() {
				var e = self.target.event.wheelDelta;
				if(e >= 120)
				{
					self.scrollUp(self.wheelDelta);
				}
				else if(e <= -120)
				{
					self.scrollDown(self.wheelDelta);
				}
			
				self.target.event.returnValue = false;
			};
		}
	}

}
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
/*
   upメソッド
	Null scrollControl.up()
*/
ScrollControl.prototype.up = function() {
	this.timer = setInterval( this.instanceName + ".scrollUp()", 50 );
}
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
/*
   scrollUpメソッド
	Null scrollControl.scrollUp( delta )

		Number delta	-	スクロールさせる幅。
					これが指定されている場合、this.deltaよりこちらが優先される。
*/
ScrollControl.prototype.scrollUp = function( delta ) {
	if( this.direction == "y" ) {
		this.target.scrollBy(0, (typeof delta != "undefined")? -delta : -this.delta);
	}
	else if( this.direction == "x" ) {
		this.target.scrollBy((typeof delta != "undefined")? -delta : -this.delta, 0);
	}
}
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
/*
   downメソッド
	Null scrollControl.down()
*/
ScrollControl.prototype.down = function() {
	this.timer = setInterval( this.instanceName + ".scrollDown()", 50 );
}
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
/*
   scrollDownメソッド
	Null scrollControl.scrollDown( delta )

		Number delta	-	スクロールさせる幅。
					これが指定されている場合、this.deltaよりこちらが優先される。
*/
ScrollControl.prototype.scrollDown = function( delta ) {
	if( this.direction == "y" ) {
		this.target.scrollBy(0, (typeof delta != "undefined")? delta : this.delta);
	}
	else if( this.direction == "x" ) {
		this.target.scrollBy((typeof delta != "undefined")? delta : this.delta, 0);
	}
}
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
/*
   stopメソッド
	Null scrollControl.stop()
*/
ScrollControl.prototype.stop = function() {
	if( this.timer != null ) {
		clearInterval( this.timer );
		this.timer = null;
	}
}
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
/*
   インスタンス化
*/
var scrollControl = new ScrollControl();
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
/*
   scrollUp・scrollDown・stopScroll 関数
*/
function scrollUp() {
	if( scrollControl.target != null ) scrollControl.up();
}
function scrollDown() {
	if( scrollControl.target != null ) scrollControl.down();
}
function stopScroll() {
	if( scrollControl.target != null ) scrollControl.stop();
}
// -----------------------------------------------------------------------------

}