// =============================================================================
// 画像順繰り表示管理クラス
// =============================================================================
/*
   photoController クラス

   最終更新日:2004年4月13日(火)
   -----------------------------------------------------------------------------

   依存
	sniffer.js
	window.js(window_mm.js)
	multipleimage.js

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

   コンストラクタの引数
	無し

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

   メソッド
	- init()
		初期化

	- onReady()
		イベント（windowからとんでくるイベント）

	- setup()
		準備

	- prev()
		一つ前の写真に切り替え

	- next()
		一つ後の写真に切り替え

	- viewDetail( link_element )
		現在表示している写真の拡大版をブランクウィンドウで表示

*/
// =============================================================================
if(sniffer.DOMable()) {



// -----------------------------------------------------------------------------
/*
   オブジェクト準備
*/
function PhotoController() {
	this.target = null;
	this.image = null;
	this.length = null;
	this.photos = null;
	this.captions = null;
	this.nowIs = null;
	this.link_element = null;
	this.caption_element = null;

	this.init();
}
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
/*
   initメソッド
	Null photoController.init()
*/
PhotoController.prototype.init = function() {
	this.nowIs = 0;
}
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
/*
   メソッド
	Null photoController.setup()
*/
PhotoController.prototype.setup = function() {
	this.image = new MultipleImage();

	for(var i=0; i<this.length; i++) {
		this.image.addState(i, this.photos[i]);
	}
}
// -----------------------------------------------------------------------------




// -----------------------------------------------------------------------------
/*
   readyイベント（windowから教えてもらえるイベント）
	Null photoController.onReady()
*/
PhotoController.prototype.onReady = function() {
}
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
/*
   prevメソッド
	Null photoController.prev()
*/
PhotoController.prototype.prev = function() {
	this.nowIs = (this.nowIs == 0) ? this.length-1: (this.nowIs-1)%this.length;
	this.image.changeTo(this.nowIs);

	this.changePhotoLinkHREF(this.nowIs);
	this.changeCaption(this.nowIs);
}
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
/*
   nextメソッド
	Null photoController.next()
*/
PhotoController.prototype.next = function() {
	this.nowIs = (this.nowIs+1)%this.length;
	this.image.changeTo(this.nowIs);

	this.changePhotoLinkHREF(this.nowIs);	
	this.changeCaption(this.nowIs);
}
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
/*
   changePhotoLinkHREFメソッド
	Null photoController.changePhotoLinkHREF( index )
	
	Number index - nowIs
*/
PhotoController.prototype.changePhotoLinkHREF = function( index ) {
	if(this.link_element != null) {
		this.link_element.href = this.photos[index].replace(/\./i, "_large.");
	}
}
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
/*
   changeCaptionメソッド
	Null photoController.changeCaption( index )
	
	Number index - nowIs
*/
PhotoController.prototype.changeCaption = function( index ) {
	if(this.caption_element != null) {
		if(typeof this.caption_element.innerHTML != "undefined") {
			this.caption_element.innerHTML = this.captions[index];
		}
		/*
		else {
			var textNode = document.createTextNode(this.captions[index]);

			if(this.caption_element.childNodes.length > 0) {
				this.caption_element.replaceChild(textNode, this.caption_element.childNodes[0]);
			}
			else {
				this.caption_element.appendChild(textNode);
			}
		}
		*/
	}
}
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
/*
   インスタンス化
*/
var photoController = new PhotoController();
// -----------------------------------------------------------------------------



// -----------------------------------------------------------------------------
/*
   windowさんにイベントを教えてもらえるようにする。
*/
//window.addListener(photoController);
// -----------------------------------------------------------------------------
}
