//基本設定
var headerImgBoxName = "headerImgBox";//ヘッダーイメージボックス名
var headerImgName = "headerImg"; //ヘッダーイメージ名
var browsSeconds = 8;//イメージがステイしている時間（秒）
var opacityGrade = 5;//フェードの段階（100まで）
var imgOpacity = 100;
var imgNum = 0;
var photos = new Array(
	"http://songbird.cc/wp-content/uploads/image/1.jpg",
	"http://songbird.cc/wp-content/uploads/image/2.jpg",
	"http://songbird.cc/wp-content/uploads/image/3.jpg",
	"http://songbird.cc/wp-content/uploads/image/4.jpg",
	"http://songbird.cc/wp-content/uploads/image/5.jpg",
	"http://songbird.cc/wp-content/uploads/image/6.jpg",
	"http://songbird.cc/wp-content/uploads/image/7.jpg",
	"http://songbird.cc/wp-content/uploads/image/8.jpg",
	"http://songbird.cc/wp-content/uploads/image/9.jpg",
	"http://songbird.cc/wp-content/uploads/image/10.jpg",
	"http://songbird.cc/wp-content/uploads/image/11.jpg",
	"http://songbird.cc/wp-content/uploads/image/12.jpg",
	"http://songbird.cc/wp-content/uploads/image/13.jpg",
	"http://songbird.cc/wp-content/uploads/image/14.jpg",
	"http://songbird.cc/wp-content/uploads/image/15.jpg",
	"http://songbird.cc/wp-content/uploads/image/16.jpg",
	"http://songbird.cc/wp-content/uploads/image/17.jpg"
);

//配列のランダム入れ替え
function changeArray(list){
  var i = list.length;
  while (--i) {
    var j = Math.floor(Math.random() * (i + 1));
    if (i == j) continue;
    var k = list[i];
    list[i] = list[j];
    list[j] = k;
  }
  return list;
}

//最初のイメージを決定
function headerRotate() {
	changeArray(photos);
	document.write('<a href="http://songbird.cc/news/" title="Photo Gallery"><img id="headerImg" width="600" height="489" alt="Photo Gallery" src="' +photos[imgNum] + '" /></a>');
}

//ヘッダーイメージアニメーション
function headerAnimation() {
	var imgObj = document.getElementById(headerImgName);
	document.getElementById(headerImgBoxName).style.backgroundImage = 'url(' + photos[imgNum] + ')';
	imgFade();
}

//フェード
function imgFade() {
	var imgObj = document.getElementById(headerImgName);
	if (imgOpacity <= opacityGrade) {//フェード外
		imgOpacity = 100;
		imgSelect();
		setTimeout("imgFade()",browsSeconds*1000);
	}else{//フェード中
		imgOpacity -= opacityGrade;
		setOpacity(imgObj,imgOpacity);
		setTimeout("imgFade()",50);
	}
}

//次イメージ選択
function imgSelect() {
	var divObj = document.getElementById(headerImgBoxName);
	var imgObj = document.getElementById(headerImgName);
	imgObj.src = photos[imgNum];
	setOpacity(imgObj,100);
	if(imgNum == photos.length-1){
		imgNum = 0;
	}else{
		imgNum++;
	}
	divObj.style.backgroundImage = 'url(' + photos[imgNum] + ')';
}

//不透明度設定
function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?100:opacity;
	obj.style.filter = "alpha(opacity:"+opacity+")";	
	obj.style.KHTMLOpacity = opacity/100;
	obj.style.MozOpacity = opacity/100;
	obj.style.opacity = opacity/100;
}

window.onload = headerAnimation; 
