

// --------------------シナリオ設定仕様-------------------------
var divid = 'chgimg';								// imgタグを内包する divタグのidを設定します。(divタグにはcssを設定してください width height )
var imgId = 'mPic';									// imgタグの id要素に記した名前を記入
var scenerys = Array(4);							// シナリオ数を設定
scenerys[0] = new Scenery('./topanime/Kogo-Top1.jpg',2000,5000,0);	// シナリオを記入(imgファイル名,トランジッションタイム,ステイタイム,後処理（0=ネクスト 1=トップ 2=終了)
scenerys[1] = new Scenery('./topanime/Kogo-Top2.jpg',2000,5000,0);
scenerys[2] = new Scenery('./topanime/Kogo-Top3.jpg',2000,5000,0);
scenerys[3] = new Scenery('./topanime/Kogo-Top4.jpg',2000,5000,2);
// -------------------------------------------------------------




// グローバル変数
var loopCount = 0;
var imgStatus = 0;	// 0=ネクスト　1=トランジッション 2=ステイ
var alphaLevel = 0;
var stayCount = 0;
var newObj;
var timerID;

function startTransission(){
	// 操作オブジェクトの作成
	var obj=document.getElementById(imgId);
	newObj=obj.cloneNode(true);
	newObj.style.zIndex=1;
	newObj.id = "alphaloop";
	// 位置合わせ
	newObj.style.position = 'relative';
	newObj.style.top = "-" + (obj.height) + "px";
	
	document.getElementById('chgimg').appendChild(newObj);


	// タイマースタート 分解能 0.1秒
	timerID = setInterval('transissionImages()',100);
}


// イメージ交換
function transissionImages() {
	if (imgStatus == 0){
		newObj.src = scenerys[loopCount].fileName;
		imgStatus = 1;
	}
	if (imgStatus == 1){
		// アルファの計算
		alphaLevel = alphaLevel + (1 / ((scenerys[loopCount].transTime / 100)));
		if (alphaLevel >= 1)
		{
			alphaLevel = 1;
			imgStatus = 2;
			stayCount = 0;
		}
		alphaBlend();
	}
	if (imgStatus == 2){
		if (scenerys[loopCount].stayTime <= stayCount)
		{
			// 画像入れ替え
			document.getElementById(imgId).src = newObj.src;
			alphaLevel = 0;
			imgStatus = 0;
			stayCount = 0;
			alphaBlend();
			if (scenerys[loopCount].nextStep == 2)
			{
				clearInterval(timerID);
				document.getElementById('alphaloop').remove;
			}
			if (scenerys[loopCount].nextStep == 1)
			{
				loopCount = 0;
			}
			if (scenerys[loopCount].nextStep == 0)
			{
				loopCount ++;
			}
		}
		else
		{
			stayCount = stayCount + (scenerys[loopCount].stayTime / 100)
		}
	}
}

// アルファブレンド
function alphaBlend()
{
	newObj.style.filter = "alpha(opacity=" + (alphaLevel*100) + ")";	// 0～100 IE
	newObj.style.opacity = alphaLevel;								// 0～1
}


// シナリオオブジェクト
function Scenery(fileName, transTime,stayTime,nextStep) {
	this.fileName = fileName;
	this.transTime = transTime;
	this.stayTime = stayTime;
	this.nextStep = nextStep;
}

