﻿var ads = null;
var currentIndex = null;
/**
* 広告初期化処理
*/
function adsInit(adsId) {
    // 複数の広告を含む広告枠
    var obj = $(adsId);
    
    if (obj) {
        // クラス名 ad で広告オブジェクトを検索
        ads = obj.getElementsByClassName("ad");
        
        // 最初のバナー以外を隠す
        for (i=1; i<ads.length; i++) {
            ads[i].hide();
        }
        currentIndex = 0;
    }
    
    // 広告枠を表示（非表示クラスを解除）
    obj.className = "";
}
/**
* ローテーション初期化処理
*/
function rotationInit() {
    setInterval(rotation, 5000);
}
/**
* ローテーション
*/
function rotation() {
    // 表示中の広告を隠す
    ads[currentIndex].hide();
    
    currentIndex++;
    if (currentIndex >= ads.length) {
        currentIndex = 0;
    }
    
    // 次の広告を表示
    ads[currentIndex].show();
}
/**
* ページ初期化処理
*/
function pageInit() {
adsInit("ads");
rotationInit();
}

Event.observe(window, "load", pageInit);


