/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Webfont loader -- https://github.com/typekit/webfontloader
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

/* WebFontConfig object which contains all of our vendor (Google, typkit, fonts.com, fontdeck), state and other configuration options */
WebFontConfig = {
/*~~~Typekit~~~*/
// Typekit's own JavaScript is built using this Web Font Loader library and already provides
// all of the same font event functionality. If you're using Typekit ALONE, you should use their embed
// codes directly unless you also need to load web fonts from other providers on the same page.
// <script type="text/javascript" src="https://use.typekit.com/xxxxxxx.js"></script>
    typekit: {
        id: 'fnt5wtm'
    },

/*~~~Google~~~*/
// https://developers.google.com/fonts/docs/getting_started
// use the same string construction syntax as if called via http request
// i.e. 'Libre Baskerville:400,700,400italic'
    // google: {
    //     families: [
    //         'Josefin Slab:400,500',
    //         'Open Sans:300,400,700'
    //     ]
        // optional text subset examples (use UTF-8 characters http://www.utf8-chartable.de)
        // , text: 'abcdedfghijklmopqrstuvwxyzABCDEDFGHIJKLMOPQRSTUVWXYZ'
        // , text: 'World\'sideeb' //(World's Wide Web)
        // optional text effects! https://developers.google.com/fonts/docs/getting_started#Effects
        // , effects : [
        //     '3d',
        //     'vintage'
        // ]
    // },

/*~~~Custom (FontAwesome, etc)~~~*/
    // if more than one webfont is used, these key:values are mapped to the array index or default to first
    custom: {
        families: [
            'FontAwesome'
            //, 'localFont'
        ],
        urls: [
            '//maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css'
            //, '/styles/screen.css'
        ],
        testStrings : {
            'FontAwesome' : '\uf083\uf015'
        }
    },

/*~~~Timeout~~~*/
// in Milliseconds - defaults to 3000 (3 seconds)
    timeout: 2000,

/*~~~Classes~~~*/
// if classes: false, disables wf- classes on HTML element -- defaults to true
    // classes: false,

/*~~~Events~~~*/
// if events: false, disables callback font events -- defaults to true
// if BOTH classes and events are disabled, Font Loader will not perform font watching and only acts as a way to inser @font-face rules into document
    // events: false,

/*~~~Events - Callback functions~~~*/
    loading: function() {
        if (window.console) {
            console.log('[_fontloader.js] All fonts loading');
        }
    },
    active: function() {
        if (window.console) {
            console.log('[_fontloader.js] All fonts active');
        }
        if ('google' in WebFontConfig) {
            if ('effects' in WebFontConfig['google']) {
                var gf   = document.querySelector('link[href*="fonts.googleapis.com"]'),
                    href = gf.getAttribute('href'),
                    fx   = WebFontConfig['google']['effects'].join('|');
                gf.getAttributeNode('href').value = href + '&effect=' + fx;
                if (window.console) {
                    console.log('[_fontloader.js] google font effects loaded');
                }
                document.querySelector('html').classList.add('wf-gfx-loaded');
            }
        }
    },
    inactive: function() {
        if (window.console) {
            console.log('[_fontloader.js] A font is inactive');
        }
    },
    fontloading: function(familyName, fvd) {
        if (window.console) {
            console.log('[_fontloader.js] Font: "' + familyName + '" (' + fvd + ') is loading');
        }
    },
    fontactive: function(familyName, fvd) {
        if (window.console) {
            console.log('[_fontloader.js] Font: "' + familyName + '" (' + fvd + ') is loaded');
        }
        document.querySelector('html').classList.remove('wf-' + familyName.toLowerCase().replace(' ', '').replace('-', '') + '-' + fvd + '-active');
    },
    fontinactive: function(familyName, fvd) {
        if (window.console) {
            console.log('[_fontloader.js] Font: "' + familyName + '" (' + fvd + ') didn\'t load');
        }
    }

};

(function(d) {
    var wf = d.createElement('script'), s = d.scripts[0];
    wf.src = 'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
    s.parentNode.insertBefore(wf, s);
})(document);
