
// ---------- 画像切り替え ----------
var imageLength = 0;
var now = 0;
var pre = 0;
var count = 0;

jQuery(function($){
	
	var startNum;
	
	startNum = Math.floor(Math.random() * 4);
	
	//画像の枚数取得
	imageLength = $("#mainvisual div").length;
	
	//初期画像表示
	$("#mainvisual div").eq(startNum).css("display", "block");
	
	//タイマースタート
	now = startNum;
	count = startNum;
	if(imageLength != 1){
		var timer = setInterval("changeImage()",5000); 
	}
});

function changeImage(){
	pre = now;
	count++;
	now = count % imageLength;
	$("#mainvisual div").eq(now).css("z-index", 100+count);
	$("#mainvisual div").eq(now).fadeIn(1000,
		function(){
			$("#mainvisual div").eq(pre).css("display", "none");
		}
	);
}
