(function ($, window, document, undefined) {

    $.perrier = $.perrier || {};

    var jsdir;

    jsdir = $.perrier.jsdir = (function () {

        var scripts = document.getElementsByTagName('script'),
            i = 0,
            l = scripts.length,
            dir,
            dir;

        for (; i < l; i++) {
            var exec = /(.+\/)(loader\.js?)$/.exec(scripts[i].src);
            exec && (dir = exec[1]);
        }
        return dir;
    })();

    Modernizr.load([{
        /*
         * 全てのページで使う内容
         */
        load: [
            jsdir + 'base.js'
        ]
    }, {
        /*
         * トップページ以外で使う内容
         */
        test: /\/about\/($|index.html$)/.test(location.pathname)
        || /\/ad\/($|index.html$)/.test(location.pathname)
        || /\/product\/($|index.html$)/.test(location.pathname)
        || /\/life\/mixology\/(|index.html)/.test(location.pathname)
        || /\/special\/($|index.html$)/.test(location.pathname),
        yep: [
            jsdir + 'lib/jquery.ba-throttle-debounce.js'
            ,jsdir + 'module/parallaxBubble/parallaxBubble.js'
            ,jsdir + 'jquery.uaScroll.js'
        ],
        callback: function (url, result, key) {
            /jquery\.uaScroll\.js$/.test(url) && $('a[href="#header"]').uaScroll({
                duration: 2000,
                useHash: false
            });
        }
    }, {
        /*
         * トップページ以外且つ、Canvas が利用可能であれば
         * Canvas を使った泡アニメーション効果を呼び出します
         */
        test: (
            /\/about\/($|index.html$)/.test(location.pathname)
            || /\/ad\/($|index.html$)/.test(location.pathname)
            || /\/product\/($|index.html$)/.test(location.pathname)
            || /\/life\/mixology\/(|index.html)/.test(location.pathname)
            || /\/special\/($|index.html$)/.test(location.pathname)
        )
        && !!document.createElement('canvas').getContext,
        yep: jsdir + 'module/bubbleGenerator/bubbleGenerator.js'
    }, {
        /*
         * About ページで使う内容
         */
        test: /\/about\/($|index.html$)/.test(location.pathname),
        yep: jsdir + 'module/page_about/page_about.js'
    }, {
        /**
         * Ad ページで使う内容
         */
        test: /\/ad\/($|index.html$)/.test(location.pathname),
        yep: jsdir + 'module/page_ad/page_ad.js'
    }, {
        /*
         * Product ページで使う内容
         */
        test: /\/product\/($|index.html$)/.test(location.pathname),
        yep: jsdir + 'module/page_product/page_product.js'
    }, {
        /*
         * Mixology ページで使う内容
         */
        test: /\/life\/mixology\/(|index.html)/.test(location.pathname),
        yep: jsdir + 'module/page_life-mixology/page_life-mixology.js'
    }, {
       /*
        * Special ページで使う内容
        */
        test: /\/special\/($|index.html$)/.test(location.pathname),
        yep: [
          jsdir + 'module/page_special/page_special.js'
          ,jsdir + 'lib/mustache.js' // Google Map のフキダシをテンプレート化するのに利用
        ]
    }, {
        test: !!($.browser.msie && $.browser.version < 7),
        yep: jsdir + 'module/supportOpacity/supportOpacity.js'
    }]);
})(jQuery, this, this.document);

