var interval = 9000;////
var intervalDefault = 9000;////

var aryG;
var id = null;//
var idr = null;//
var cnt = 0;
var n = 0;//

var group01;
var group02;
var group03;
var group04;
var group05;
var group06;

//
//
var naviLayerObj;
var btn1_objimg;
var btn2_objimg;
var objimg;

function init(){

	//
	//window.alert(swfobject.getFlashPlayerVersion().major);
	//
	if(swfobject.getFlashPlayerVersion().major > 0){
		return false;
	}

	//index
	group01 = new setimgs("images/top/nf/nf_01.jpg","images/top/nf/nf_02.jpg","images/top/nf/index.jpg","images/top/nf/index.jpg");

	//story1
	group02 = new setimgs("images/top/nf/st01_01.jpg","images/top/nf/st01_02.jpg","images/top/nf/st01_03.jpg","images/top/nf/st01_04.jpg","images/top/nf/st01_05.jpg","images/top/nf/st01_06.jpg","images/top/nf/st01_07.jpg","images/top/nf/st01_08.jpg","images/top/nf/st01_08.jpg","images/top/nf/st01_09.jpg","images/top/nf/st01_10.jpg","images/top/nf/st01_11.jpg","images/top/nf/st01_12.jpg","images/top/nf/st01_13.jpg","images/top/nf/st01_14.jpg","images/top/nf/st01_14.jpg","images/top/nf/st01_14.jpg","images/top/nf/st01_15.jpg","images/top/nf/st01_16.jpg","images/top/nf/st01_16.jpg");

	//story2
	group03 = new setimgs("images/top/nf/st02_01.jpg","images/top/nf/st02_02.jpg","images/top/nf/st02_03.jpg","images/top/nf/st02_04.jpg","images/top/nf/st02_05.jpg","images/top/nf/st02_06.jpg","images/top/nf/st02_07.jpg","images/top/nf/st02_08.jpg","images/top/nf/st02_09.jpg","images/top/nf/st02_10.jpg","images/top/nf/st02_11.jpg","images/top/nf/st02_12.jpg","images/top/nf/st02_13.jpg","images/top/nf/st02_14.jpg","images/top/nf/st02_14.jpg","images/top/nf/st02_15.jpg","images/top/nf/st02_16.jpg","images/top/nf/st02_16.jpg","images/top/nf/st02_17.jpg","images/top/nf/st02_18.jpg","images/top/nf/st02_18.jpg","images/top/nf/st02_18.jpg","images/top/nf/st02_19.jpg","images/top/nf/st02_20.jpg","images/top/nf/st02_20.jpg","images/top/nf/st02_20.jpg","images/top/nf/st02_21.jpg","images/top/nf/st02_22.jpg","images/top/nf/st02_22.jpg");

	//story3
	group04 = new setimgs("images/top/nf/st03_01.jpg","images/top/nf/st03_02.jpg","images/top/nf/st03_03.jpg","images/top/nf/st03_04.jpg","images/top/nf/st03_04.jpg","images/top/nf/st03_05.jpg","images/top/nf/st03_06.jpg","images/top/nf/st03_07.jpg","images/top/nf/st03_07.jpg","images/top/nf/st03_08.jpg","images/top/nf/st03_09.jpg","images/top/nf/st03_10.jpg","images/top/nf/st03_11.jpg","images/top/nf/st03_11.jpg");

	//story4
	group05 = new setimgs("images/top/nf/st04_01.jpg","images/top/nf/st04_02.jpg","images/top/nf/st04_03.jpg","images/top/nf/st04_04.jpg","images/top/nf/st04_05.jpg","images/top/nf/st04_05.jpg","images/top/nf/st04_05.jpg","images/top/nf/st04_06.jpg","images/top/nf/st04_07.jpg","images/top/nf/st04_07.jpg","images/top/nf/st04_08.jpg","images/top/nf/st04_09.jpg","images/top/nf/st04_09.jpg","images/top/nf/st04_10.jpg","images/top/nf/st04_10.jpg","images/top/nf/st04_11.jpg","images/top/nf/st04_12.jpg","images/top/nf/st04_13.jpg","images/top/nf/st04_13.jpg","images/top/nf/st04_14.jpg","images/top/nf/st04_15.jpg","images/top/nf/st04_15.jpg");

	//story5
	group06 = new setimgs("images/top/nf/st05_01.jpg","images/top/nf/st05_02.jpg","images/top/nf/st05_03.jpg","images/top/nf/st05_04.jpg","images/top/nf/st05_05.jpg","images/top/nf/st05_06.jpg","images/top/nf/st05_07.jpg","images/top/nf/st05_08.jpg","images/top/nf/st05_09.jpg","images/top/nf/st05_10.jpg","images/top/nf/st05_11.jpg","images/top/nf/st05_11.jpg","images/top/nf/st05_12.jpg","images/top/nf/st05_13.jpg","images/top/nf/st05_14.jpg","images/top/nf/st05_15.jpg","images/top/nf/st05_16.jpg","images/top/nf/st05_16.jpg");

	//story6
	group07 = new setimgs("images/top/nf/st06_01.jpg","images/top/nf/st06_02.jpg","images/top/nf/st06_03.jpg","images/top/nf/st06_04.jpg","images/top/nf/st06_05.jpg","images/top/nf/st06_06.jpg","images/top/nf/st06_07.jpg","images/top/nf/st06_08.jpg","images/top/nf/st06_08.jpg","images/top/nf/st06_09.jpg","images/top/nf/st06_09.jpg","images/top/nf/st06_10.jpg","images/top/nf/st06_11.jpg","images/top/nf/st06_11.jpg","images/top/nf/st06_12.jpg","images/top/nf/st06_13.jpg","images/top/nf/st06_13.jpg");


	//BTN1
	group01.btn1_linkpath = "";
	group01.btn1_target = "";
	group02.btn1_linkpath = "";
	group02.btn1_target = "";
	group03.btn1_linkpath = "";
	group03.btn1_target = "";
	group04.btn1_linkpath = "";
	group04.btn1_target = "_blank";	
	group05.btn1_linkpath = "http://www.yamatake.com/products/bi/ba/index.html";
	group05.btn1_target = "";
	group06.btn1_linkpath = "";
	group06.btn1_target = "_blank";	
	group07.btn1_linkpath = "";
	group07.btn1_target = "_blank";

	//BTN2
	group01.btn2_linkpath = "";
	group01.btn2_target = "";
	group02.btn2_linkpath = "";
	group02.btn2_target = "";
	group03.btn2_linkpath = "";
	group03.btn2_target = "";
	group04.btn2_linkpath = "http://www.yamatake.com/products/bi/ba/index.html";
	group04.btn2_target = "_blank";	
	group05.btn2_linkpath = "";
	group05.btn2_target = "_blank";
	group06.btn2_linkpath = "http://www.yamatake.com/products/bi/iap/products/product_18.html";
	group06.btn2_target = "_blank";
	group07.btn2_linkpath = "";
	group07.btn2_target = "";

	aryG = new Array(group01, group02, group03, group04, group05, group06, group07);

	//
	mgr();

	//
	btn1_objimg = document.getElementById("linkBtn1");
	btn2_objimg = document.getElementById("linkBtn2");
	btn1_objimg.src = "images/top/nf/linkbtn_01.gif";
	btn2_objimg.src = "images/top/nf/linkbtn_02.gif";

	//
	var naviBtn0_objimg = document.getElementById("bt_00");
	var naviBtn1_objimg = document.getElementById("bt_01");
	var naviBtn2_objimg = document.getElementById("bt_02");
	var naviBtn3_objimg = document.getElementById("bt_03");
	var naviBtn4_objimg = document.getElementById("bt_04");
	var naviBtn5_objimg = document.getElementById("bt_05");
	var naviBtn6_objimg = document.getElementById("bt_06");
	naviBtn0_objimg.src = "images/top/nf/btn_00.gif";
	naviBtn1_objimg.src = "images/top/nf/btn_01.gif";
	naviBtn2_objimg.src = "images/top/nf/btn_02.gif";
	naviBtn3_objimg.src = "images/top/nf/btn_03.gif";
	naviBtn4_objimg.src = "images/top/nf/btn_04.gif";
	naviBtn5_objimg.src = "images/top/nf/btn_05.gif";
	naviBtn6_objimg.src = "images/top/nf/btn_06.gif";

}

//
var setimgs = function(){

	//
	this.ary = [];
	for(var i=0; i<arguments.length;i++){
		this.ary.push(arguments[i]);
	}
	this.showed = false;

	//
	//
	//
	this.start = function(i){

		//interval = 3500;/////

		if(id){
			clearTimeout(id);
			id = null;
		}

		//IMAGE
		objimg = document.getElementById("image_change");
		//
		btn1_objimg = document.getElementById("linkBtn1");
		btn2_objimg = document.getElementById("linkBtn2");
		//
		naviLayerObj = document.getElementById("naviLayer");

		//
		//block:displayAnone:non-display
		btn1_objimg.style.display = "none";
		btn2_objimg.style.display = "none";

		//
		objimg.src = this.ary[i];

		if(i==this.ary.length-2){
			//window.alert(i);
			interval = 300;/////
		}
		if(i==this.ary.length-1){
			//window.alert(i);
			interval = intervalDefault;/////
		}

		i++;

		//
		if(i==this.ary.length){
			//interval = 3500;/////

			//
			this.showed = true;

			//
			if(this.btn1_linkpath){
				//
				btn1_objimg.style.display = "block";
				//
				btn1_objimg.parentNode.href = this.btn1_linkpath;
				//
				if(this.btn1_target){
					btn1_objimg.parentNode.target = this.target;
				}else{
					btn1_objimg.parentNode.target = "_self";
				}
			}

			//
			if(this.btn2_linkpath){
				//
				btn2_objimg.style.display = "block";
				//
				btn2_objimg.parentNode.href = this.btn2_linkpath;
				//
				if(this.btn2_target){
					btn2_objimg.parentNode.target = this.target;
				}else{
					btn2_objimg.parentNode.target = "_self";
				}
			}

			//naviLayer
			//
			if(naviLayerObj.style.display=="none"){
				naviLayerObj.style.display = "block";//
			}

			//
			//
			if(cnt<aryG.length){
				if(cnt==1){//
					idr = setTimeout(mgr,interval+2000);
				}else{
					//
					return false;
				}
			}

			//
			return false;

		}

		//
		id = setTimeout(this.start.bind(this,i), interval);

	}
}

//
//
//
function mgr(){	

	var ary = [];
	cnt++;

	//
	naviLayerObj = document.getElementById("naviLayer");

	//
	if(cnt==1){
		//naviLayer
		naviLayerObj.style.display = "none";//
		n = 0;//idx
		aryG[0].start(0);
		return false;
	}

	//
	naviLayerObj.style.display = "block";//
	for(i=0; i<aryG.length; i++){
		if(!aryG[i].showed)
			ary.push(aryG[i]);
	}
	if(ary.length > 0){
		var idx = Math.floor(Math.random() * ary.length);
		n = idx;
		ary[idx].start(0);
	}

}

//
//
//
function targetStart(idx){

	if(aryG.length <= idx){
		return;
	}

	if(idr){
//		window.alert(idr);
		clearTimeout(idr);
		idr = null;
	}
	if(id){
//		window.alert(id);
		clearTimeout(id);
		id = null;
	}

	//
	naviLayerObj = document.getElementById("naviLayer");

	//
	if(idx==0){
		//naviLayer
		naviLayerObj.style.display = "none";//
	}else{
		//naviLayer
		naviLayerObj.style.display = "block";//
	}

	cnt = aryG.length;
	aryG[idx].start(0);

}

Function.prototype.bind = function() {
	var __method = this, args = $A(arguments), object = args.shift();
	return function() {
		return __method.apply(object, args.concat($A(arguments)));
	}
}
function $A(iterable) {
 	var length = iterable.length, results = new Array(length);
 	while (length--) results[length] = iterable[length];
	return results;
}


if (window.attachEvent) {
	window.attachEvent("onload", init);
}
else if (window.addEventListener) {
	window.addEventListener("load", init, false);
}

