//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//		Copyright (C) 2004 Hiroshi Shibata.
//------------------------------------------------------------
//	全部または一部をコピー、転載、その他の無断使用を禁じます。
//------------------------------------------------------------
//	● グローバル ●
var gRobj = this;
//	● 定数 ●
var intervalTime = 50;
//____________________________________________________________



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	初期化
//____________________________________________________________

function init()
{
	//< 初期化 >----------
	this.anime = new Array();
	this.count = 0;
	this.timer = setInterval("intervalCall()", intervalTime);
	//< /初期化 >---------
}
//____________________________________________________________



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	インターバル・コール
//____________________________________________________________

function intervalCall()
{
	for (var i=0; i<this.count; i++) {
		this.anime[i].loop();
	}
}
//____________________________________________________________










//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	フェードイン
//____________________________________________________________

function fadeIn(
	id, data
){
	this.id = id;
	if (data) {
		this.data = data;
		this.dispFrm = data.dispFrm;
		this.fadeFrm = data.fadeFrm;
	} else {
		this.dispFrm = 0;
		this.fadeFrm = 30;
	}
	this.loop = fadeInInit;

	//登録
	gRobj.anime[gRobj.count++] = this;
}

function fadeInInit()
{
	this.timer = this.dispFrm;
	this.loop = fadeInWait;
}

function fadeInWait()
{
	if (!this.timer) {
		this.opacity = 0;
		this.pitch = 100 / this.fadeFrm;
		this.loop = fadeInFade;
	} else this.timer--;
}

function fadeInFade()
{
	this.opacity += this.pitch;
	if (this.opacity < 100) {
		this.id.filters[0].opacity = this.opacity;
		this.id.style.MozOpacity = this.opacity;
	} else {
		this.opacity = 100;
		this.id.filters[0].opacity = this.opacity;
		this.id.style.MozOpacity = this.opacity;
		this.loop = fadeInNop;
	}
}

function fadeInNop()
{
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	アニメーション制御
//____________________________________________________________

function imgAnime(
	id, data
){
	this.id = id;
	if (data) {
		switch (data.mode) {
			case 'html':
				this.loop = htmlAnimeInit;
				break;
			case 'img':
			default:
				this.loop = imgAnimeInit
				break;
		}
		this.data = data;
		this.dispFrm = data.dispFrm;
		this.fadeFrm = data.fadeFrm;
	} else {
		this.dispFrm = 300;
		this.fadeFrm = 30;
		this.loop = imgAnimeInit;
	}

	if (id.length) {
		var files = id[0].id+'Files';
		this.files = window[files];
	}

	//登録
	gRobj.anime[gRobj.count++] = this;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	HTML
//____________________________________________________________

function htmlAnimeInit()
{
	this.num = this.id.length;
	if (1<this.num) {
		this.no = this.num-1;
		for (var i=0; i<this.no; i++) {
			this.id[i].style.visibility = 'hidden';
		}
		this.timer = this.dispFrm;
		this.loop = htmlAnimeWait;
	}
}
function htmlAnimeWait()
{
	if (!this.timer) {
		this.lastNo = this.no;
		this.no--;
		if (this.no < 0) this.no = this.num-1;
		this.opacity = 0;
		this.pitch = 100 / this.fadeFrm;
		this.id[this.no].filters[0].opacity = this.opacity;
		this.id[this.no].style.MozOpacity = this.opacity;
		this.id[this.no].style.visibility = 'visible';
		this.id[this.no].style.zIndex = 1;
		this.loop = htmlAnimeFade;
	} else this.timer--;
}
function htmlAnimeFade()
{
	this.opacity += this.pitch;
	if (this.opacity < 100) {
		this.id[this.no].filters[0].opacity = this.opacity;
		this.id[this.no].style.MozOpacity = this.opacity;
	} else {
		this.opacity = 100;
		this.id[this.no].filters[0].opacity = this.opacity;
		this.id[this.no].style.MozOpacity = this.opacity;
		this.id[this.lastNo].style.visibility = 'hidden';
		this.id[this.no].style.zIndex = 0;

		this.timer = this.dispFrm;
		this.loop = htmlAnimeWait;
	}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//	IMG
//____________________________________________________________

function imgAnimeInit()
{
	if (this.files) {
		this.num = this.files.length;
		this.no = 0;
		this.side = 1;
		this.timer = this.dispFrm;
		this.loop = imgAnimeWait;
	}
}
function imgAnimeWait()
{
	if (!this.timer) {
		this.lastNo = this.no;
		this.no++;
		if (this.num <= this.no) this.no = 0;
		this.side ^= 1;
		this.opacity = 0;
		this.pitch = 100 / this.fadeFrm;
		this.id[this.side].filters[0].opacity = this.opacity;
		this.id[this.side].style.MozOpacity = this.opacity;
		this.id[this.side].style.visibility = 'visible';
		this.id[this.side].style.zIndex = 1;
		this.loop = imgAnimeLoadCK;
	} else this.timer--;
}
function imgAnimeLoadCK()
{
	if (this.id[this.side].readyState=='complete') {
		this.loop = imgAnimeFade;
	}
}
function imgAnimeFade()
{
	this.opacity += this.pitch;
	if (this.opacity < 100) {
		this.id[this.side].filters[0].opacity = this.opacity;
		this.id[this.side].style.MozOpacity = this.opacity;
	} else {
		this.opacity = 100;
		this.id[this.side].filters[0].opacity = this.opacity;
		this.id[this.side].style.MozOpacity = this.opacity;
		this.id[this.side^1].style.visibility = 'hidden';
		this.id[this.side].style.zIndex = 0;
		var no = this.no+1;
		if (this.num <= no) no = 0;
		this.id[this.side^1].src = this.files[no];

		this.timer = this.dispFrm;
		this.loop = imgAnimeWait;
	}
}
//____________________________________________________________
