if (typeof(QLifePet) == 'undefined') {
    var QLifePet = {};
}

QLifePet.Kandou = {
    /**
     * PeriodicalExecuterオブジェクト(prototype.js)
     */
    exec : null,
    /**
     * ローテーション開始
     */
    startRotation : function(){
        if (QLifePet.Kandou.exec == null) {
	        // [ref] PeriodicalExecuter ... prototype.js
	        QLifePet.Kandou.exec = new PeriodicalExecuter(function(){ QLifePet.Kandou.rotateKuchikomi(); }, 4);
        }
    },
    /**
     * 現在表示している感動口コミインデックス (1-6)
     */
    currentIndex : 0,
    /**
     * 感動口コミローテーションの切り替え
     */
    rotateKuchikomi : function(){
        var nextIndex = (QLifePet.Kandou.currentIndex % 6) + 1;
        QLifePet.Kandou.switchBalloon(QLifePet.Kandou.currentIndex, nextIndex);
    },
    /**
     * 表示する口コミの切り替え
     *
     * @param int disableIndex 無効にするアバターインデックス(0-6)
     * @param int enableIndex 有効にするアバターインデックス(0-6)
     */
    switchBalloon : function(disableIndex, enableIndex){
        // [ref] $$() ... prototype.js
        var spans = $$('div#fukidashi div.balloon p');
        // [ref] Element.setStyle() ... prototype.js
        Element.setStyle(spans[disableIndex], {display : 'none'});
        Element.setStyle(spans[enableIndex], {display : ''});
        // 表示中の口コミインデックスを更新
        QLifePet.Kandou.currentIndex = enableIndex;
        // ふきだし画像を変更
        $$('div#fukidashi img#fukidashi_kuchi')[0].src = '/pet/images/rotation/fukidashi_kuchi' + enableIndex + '.png';
    },
    /**
     * ローテーションを中断、指定アバターの口コミを表示
     *
     * @param avatarIndex 有効にするアバターインデックス
     */
    mouseOver : function(avatarIndex){
	    // ローテーションを中断
	    if (QLifePet.Kandou.exec != null) {
		    QLifePet.Kandou.exec.stop();
		    QLifePet.Kandou.exec = null;
	    }
        QLifePet.Kandou.switchBalloon(QLifePet.Kandou.currentIndex, avatarIndex);
    }
};

QLifePet.Common.addOnload(
    function(){
        // 感動口コミローテーション開始
//        // [ref] PeriodicalExecuter ... prototype.js
//        QLifePet.Kandou.exec = new PeriodicalExecuter(function(){ QLifePet.Kandou.rotateKuchikomi(); }, 4);
		QLifePet.Kandou.startRotation();
    }
);

