

// --------------------シナリオ設定仕様-------------------------
var divid = 'chgimg';								// imgタグを内包する divタグのidを設定します。(divタグにはcssを設定してください width height )
var imgId = 'mPic';									// imgタグの id要素に記した名前を記入
var scenerys = Array(37);							// シナリオ数を設定
scenerys[0] = new Scenery('./toppic/TV/TV01.jpg',1000,2000,0);	// シナリオを記入(imgファイル名,トランジッションタイム,ステイタイム,後処理（0=ネクスト 1=トップ 2=終了)
scenerys[1] = new Scenery('./toppic/TV/TV02.jpg',1000,2000,0);
scenerys[2] = new Scenery('./toppic/TV/TV03.jpg',1000,2000,0);
scenerys[3] = new Scenery('./toppic/TV/TV04.jpg',1000,2000,0);
scenerys[4] = new Scenery('./toppic/TV/TV05.jpg',1000,2000,0);
scenerys[5] = new Scenery('./toppic/TV/TV06.jpg',1000,2000,0);
scenerys[6] = new Scenery('./toppic/TV/TV07.jpg',1000,2000,0);
scenerys[7] = new Scenery('./toppic/TV/TV08.jpg',1000,2000,0);
scenerys[8] = new Scenery('./toppic/TV/TV09.jpg',1000,2000,0);
scenerys[9] = new Scenery('./toppic/TV/TV10.jpg',1000,2000,0);
scenerys[10] = new Scenery('./toppic/TV/TV11.jpg',1000,2000,0);
scenerys[11] = new Scenery('./toppic/TV/TV12.jpg',1000,2000,0);
scenerys[12] = new Scenery('./toppic/TV/TV13.jpg',1000,2000,0);
scenerys[13] = new Scenery('./toppic/TV/TV14.jpg',1000,2000,0);
scenerys[14] = new Scenery('./toppic/TV/TV15.jpg',1000,2000,0);
scenerys[15] = new Scenery('./toppic/TV/TV16.jpg',1000,2000,0);
scenerys[16] = new Scenery('./toppic/TV/TV17.jpg',1000,2000,0);
scenerys[17] = new Scenery('./toppic/TV/TV18.jpg',1000,2000,0);
scenerys[18] = new Scenery('./toppic/TV/TV19.jpg',1000,2000,0);
scenerys[19] = new Scenery('./toppic/TV/TV20.jpg',1000,2000,0);
scenerys[20] = new Scenery('./toppic/TV/TV21.jpg',1000,2000,0);
scenerys[21] = new Scenery('./toppic/TV/TV22.jpg',1000,2000,0);
scenerys[22] = new Scenery('./toppic/TV/TV23.jpg',1000,2000,0);
scenerys[23] = new Scenery('./toppic/TV/TV24.jpg',1000,2000,0);
scenerys[24] = new Scenery('./toppic/TV/TV25.jpg',1000,2000,0);
scenerys[25] = new Scenery('./toppic/TV/TV26.jpg',1000,2000,0);
scenerys[26] = new Scenery('./toppic/TV/TV27.jpg',1000,2000,0);
scenerys[27] = new Scenery('./toppic/TV/TV28.jpg',1000,2000,0);
scenerys[28] = new Scenery('./toppic/TV/TV29.jpg',1000,2000,0);
scenerys[29] = new Scenery('./toppic/TV/TV30.jpg',1000,2000,0);
scenerys[30] = new Scenery('./toppic/TV/TV31.jpg',1000,2000,0);
scenerys[31] = new Scenery('./toppic/TV/TV32.jpg',1000,2000,0);
scenerys[32] = new Scenery('./toppic/TV/TV33.jpg',1000,2000,0);
scenerys[33] = new Scenery('./toppic/TV/TV34.jpg',1000,2000,0);
scenerys[34] = new Scenery('./toppic/TV/TV35.jpg',1000,2000,0);
scenerys[35] = new Scenery('./toppic/TV/TV36.jpg',1000,2000,0);
scenerys[36] = new Scenery('./toppic/TV/TV37.jpg',1000,2000,1);
// -------------------------------------------------------------




// グローバル変数
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;
			}else 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;
}

