// メニューをhoverしたときの処理
function controlToparea(){
    // ターゲットの取得
    var elems = $('#toparea');
    if(elems.length < 1){ return; }
    // TOPバナーの再生
    if(!topbanners) return false;
    topbannerModel.init(topbanners);
    topbannerModel.play();

    // 生徒画像の再生
    if(!multiblocks) return false;
    studentImageModel.init(multiblocks[0]);
    studentImageModel.play();

    // 雰囲気画像の再生
    atmosphereImageModel.init(multiblocks[1]);
    for(i=1; i<= 6 ; i++){
        atmosphereImageModel.play(i);
    }	
}

var topbannerModel = {

    id : 0,

    list : [],

    init : function(data) { this.list = data; },
    
    play: function() {
	var max = topbannerModel.list.length;
	topbannerModel.id = ( topbannerModel.id + 1  < max ) ? topbannerModel.id + 1 : 0;
	var img = topbannerModel.list[topbannerModel.id];
	$('#toparea #bannerblock .photo img').fadeOut(500, function(){
	    $('#toparea #bannerblock .photo img').attr('src', img);
	    $('#toparea #bannerblock .photo img').fadeIn(2000);
	});
	var tid = setTimeout(topbannerModel.play,20000);
    }

};


var studentImageModel = {

    // 現在のid
    id : 0,

    // topimage一覧
    list : [],

    init : function(data) { this.list = data; },
    
    // 繰り返し再生
    play: function() {
	var max = studentImageModel.list.length;
	studentImageModel.id = ( studentImageModel.id + 1 < max ) ? studentImageModel.id + 1 : 0;
	var image = studentImageModel.list[studentImageModel.id];
	$('#toparea #studentblock div').fadeOut(1000, function(){
	    $('#toparea #studentblock div').replaceWith(image);
	    $('#toparea #studentblock div').fadeIn(2000);
	});
	var tid = setTimeout(studentImageModel.play,5000);
    }
    
};

var atmosphereImageModel = {

    list : [],

    max  : 0,

    id   : 0,

    init : function(data) { 
	this.list = data; 
	this.max = this.list.length;
    },
    
    play : function(num) {
	var time = 2500 + 300 * (Math.floor(Math.random()*10));
	atmosphereImageModel.changeImage(num, time);
	var tid = setTimeout('atmosphereImageModel.play(' + num + ')', time * 2 + 5000);
    },

    changeImage : function(num, time) {
	atmosphereImageModel.id = ( atmosphereImageModel.id + 1 < atmosphereImageModel.max ) ? atmosphereImageModel.id + 1 : 0;
	//var image_number = Math.floor(Math.random() * atmosphereImageModel.list.length);
	var image = atmosphereImageModel.list[atmosphereImageModel.id];
	$('#toparea #atmosphereblocks #multi-' + num + ' div').fadeOut(time, function(){
	    $('#toparea #atmosphereblocks #multi-' + num + ' div').replaceWith(image);
	    $('#toparea #atmosphereblocks #multi-' + num + ' div').fadeIn(time);
	})
    }

};

