if (typeof MOECO != "object") MOECO = {};
MOECO.TOP = {
	// 初期設定
	imgs : ["images/index/mainimg2.jpg", "images/index/mainimg3.jpg"], // 画像のURL
	timer : 2500, // 変化までの時間（単位：ミリ秒）
	target : "mainimg" // 画像のID
};

// 画像の先読み
(function() {
	for (var i = 0; i < MOECO.TOP.imgs.length; i++) {
		newImg = [];
		newImg[i] = new Image();
		newImg[i].src = MOECO.TOP.imgs[i];
	}
})();

// Windowオンロード時に実行する
MOECO.TOP.init = function() {
	MOECO.TOP.target = document.getElementById(MOECO.TOP.target);
	if (typeof MOECO.TOP.target == "object") {
		MOECO.TOP.setTimer();
	}
}
// 汎用関数：イベントの追加
if (typeof MOECO.addEvent == "undefined") {
	MOECO.addEvent = function(obj, type, fn) {
		if(obj.addEventListener) {
			obj.addEventListener(type, fn, false);
		} else if(obj.attachEvent) {
			obj.attachEvent("on" + type, fn);
		}
	}
}
MOECO.addEvent(window, "load", MOECO.TOP.init);

// タイマーをセットする
MOECO.TOP.setTimer = function() {
	var changeImg = new MOECO.TOP.changeImg();
	MOECO.TOP.timer = setInterval(changeImg, MOECO.TOP.timer);
}

// 画像を変更する
MOECO.TOP.changeImg = function() {
	var i = 0;
	return function() {
		if(i < MOECO.TOP.imgs.length) {
			MOECO.TOP.target.src = MOECO.TOP.imgs[i];
			i++;
		} else {
			clearInterval(MOECO.TOP.timer);
		}
	}
}
