// エンドレスにフェードエフェクト

// タイマーの起動
$(function () {
	  $("body").headerFadeStart(1000);
});


// タイマーでCSSの背景位置を切り替える
$.fn.headerFadeStart = function(timer) {
	// 処理中の配列番号
	var current_count = 0;
	
	// フェードイン処理
	function headerFadeInTextA() {
		$('div#one').fadeIn("slow");
	}
	function headerFadeInImgA1() {
		$('div#two').fadeIn("slow");
	}
	function headerFadeInImgA2() {
		$('div#three').fadeIn("slow");
	}
	function headerFadeInImgA3() {
		$('div#four').fadeIn("slow");
	}
	
	// フェードアウトA
	function headerFadeOutTextA() {
		$("div#one").fadeOut("slow");
		$('div#two').fadeOut("slow");
		$('div#three').fadeOut("slow");
		$('div#four').fadeOut("slow");
	}
	
	// フェードインB
	function headerFadeInTextB() {
		$("div#oneB").fadeIn("slow");
	}
	function headerFadeInImgB1() {
		$('div#twoB').fadeIn("slow");
	}
	function headerFadeInImgB2() {
		$('div#threeB').fadeIn("slow");
	}
	function headerFadeInImgB3() {
		$('div#fourB').fadeIn("slow");
	}
	
	// フェードアウトB
	function headerFadeOutTextB() {
		$("div#oneB").fadeOut("slow");
		$('div#twoB').fadeOut("slow");
		$('div#threeB').fadeOut("slow");
		$('div#fourB').fadeOut("slow");
	}
	
	// フェードインC
	function headerFadeInTextC() {
		$("div#oneC").fadeIn("slow");
	}
	function headerFadeInImgC1() {
		$('div#twoC').fadeIn("slow");
	}
	function headerFadeInImgC2() {
		$('div#threeC').fadeIn("slow");
	}
	function headerFadeInImgC3() {
		$('div#fourC').fadeIn("slow");
	}
	
	// フェードアウトC
	function headerFadeOutTextC() {
		$("div#oneC").fadeOut("slow");
		$('div#twoC').fadeOut("slow");
		$('div#threeC').fadeOut("slow");
		$('div#fourC').fadeOut("slow");
	}
	
	// フェードインD
	function headerFadeInTextD() {
		$("div#oneD").fadeIn("slow");
	}
	function headerFadeInImgD1() {
		$('div#twoD').fadeIn("slow");
	}
	function headerFadeInImgD2() {
		$('div#threeD').fadeIn("slow");
	}
	function headerFadeInImgD3() {
		$('div#fourD').fadeIn("slow");
	}
	
	// 全フェードアウト処理
	function headerFadeOut() {
		$('div#oneD').fadeOut("slow");
		$('div#twoD').fadeOut("slow");
		$('div#threeD').fadeOut("slow");
		$('div#fourD').fadeOut("slow");
	}
		
	// 起動時に処理を開始する
	$(function(){
		var tId = setInterval(function()
		{
			current_count++;
			// カウント数が既定値になったら全フェードイン
			if (current_count == 1) {
				headerFadeInTextA();
			}
			if (current_count == 2) {
				headerFadeInImgA1();
			}
			if (current_count == 3) {
				headerFadeInImgA2();
			}
			if (current_count == 4) {
				headerFadeInImgA3();
			}
			// カウント数が既定値になったらAフェードアウト
			if (current_count == 10) {
				headerFadeOutTextA();
			}
			// カウント数が既定値になったらBフェードイン
			if (current_count == 11) {
				headerFadeInTextB();
			}
			if (current_count == 12) {
				headerFadeInImgB1();
			}
			if (current_count == 13) {
				headerFadeInImgB2();
			}
			if (current_count == 14) {
				headerFadeInImgB3();
			}
			// カウント数が既定値になったらAフェードアウト
			if (current_count == 20) {
				headerFadeOutTextB();
			}
			// カウント数が既定値になったらBフェードイン
			if (current_count == 21) {
				headerFadeInTextC();
			}
			if (current_count == 22) {
				headerFadeInImgC1();
			}
			if (current_count == 23) {
				headerFadeInImgC2();
			}
			if (current_count == 24) {
				headerFadeInImgC3();
			}
			// カウント数が既定値になったらAフェードアウト
			if (current_count == 30) {
				headerFadeOutTextC();
			}
			// カウント数が既定値になったらBフェードイン
			if (current_count == 31) {
				headerFadeInTextD();
			}
			if (current_count == 32) {
				headerFadeInImgD1();
			}
			if (current_count == 33) {
				headerFadeInImgD2();
			}
			if (current_count == 34) {
				headerFadeInImgD3();
			}
			// カウント数が既定値になったら再度カウント開始
			if (current_count == 40) {
				headerFadeOut();
				current_count = 0;
			}
		}, timer);
	});
}
