// 背景スライド ========================
//	Update 2010-09-09
//	Version 1.0.8
// =====================================

var image_count = 5;
var image_width = 1278;
var image_height = 852;
var image_mode = 1278;
var read_time = 500;
var show_time = 500;
var read_count = 1;
var bg_count = 0;

var readBackgroundImage = function() {
	bg_count++;
	var num = (read_count % image_count) + 1;

	var bg = document.createElement("div");
	bg.setAttribute("id", "background" + bg_count);
	bg.style.zIndex = -1;
	bg.style.position = "absolute";
	bg.style.left = 0;
	bg.style.top = 0;
	bg.style.width = image_width + "px";
	bg.style.height = image_height + "px";
	bg.style.overflow = "hidden";

	var link = document.createElement("a");
	link.setAttribute("href", "/");

	var image = document.createElement("img");
	image.setAttribute("src", "/images/" + image_mode + "/" + num + ".jpg");
	image.style.width = "100%";
	image.style.height = "100%";

	bg.appendChild(link);
	link.appendChild(image);
	document.getElementById("display").appendChild(bg);

	read_count++;
	setTimeout("showBackgroundImage()", show_time);
};

var showBackgroundImage = function() {
	if(read_count % image_count == 1) {
		location.href = "/";
	} else {
		document.getElementById("background" + bg_count).style.zIndex = 1;
		removeBackgroundImage();
		setTimeout("readBackgroundImage()", read_time);
	}
};

var removeBackgroundImage = function() {
	var cnt = bg_count - 1
	var pre = document.getElementById("background" + cnt);
	if(pre) {
		pre.style.zIndex = -1;
		document.getElementById("display").removeChild(pre);
	}
};

var startBackgroundImage = function() {
	if(!document.getElementById) return false;
	if(!document.getElementsByTagName) return false;
	loadImage(imageData);
	setTimeout("readBackgroundImage()", read_time);
	setDisplay();
	resizeDisplay();
};

var checkHeight = function() {
	var height = Math.max(document.body.clientHeight, document.documentElement.clientHeight);
	image_width = Math.floor(1.5 * height);
	image_height = height;
	if(height < 800) {
		image_mode = 1000;
	} else {
		image_mode = 1278;
	}
	document.getElementById("display").style.width = image_width + "px";
}

var setDisplay = function() {
	checkHeight();
	document.getElementById("background0").style.width = image_width + "px";
	document.getElementById("background0").style.height = image_height + "px";
}

var resizeDisplay = function() {
	checkHeight();
	var cnt = bg_count - 1;
	var pre = document.getElementById("background" + cnt);
	if(pre) {
		pre.style.width = image_width + "px";
		pre.style.height = image_height + "px";
	}
	var bg = document.getElementById("background" + bg_count);
	if(bg) {
		bg.style.width = image_width + "px";
		bg.style.height = image_height + "px";
	}
}

// 画像のプリロード ============================================================

var preImage = new Array();

var loadImage = function(imageData) {
	for(i = 0; i < imageData.length; i++) {
		preImage[i] = new Image();
		preImage[i].src = imageData[i];
	}
}

var imageData = new Array(
  "images/1000/1.jpg"
, "images/1000/2.jpg"
, "images/1000/3.jpg"
, "images/1000/4.jpg"
, "images/1000/5.jpg"
, "images/1278/1.jpg"
, "images/1278/2.jpg"
, "images/1278/3.jpg"
, "images/1278/4.jpg"
, "images/1278/5.jpg"
);


// onload ======================================================================

if(window.addEventListener) {
	window.addEventListener("load", startBackgroundImage, false);
} else if (window.attachEvent) {
	window.attachEvent("onload", startBackgroundImage);
}

