/*==============================================================================
一言お知らせ JavaScript

$Id: TellWords.js,v 1.3 2004/10/11 08:19:56 okamura Exp $
Copyright (C) 2004 OKAMURA Yuji, All right reserved.
==============================================================================*/
function TellWords(id) {
	/*---- お知らせ ----*/
	this.m_NoticeString = new Array();

	/*---- 設定 ----*/
	// 表示部の ID 属性値
	if (id) {
		this.m_ID = id;
	}
	else {
		this.m_ID = 'TellWords';
	}
	// 切り替え間隔
	this.m_Interval = 5 * 1000;	// ms
	// 制御部の ID 属性値
	this.m_CtrlsID = this.m_ID+'Ctrls';
	// 巻き戻しボタン
	this.m_RewindCtrlID = this.m_ID+'RewindCtrl';	// ID 属性値
	this.m_RewindCtrlStr = '≪';					// 表示文字列
	this.m_RewindCtrlAK = '';						// アクセスキー
	this.m_RewindCtrlTitle = '巻き戻し';			// title 属性値
	// 前ボタン
	this.m_PrevCtrlID = this.m_ID+'PrevCtrl';		// ID 属性値
	this.m_PrevCtrlStr = '＜';						// 表示文字列
	this.m_PrevCtrlAK = '';							// アクセスキー
	this.m_PrevCtrlTitle = '前';					// title 属性値
	// 再生ボタン
	this.m_PlayCtrlID = this.m_ID+'PlayCtrl';		// ID 属性値
	this.m_PlayCtrlStr = '|>';						// 表示文字列(再生)
	this.m_PlayCtrlAK = '';							// アクセスキー
	this.m_PlayCtrlTitle = '再生';					// title 属性値(再生)
	// 停止ボタン
	this.m_StopCtrlID = this.m_ID+'StopCtrl';		// ID 属性値
	this.m_StopCtrlStr = '■';						// 表示文字列(停止)
	this.m_StopCtrlAK = '';							// アクセスキー
	this.m_StopCtrlTitle = '停止';					// title 属性値(停止)
	// 次ボタン
	this.m_NextCtrlID = this.m_ID+'NextCtrl';		// ID 属性値
	this.m_NextCtrlStr = '＞';						// 表示文字列
	this.m_NextCtrlAK = '';							// アクセスキー
	this.m_NextCtrlTitle = '次';					// title 属性値
	// 早送りボタン
	this.m_ForwardCtrlID = this.m_ID+'ForwardCtrl';	// ID 属性値
	this.m_ForwardCtrlStr = '≫';					// 表示文字列
	this.m_ForwardCtrlAK = '';						// アクセスキー
	this.m_ForwardCtrlTitle = '早送り';				// title 属性値

	/*---- 内部変数 ----*/
	this.m_CurrentCount = 0;	// 現在の行番号(0から)
	this,m_Timer = 0;			// タイマーID

	/*---- 内部関数 ----*/
	this.Refresh = function() {
		this.m_CurrentCount = (this.m_CurrentCount + 1) % this.m_NoticeString.length;
		document.getElementById(this.m_ID).innerHTML = this.m_NoticeString[this.m_CurrentCount];
	}

	this.GetThisCode = function() {
		return 'document.getElementById(\''+this.m_ID+'\').tellWords';
	}

	this.Html = function() {
		var	html = '';

		if (this.m_NoticeString.length > 0) {
			// 制御部
			if (this.m_CtrlsID) {
				html += '<div id="'+this.m_CtrlsID+'">';
				// 巻き戻しボタン
				if (this.m_RewindCtrlID && this.m_RewindCtrlStr) {
					html += '<input id="'+this.m_RewindCtrlID+'" type="button" value="'+this.m_RewindCtrlStr+'" onclick="'+this.GetThisCode()+'.RewindTellWords()" title="'+this.m_RewindCtrlTitle+'" ';
					if (this.m_RewindCtrlAK != '') {
						html += 'accesskey="'+this.m_RewindCtrlAK+'" ';
					}
					html += '/>';
				}
				// 前ボタン
				if (this.m_PrevCtrlID && this.m_PrevCtrlStr) {
					html += '<input id="'+this.m_PrevCtrlID+'" type="button" value="'+this.m_PrevCtrlStr+'" onclick="'+this.GetThisCode()+'.PrevTellWords()" title="'+this.m_PrevCtrlTitle+'" ';
					if (this.m_PrevCtrlAK != '') {
						html += 'accesskey="'+this.m_PrevCtrlAK+'" ';
					}
					html += '/>';
				}
				// 再生ボタン
				if (this.m_PlayCtrlID && this.m_PlayCtrlStr) {
					html += '<input id="'+this.m_PlayCtrlID+'" type="button" value="'+this.m_PlayCtrlStr+'" onclick="'+this.GetThisCode()+'.PlayTellWords()" title="'+this.m_PlayCtrlTitle+'" ';
					if (this.m_PlayCtrlAK != '') {
						html += 'accesskey="'+this.m_PlayCtrlAK+'" ';
					}
					if (this.m_Timer) {
						html += 'disabled="disabled" ';
					}
					html += '/>';
				}
				// 停止ボタン
				if (this.m_StopCtrlID && this.m_StopCtrlStr) {
					html += '<input id="'+this.m_StopCtrlID+'" type="button" value="'+this.m_StopCtrlStr+'" onclick="'+this.GetThisCode()+'.StopTellWords()" title="'+this.m_StopCtrlTitle+'" ';
					if (this.m_StopCtrlAK != '') {
						html += 'accesskey="'+this.m_StopCtrlAK+'" ';
					}
					if (!this.m_Timer) {
						html += 'disabled="disabled" ';
					}
					html += '/>';
				}
				// 次ボタン
				if (this.m_NextCtrlID && this.m_NextCtrlStr) {
					html += '<input id="'+this.m_NextCtrlID+'" type="button" value="'+this.m_NextCtrlStr+'" onclick="'+this.GetThisCode()+'.NextTellWords()" title="'+this.m_NextCtrlTitle+'" ';
					if (this.m_NextCtrlAK != '') {
						html += 'accesskey="'+this.m_NextCtrlAK+'" ';
					}
					html += '/>';
				}
				// 早送りボタン
				if (this.m_ForwardCtrlID && this.m_ForwardCtrlStr) {
					html += '<input id="'+this.m_ForwardCtrlID+'" type="button" value="'+this.m_ForwardCtrlStr+'" onclick="'+this.GetThisCode()+'.ForwardTellWords()" title="'+this.m_ForwardCtrlTitle+'" ';
					if (this.m_ForwardCtrlAK != '') {
						html += 'accesskey="'+this.m_ForwardCtrlAK+'" ';
					}
					html += '/>';
				}
				html += '</div>';
			}

			// 表示部
			html += '<div id="'+this.m_ID+'">';
			html += this.m_NoticeString[this.m_CurrentCount];
			html += '</div>';
		}

		return html;
	}

	/*---- インターフェース関数 ----*/
	this.StartTellWords = function() {
		if (this.m_NoticeString.length > 1 && !this.m_Timer) {
			var	ctrl;

			this.m_Timer = setInterval(this.GetThisCode()+'.NextTellWords()', this.m_Interval);
			ctrl = document.getElementById(this.m_PlayCtrlID);
			if (ctrl) ctrl.disabled = true;
			ctrl = document.getElementById(this.m_StopCtrlID);
			if (ctrl) ctrl.disabled = false;
		}
	}

	this.PlayTellWords = function() {
		this.NextTellWords();
		this.StartTellWords();
	}

	this.StopTellWords = function() {
		if (this.m_Timer) {
			var	ctrl;

			clearTimeout(this.m_Timer);
			this.m_Timer = 0;
			ctrl = document.getElementById(this.m_PlayCtrlID);
			if (ctrl) ctrl.disabled = false;
			ctrl = document.getElementById(this.m_StopCtrlID);
			if (ctrl) ctrl.disabled = true;
		}
	}

	this.NextTellWords = function() {
		if (this.m_NoticeString.length > 1) {
			this.m_CurrentCount = (this.m_CurrentCount + 1) % this.m_NoticeString.length;
			document.getElementById(this.m_ID).innerHTML = this.m_NoticeString[this.m_CurrentCount];
		}
	}

	this.PrevTellWords = function() {
		if (this.m_NoticeString.length > 1) {
			if (this.m_CurrentCount > 0) {
				this.m_CurrentCount = (this.m_CurrentCount - 1) % this.m_NoticeString.length;
			}
			else {
				this.m_CurrentCount = this.m_NoticeString.length - 1;
			}
			document.getElementById(this.m_ID).innerHTML = this.m_NoticeString[this.m_CurrentCount];
		}
	}

	this.RewindTellWords = function() {
		if (this.m_NoticeString.length > 1) {
			this.m_CurrentCount = 0;
			document.getElementById(this.m_ID).innerHTML = this.m_NoticeString[this.m_CurrentCount];
		}
	}

	this.ForwardTellWords = function() {
		if (this.m_NoticeString.length > 1) {
			this.m_CurrentCount = this.m_NoticeString.length - 1;
			document.getElementById(this.m_ID).innerHTML = this.m_NoticeString[this.m_CurrentCount];
		}
	}

	/*---- ユーザインターフェース関数 ----*/
	this.Write = function() {
		document.write(this.Html());
		document.getElementById(tellWords.m_ID).tellWords = this;
	}
}
