(function($) {
    // ロールオーバー
    $.fn.roll = function(s0, s1) {
        return this.each(function() {
            if (!this.src) return;
            var s = [];
            s[0] = s0 || '_off';
            s[1] = s1 || '_on';
            $(this).hover(
                function() {this.src = this.src.replace(s[0], s[1])},
                function() {this.src = this.src.replace(s[1], s[0])}
            );
        });
    }
    // 背景色ロールオーバー
    /*
        siblingsがtrueのときは、自分がhover時に兄弟要素もロールオーバーする（テーブル行毎にロールオーバーするときなど）
    */
    $.fn.rollBgColor  = function(after, before, siblings) {
        if (!after) return this;
        return this.each(function() {
            var self   = $(this);
            var target = (!siblings) ? self : self.siblings().andSelf();
            var before = before || self.css('background-color');
            self.hover(
                function(){target.css('background-color', after)},
                function(){target.css('background-color', before)}
            );
        });
    }
})(jQuery);


if (typeof NXT1 == 'undefined') NXT1 = {};

//新着
NXT1.News = {};
NXT1.News.setup = function(entries) {
    var entries = entries || $('#news .accordion_toggle');

    if (entries.length == 0) return;
    return entries.click(function() {
        var self = $(this).find('.accordion_content:first');
        if(self.css('display') == 'block') {
            self.hide('slow');
        } else {
            self.show('slow');
        }
    });
}

// フロアマップ
NXT1.Floormap = {};
NXT1.Floormap.setup = function(shops) {
    var shops = shops || $('#floormap .shops li').not('.noshop');

    if (shops.length == 0) return;
    shops.click(function() {
        var url = $(this).find('a').attr('href');
        document.location.href = url;
    });
}

// ショップリスト
NXT1.Shoplist = {};
NXT1.Shoplist.setup = function(shops) {
    var shops = shops || $('#shoplist .shopgroup li');

    if (shops.length == 0) return;
    shops.click(function() {
        var url = $(this).find('a').attr('href');
        document.location.href = url;
    });
}

// 各ショップ
NXT1.Shop = {};
NXT1.Shop.setup = function(shops) {
    var shops = shops || $('#shop .shop_navi li');

    if (shops.length == 0) return;
    shops.click(function() {
//      $(this).find('a').trigger("click");
        var url = $(this).find('a').attr('href');
        document.location.href = url;
    });
}

NXT1.setup = function() {
    // 各要素に振る舞いを設定
    NXT1.News.setup();
    NXT1.Floormap.setup();
    NXT1.Shoplist.setup();
//  NXT1.Shop.setup();
}

// DOM構築後に実行
$(function() {
    NXT1.setup();

    $('#news').find('.accordion_content').not(':first').css('display','none');
    $('#floormap').find('.shops li').not('.noshop').rollBgColor('#f0f0f0', null).css('cursor','pointer');
    $('#shoplist').find('.shopgroup li').rollBgColor('#f0f0f0', null).css('cursor','pointer');
    $('#shop').find('.shop_navi li').rollBgColor('#f0f0f0', null).css('cursor','pointer');
    $('img[src *= _off], input[type = image][src *= _off]').roll();

    setTimeout("fareAnimation()",3000);

});

    var rev = false;
    function fareAnimation() {
        $('#shop').find('.side .fare').each(function() {
            var pos;
            if(rev == false) {
                pos = '-=240px';
                rev = true;
            } else {
                pos = '+=240px';
                rev = false;
            }
            $(this).animate({backgroundPosition: pos}, 1500 );
            setTimeout("fareAnimation()",4500);
        });
    }
