$(function() {
    // 検索フォーム
    $('table#search-title a').click(function () {
        $("input[name='method']", "#search_form").val(this.href.substring(this.href.lastIndexOf('/')+1));
        $('table#search-title a img').each(function(){
            if (this.src.match(/^(.+)bt_([a-z]+)_on(\.gif)$/)) {
                this.src = RegExp.$1 + 'bt_' + RegExp.$2 + '_out' + RegExp.$3;
            }
        });
        var this_img = $('img', this);
        if (this_img.attr('src').match(/^(.+)bt_([a-z]+)_out(\.gif)$/)) {
            this_img.attr('src', RegExp.$1 + 'bt_' + RegExp.$2 + '_on' + RegExp.$3);
        }
        return false;
    });

    // タブ選択
    $('#tabheader_table a').mouseover(function () {
        var img = $('img', this);
        if (img.attr('id') == 'sel') return;
        if (img.attr('src').match(/^(.+)tab_([a-z]+)_out(\.gif)$/)) {
            img.attr('src', RegExp.$1 + 'tab_' + RegExp.$2 + '_on' + RegExp.$3);
        }
    });
    $('#tabheader_table a').mouseout(function () {
        var img = $('img', this);
        if (img.attr('id') == 'sel') return;
        if (img.attr('src').match(/^(.+)tab_([a-z]+)_on(\.gif)$/)) {
            img.attr('src', RegExp.$1 + 'tab_' + RegExp.$2 + '_out' + RegExp.$3);
        }
    });
    seltab('box', 'head', 2, 1);

    // ECNaviの設定上書き
    imgDirRanking = 'img/shop/';
});


// bpref = tab body prefix, hpref = tab header prefix
function seltab(bpref, hpref, id_max, selected) {
    for (i = 1; i <= id_max; i++) {
        if (!$('#' + bpref + i)) continue;
        if (i == selected) {
            $('#' + bpref + i).css('display', 'block');
            img = $('#' + hpref + i + ' a img');
            if (img.attr('src').match(/^(.+)tab_([a-z]+)_out(\.gif)$/)) {
                img.attr('src', RegExp.$1 + 'tab_' + RegExp.$2 + '_on' + RegExp.$3);
            }
            img.attr('id', 'sel');
        } else {
            $('#' + bpref + i).css('display', 'none');
            img = $('#' + hpref + i + ' a img');
            if (img.attr('src').match(/^(.+)tab_([a-z]+)_on(\.gif)$/)) {
                img.attr('src', RegExp.$1 + 'tab_' + RegExp.$2 + '_out' + RegExp.$3);
            }
            img.attr('id', '');
        }
    }
}
