(function () {
  "use strict";

  var IS_LOCAL  = /(:\/\/localhost|file:\/\/)/.test(document.location.href);

  require.config({
      waitSeconds :   (IS_LOCAL? 10 : 45)
    , paths: {

      // requireJs
        app:            '../js/app'
      , polyfill:       '../js/polyfill'
      , overrides:      '../js/overrides'
      , almond:         '../js/libs/require/almond'
      , text:           '../js/libs/require/text'
      , css:            '../js/plugins/require-css/require-css'
      , normalize:      '../js/plugins/require-css/normalize'
      , json:           '../js/plugins/requirejs-plugins/json'

      // plugins/libs
      , jquery:         '../js/libs/jquery/jquery'
      , jqm:            '../js/libs/jquery-mobile/jquery-mobile'
      , i18next:        '../js/plugins/i18next/i18next'
      , renderjs:       '../js/plugins/renderjs/renderjs'
      , modernizr:      '../js/plugins/modernizr'
      , selectivzr:     '../js/plugins/selectivzr'
      , jio:            '../js/libs/jio/jio'
      , md5:            '../js/libs/jio/md5'
      , localstorage:   '../js/libs/jio/localstorage'
      , indexstorage:   '../js/libs/jio/indexstorage'
      , complex_queries:'../js/libs/jio/complex_queries'
      , validval:       '../js/plugins/validval/validval'

      // page gadgets
      , address:          '../modules/address/address'
      , basket:           '../modules/basket/basket'
      , browser:          '../modules/browser/browser'
      , confirm:          '../modules/confirm/confirm'
      , description:      '../modules/description/description'
      , details:          '../modules/details/details'
      , footer:           '../modules/footer/footer'
      , gallery:          '../modules/gallery/gallery'
      , header:           '../modules/header/header'
      , index:            '../modules/index/index'
      , item:             '../modules/item/item'
      , items:            '../modules/items/items'
      , login:            '../modules/login/login'
      , media:            '../modules/media/media'
      , payment:          '../modules/payment/payment'
      , refine:           '../modules/refine/refine'
      , register:         '../modules/register/register'
      , search:           '../modules/search/search'
      , searchbar:        '../modules/searchbar/searchbar'
      , seo:              '../modules/seo/seo'
      , shipment:         '../modules/shipment/shipment'
      , sorting:          '../modules/sorting/sorting'
      , storage:          '../modules/storage/storage'
      , summary:          '../modules/summary/summary'
      , teaser:           '../modules/teaser/teaser'
      , terms:            '../modules/terms/terms'
      , translate:        '../modules/translate/translate'
      , pageheader:       '../modules/pageheader/pageheader'
      , pagefooter:       '../modules/pagefooter/pagefooter'
    }
    , shim: {
        'overrides':        { deps: ['jquery'] }
      , 'jqm':              { deps: ['jquery'], exports: 'mobile' }
      , 'jio':              { deps: ['md5'] }
      , 'complex_queries':  { exports: 'complex_queries' }
      , 'localstorage':     { deps: ['jio', 'complex_queries'] }
      , 'indexstorage':     { deps: ['jio'] }
      , 'renderjs':         { deps: ['jquery'], exports: 'RenderJs' }
      , 'app':              { deps: ['jio'], exports: 'App' }
      , 'validval':         { deps: ['jquery'] }
    }
    , map: {
      '*': {
        'css': '../js/plugins/require-css/css'
      }
    }
  });

define(
    [
        'require'
      , 'overrides'
      , 'jquery'
      , 'jqm'
      , 'jio'
      , 'polyfill'
      , 'text'
      , 'json'
      , 'renderjs'
      , 'i18next'
      , 'localstorage'
      //, 'indexstorage'
      , 'complex_queries'
      , 'md5'
      , 'css!../css/jquery-mobile/jquery-mobile.latest'
      , 'css!../css/css'
      , 'css!../css/normalize/normalize'
    ],
  function (require) {
    require(['app', 'storage'], function(App, Storage) {

      App.initialize();

      // expose App
      window.App = App;

      // attach storage
      window.App.storage = Storage;
    });
  }
);
}());