// メニューをhoverしたときの処理
function controlGCAward(){
    var elems = $('#page.gcaward2010 #main .item');
    if(elems.length < 1){ return; }
    topModel.init(elems);
    topModel.play();
}

// データモデル
var topModel = {

    index : 0,

    maxwidth : 1000,

    able : [[0,0],[190,0],[380,0],[570,0]],

    // topimage一覧
    list : [],

    init : function(data) { this.list = data; },
    
    // 繰り返し再生
    play: function() {
// 	this.setBannerblock();
// 	this.setNewsblock();
	var top;
	var left;
	var position;
	for(i=0; i < this.list.length; i++){
	    var item = $('#' + this.list[i].id);
	    var height = item.outerHeight();
	    var width = item.outerWidth();
	    if( width <= 190 ){
		this.setMinIndex();
		leftpos = this.able[this.index][0];
		toppos  = this.able[this.index][1];
		item.css({'position':'absolute','left': leftpos, 'top': toppos});
		this.able[this.index][1] = toppos + height;
	    } else if( width <= 380 ){
		this.setMaxIndex();
		if(this.index >= 4){
		    this.able[3][1] = this.able[this.index][1];
		    this.index = 3;
		}
		leftpos = this.able[this.index][0];
		toppos  = this.able[this.index][1];
		item.css({'position':'absolute','left': leftpos, 'top': toppos});
		this.able[this.index][1] = toppos + height;
		this.able[this.index + 1][1] = toppos + height;
	    } else if( width <= 570 ){
		this.setMaxIndex();
		if(this.index >= 3){
		    this.able[2][1] = this.able[this.index][1];
		    this.index = 2;
		}
		leftpos = this.able[this.index][0];
		toppos  = this.able[this.index][1];
		item.css({'position':'absolute','left': leftpos, 'top': toppos});
		this.able[this.index][1] = toppos + height;
		this.able[this.index + 1][1] = toppos + height;
		this.able[this.index + 2][1] = toppos + height;
	    } else if( width <= 760 ){
		this.setMaxIndex();
		if(this.index >= 2){
		    this.able[1][1] = this.able[this.index][1];
		    this.index = 1;
		}
		leftpos = this.able[this.index][0];
		toppos  = this.able[this.index][1];
		item.css({'position':'absolute','left': leftpos, 'top': toppos});
		this.able[this.index][1] = toppos + height;
		this.able[this.index+1][1] = toppos + height;
 		this.able[this.index+2][1] = toppos + height;
 		this.able[this.index+3][1] = toppos + height;
	    } else {
		this.setMaxIndex();
		if(this.index >= 1){
		    this.able[0][1] = this.able[this.index][1];
		    this.index = 0;
		}
		leftpos = this.able[this.index][0];
		toppos  = this.able[this.index][1];
		item.css({'position':'absolute','left': leftpos, 'top': toppos});
		this.able[this.index][1] = toppos + height;
		this.able[this.index+1][1] = toppos + height;
		this.able[this.index+2][1] = toppos + height;
 		this.able[this.index+3][1] = toppos + height;
 		this.able[this.index+4][1] = toppos + height;
	    }
	}
	$('#twittercommentblock').css({'height' : this.getMaxHeight()});
    },

    setBannerblock: function(){
	var height = $('#bannerblock').outerHeight();
	for(var i=0; i < 3; i++){
	    this.able[i][1] = height;
	}
    },

    setNewsblock: function(){
	var height = $('#newsblock').outerHeight();
	for(var i=0; i < 2; i++){
	    this.able[i][1] += height;
	}
    },

    setMinIndex: function(){
	this.index = 0;
	var ymin = this.able[0][1];
	for(var i=0; i < this.able.length; i++){
	    if( ymin > this.able[i][1] ) { 
		ymin = this.able[i][1];
		this.index = i; 
	    }
	}
    },

    setMaxIndex: function(){
	this.index = 0;
	var ymax = this.able[0][1];
	for(var i=0; i < this.able.length; i++){
	    if( ymax < this.able[i][1] ) { 
		ymax = this.able[i][1];
		this.index = i; 
	    }
	}
    },

    getMaxHeight: function(){
	var maxheight = this.able[0][1];
	for(var i=0; i < this.able.length; i++){
	    if( maxheight < this.able[i][1] ) { 
		maxheight = this.able[i][1];
	    }
	}
	return maxheight;
    }

    
    
    
};


