var Inneractive = {
    'loadScript' : function () {

        var body= document.getElementsByTagName('body')[0],
            script= document.createElement('script'),
            scope = angular.element(body).scope(),
            scripts = body.getElementsByTagName('script');

        for (var i = 0; i < scripts.length; i++) {
            if( scripts[i].src == "http://cdn2.inner-active.mobi/wv-js/iaAdTagInternal.min.js" ) {
                body.removeChild(scripts[i]);
            }
        }

        script.type = 'text/javascript';
        script.src = 'http://cdn2.inner-active.mobi/wv-js/iaAdTagInternal.min.js';
        body.appendChild(script);

        var timeout = window.setInterval(function(){

            if (undefined !== $('#iawrapper a').html() ) {

                var link = $('#iawrapper a'),
                    url = link.attr('href');

                link.click(function(e) {
                    e.preventDefault();
                    var body= document.getElementsByTagName('body')[0],
                        scope = angular.element(body).scope();
                    scope.openExternal(url);
                    scope.$apply();
                });

                link.removeAttr('href');
                clearInterval(timeout);
            }

        }, 10);

    },

    'initVars': function () {
        try {
            (function() {
                if (typeof ia === 'undefined') {
                    ia = {};
                }

                // CHANGE AD SETTINGS BELOW.
                // More details about the different parameters can be found here:
                // https://inneractive.jira.com/wiki/display/DevWiki/JavaScript+Ad+Tag#JavaScriptAdTag-RequestParameters
                ia.adSettings = {
                    APP_ID:'KickItAway_Futbal_other',
                    IS_MOBILE_WEB: true,
                    IS_ORMMA_SUPPORT: false,
                    IS_MRAID_SUPPORT: false,
                    IS_VIDEO_SUPPORT : false,
                    IS_INTERSTITIAL_AD: false,
                    IS_FLOATING_BANNER: false, // Glues banner ad position to bottom of the page, even when the page is scrolled. Supported only for banner ads, on iOS (>= 5.0) and Android (>= 2.2). Does not apply when IS_INTERSTITIAL_AD: true.

                    // Device Identifiers
                    IMEI_MD5: '',
                    IMEI_SHA1: '',
                    IMSI_MD5: '',
                    IMSI_SHA1: '',
                    ANDROID_ID_MD5: '',
                    ANDROID_ID_SHA1: '',
                    IDFA:'',
                    IDFV:'',

                    // App. Identifiers
                    PACKAGE_NAME:'com.kickitaway.futbal', // The application name as a reverse domain notation string (e.g., 'com.inneractive.adTag'). Equivalent to the bundle ID in iOS.

                    // Ad targeting data and keywords
                    CATEGORY:'Sport', // e.g., Music
                    AGE:'',
                    GENDER:'',
                    KEYWORDS: '', // e.g., Rock,Pop,Jazz,Blues
                    LOCATION:'',
                    GPS_COORDINATES:'',
                    DEVICE_WIDTH:'', // resolution width of the device
                    DEVICE_HEIGHT:'', // resolution height of the device
                    MOBILE_NETWORK_CODE:'',
                    MOBILE_COUNTRY_CODE:'',
                    NETWORK:'', // values are 3G or WIFI
                    REQUIRED_WIDTH:'',
                    REQUIRED_HEIGHT:'',
                    FAILOVER: ''
                };
                // CHANGE AD SETTINGS  ABOVE.
            })();
        }
        catch (e) {

        }
    }
};