var gAction = "false";	// アクションフラグ
var gAction2 = "false";	// アクションフラグ
var myTim = 0;	// インターバル
var myTim2 = 0;	// インターバル

var thumImg = new Thumbnails();	// イメージ配列
var thumImg2 = new ThumbnailsEx();	// イメージ配列
// thumImg.add('ID', 'リンク先URL', 'ALTテキスト');
// ID         : HTMLコードライト画像のname属性
// リンク先URL: クリック時のリンク先
// ALTテキスト: alt="ここに入る"
thumImg.add('topslide01', 'sp1.html', '');
thumImg.add('topslide02', 'girls_date.html', '');
thumImg.add('topslide03', 'sp2.html', '');
thumImg.add('topslide04', 'sp3.html', '');

thumImg2.add('topslide05', 'shop.html', '');
thumImg2.add('topslide06', 'shop.html', '');
thumImg2.add('topslide07', 'shop.html', '');
thumImg2.add('topslide08', 'shop.html', '');
thumImg2.add('topslide09', 'shop.html', '');
thumImg2.add('topslide10', 'shop.html', '');
thumImg2.add('topslide11', 'shop.html', '');
thumImg2.add('topslide12', 'shop.html', '');
thumImg2.add('topslide13', 'shop.html', '');
thumImg2.add('topslide14', 'shop.html', '');

var gPreLoadList = new Array("images/topslide01_ov.jpg",
                             "images/topslide02_ov.jpg",
                             "images/topslide03_ov.jpg",
                             "images/topslide04_ov.jpg"
                            );

var gPreLoadList2 = new Array("images/topslide05_ov.jpg",
                              "images/topslide06_ov.jpg",
                              "images/topslide07_ov.jpg",
                              "images/topslide08_ov.jpg",
                              "images/topslide09_ov.jpg",
                              "images/topslide10_ov.jpg",
                              "images/topslide11_ov.jpg",
                              "images/topslide12_ov.jpg",
                              "images/topslide13_ov.jpg",
                              "images/topslide14_ov.jpg"
                            );

function Thumbnail(iid, url, alt)
{
    this.iid = iid;
    this.url = url;
    this.alt = alt;
}

function ThumbnailEx(iid, url, alt)
{
    this.iid = iid;
    this.url = url;
    this.alt = alt;
}

function Thumbnails()
{
    this.item = new Array();
    this.add  = _addThum;
}

function ThumbnailsEx()
{
    this.item = new Array();
    this.add  = _addThumEx;
}

function _addThum(iid, url, alt)
{
    var b = new Thumbnail(iid, url, alt);
    this.item[this.item.length] = b;
}

function _addThumEx(iid, url, alt)
{
    var b = new ThumbnailEx(iid, url, alt);
    this.item[this.item.length] = b;
}

function changeImage(imageObj)
{
    if (gAction == "true") {
        for (i = 0; i < thumImg.item.length; i ++) {
            if (imageObj.name == thumImg.item[i].iid) {
                document.getElementById('recoLnk').href  = thumImg.item[i].url;
                document.images['recoImg'].src           = "images/" + thumImg.item[i].iid + ".png";
                document.images[thumImg.item[i].iid].src = "images/" + thumImg.item[i].iid + "_ov.jpg";
                count = i;
            } else {
                document.images[thumImg.item[i].iid].src = "images/" + thumImg.item[i].iid + ".jpg";
            }
        }
        clearInterval(myTim);
    }
}

function changeImageEx(imageObj)
{
    if (gAction2 == "true") {
        for (i = 0; i < thumImg2.item.length; i ++) {
            if (imageObj.name == thumImg2.item[i].iid) {
                document.getElementById('recoLnk2').href  = thumImg2.item[i].url;
                document.images['recoImg2'].src           = "images/" + thumImg2.item[i].iid + ".png";
                document.images[thumImg2.item[i].iid].src = "images/" + thumImg2.item[i].iid + "_ov.jpg";
                count = i;
            } else {
                document.images[thumImg2.item[i].iid].src = "images/" + thumImg2.item[i].iid + ".jpg";
            }
        }
        clearInterval(myTim2);
    }
}

// 3秒ごとに画像を切り替える処理
function changeImg()
{
    onImages = new Array();

    for (field in gPreLoadList) {
        onImages[field]     = new Image();
        onImages[field].src = gPreLoadList[field];
    }
    gAction = "true";
    myTim   = setInterval('changeImg2()', 2000);	// 2秒ごと
}

function changeImgEx()
{
    onImages2 = new Array();

    for (field in gPreLoadList2) {
        onImages2[field]     = new Image();
        onImages2[field].src = gPreLoadList2[field];
    }
    gAction2 = "true";
    myTim2   = setInterval('changeImg2Ex()', 2000);	// 2秒ごと
}

count = 0;
function changeImg2()
{
    if (gAction == "true") {
        count ++;
        count %= 4;
        num = count;
        for (i = 0; i < thumImg.item.length; i ++) {
            //alert(thumImg.item[i].iid);
            document.images[thumImg.item[i].iid].src = "images/" + thumImg.item[i].iid + ".jpg";
        }
        document.getElementById('recoLnk').href    = thumImg.item[num].url;
        document.images['recoImg'].src             = "images/" + thumImg.item[num].iid + ".png";
        document.images[thumImg.item[num].iid].src = "images/" + thumImg.item[num].iid + "_ov.jpg";
    }
}

count2 = 0;
function changeImg2Ex()
{
    if (gAction2 == "true") {
        count2 ++;
        count2 %= 10;
        num = count2;
        for (i = 0; i < thumImg2.item.length; i ++) {
            //alert(thumImg2.item[i].iid);
            document.images[thumImg2.item[i].iid].src = "images/" + thumImg2.item[i].iid + ".jpg";
        }
        document.getElementById('recoLnk2').href    = thumImg2.item[num].url;
        document.images['recoImg2'].src             = "images/" + thumImg2.item[num].iid + ".png";
        document.images[thumImg2.item[num].iid].src = "images/" + thumImg2.item[num].iid + "_ov.jpg";
    }
}

// オンマウス時に画像の切り替えを停止する
function changeImg3()
{
    clearInterval (myTim);
}

// オンマウス時に画像の切り替えを停止する
function changeImg3Ex()
{
    clearInterval (myTim2);
}

window.onload = function(){
    changeImg();
    changeImgEx();
}
