var opaCnt=8;		//透明／不透明化係数
var opaTimer=25;	//透明／不透明化間隔
var ssTimer=3000;	//スライドショーの画像切り替え間隔（3秒）

function imgFade(){
	//先出し画像
	imgPre=new Array();//画像ファイル名、リンク、画像名、フォントカラー
	imgPre[0]={image:"mitui_outlet01.jpg",url:"http://bus.keifuku.co.jp/kasikiri/liner/",name:"滋賀竜王アウトレットライナー",color:"#FFF",target:""};
	imgPre[1]={image:"mitui_outlet02.jpg",url:"http://bus.keifuku.co.jp/kasikiri/liner/",name:"滋賀竜王アウトレットライナー",color:"#FFF",target:""};
	imgPre[2]={image:"katufuku.jpg",url:"http://www.kaland.co.jp/katsufuku/index.html",name:"京福バス直営「祇園八咫 かつふく」",color:"#111",target:"blank"};
	imgPre[3]={image:"hw_bus_top.gif",url:"",name:"高速バス",color:"#111",target:""};
	imgPre[4]={image:"hw_bus_tokyo.jpg",url:"http://bus.keifuku.co.jp/hw/tokyo.shtml",name:"高速バス　東京線",color:"#EEE",target:""};
	imgPre[5]={image:"hw_bus_nagoya.jpg",url:"http://bus.keifuku.co.jp/hw/nagoya.shtml",name:"高速バス　名古屋線",color:"#EEE",target:""}
	imgPre[6]={image:"hw_bus_osaka.jpg",url:"http://bus.keifuku.co.jp/hw/osaka.shtml",name:"高速バス　大阪線",color:"#EEE",target:""};

	images=new Array();//画像ファイル名、リンク、画像名、フォントカラー
	images[0]={image:"kocyoumon.jpg",url:"",name:"越前海岸　呼鳥門付近",color:"#EEE",target:""};
	images[1]={image:"bus2011model.jpg",url:"http://bus.keifuku.co.jp/rosen/",name:"2011年度　ノンステップバス新造車両を国と福井県の補助を受けて導入しました。",color:"#EEE",target:"blank"};
	images[2]={image:"eiheiji_liner.jpg",url:"http://bus.keifuku.co.jp/hw/eiheiji.shtml",name:"福井駅東口の永平寺ライナーバス",color:"#EEE",target:""};
	images[3]={image:"araiso.jpg",url:"",name:"東尋坊　荒磯遊歩道付近",color:"#EEE",target:""};
	images[4]={image:"sakura_nhk.jpg",url:"",name:"さくら通りNHK前",color:"#EEE",target:""};
	images[5]={image:"umitobus.jpg",url:"",name:"海岸線を走るバス",color:"#EEE",target:""};
	images[6]={image:"kasikiri.jpg",url:"http://bus.keifuku.co.jp/kasikiri/",name:"貸切バス車両",color:"#EEE",target:""};
	images[7]={image:"winter01.jpg",url:"",name:"下新橋〜高田橋間",color:"#EEE",target:""};
	//images[0]={image:"asakuraiseki.jpg",url:"",name:"朝倉氏遺跡",color:"#FFF",target:""};
	//images[3]={image:"maruokajyo.jpg",url:"",name:"日本の桜名所百選　丸岡城",color:"#EEE",target:""};
	//images[4]={image:"toujinbousunset.jpg",url:"",name:"日本の夕日百選　東尋坊",color:"#EEE",target:""};
	//images[4]={image:"oonoteramati.jpg",url:"",name:"大野寺町通り",color:"#333"};
	//images[6]={image:"toujinboutobus.jpg",url:"",name:"東尋坊松林とバス"};
	images.shuffle(); //先に順番をシャッフルして決めておく
	
	images = imgPre.concat(images);
	for(var i=0;i<images.length;i++){ //画像のプレロード
		var buf=new Image();
		buf.src='slideshowimg/'+images[i].image;
	}
	curimg=0; //今の画像のインデックス
	showImage(curimg);
}


Array.prototype.shuffle=function(){ //Arrayオブジェクトにshuffle メソッドを追加
	var i = this.length;
	while(i){
		var j = Math.floor(Math.random()*i);
		var t = this[--i];
		this[i] = this[j];
		this[j] = t;
	}
	return this;
}

function nextImage(){
	if (++curimg>=images.length) curimg=0;
	showImage(curimg);
}

function showImage(index){
	opa=100;	//不透明度　Max100で不透明
	FadeStr(opa,index);
	document.getElementById("lnk").href="";
	document.getElementById("imgname").innerHTML="";
}

var flg=1;		//フェイドアウト進行中は1、フェイドイン進行中は0
function FadeStr(opa,index) {
	fadeId = "slideshow";
	//fadeId = "main";
	MyImg = document.getElementById(fadeId);
	MyImg.style.visibility = "visible";
	if (flg) FadeOut(opa,index); else FadeIn(opa,index);
}
var timerID01, timerID02, timerID03;
function FadeOut(opa,index) {
	if(opa <= 0) {
		flg=0;	//画像が消えたら、flg=0にして、フェイドインに切り替える。
		//document.getElementById(fadeId).src='slideshowimg/'+images[index].image;
		MyImg.style.backgroundImage = 'url(slideshowimg/' + images[index].image + ')';
	}else{
		MyImg.style.filter = "alpha(opacity:"+opa+")";
		MyImg.style.opacity = opa/100;
		opa -= opaCnt;
	}
	clearTimeout(timerID01);
	timerID01 = setTimeout("FadeStr("+opa+","+ index +")", opaTimer);
}
function FadeIn(opa,index) {
	if (opa <= 100) {
		MyImg.style.filter = "alpha(opacity:"+opa+")";
		MyImg.style.opacity = opa/100;
		opa += opaCnt;
		clearTimeout(timerID02);
		timerID02 = setTimeout("FadeStr("+opa+","+ index +")", opaTimer);
	}else{
		flg=1;
		clearTimeout(timerID03);
		timerID03 = setTimeout(nextImage,ssTimer);//指定秒数ごとに次の画像へ
		if(images[index].url == ""){
			document.getElementById("lnk").removeAttribute('href');
		} else {
			document.getElementById("lnk").href=images[index].url;
		}
		if(images[index].target == ""){
			document.getElementById("lnk").removeAttribute('class');
		} else {
			document.getElementById("lnk").className=images[index].target;
		}
		//alert(images[index].target);
		//alert(document.getElementById("lnk").className);
		document.getElementById("imgname").innerHTML=images[index].name;
		document.getElementById("imgname").style.color=images[index].color;
	}
}
