﻿/**
* @description
* Ads from AdTech
*/
var ads = {

    // Site ID
    networkId: '1044.1',

    // Mapping between real ad sizes and AdTech size id's
    sizes: {
        '768x150': 316,
        '180x500': 339,
        '468x400': 261,
        '180x150': 169,
        '180x60': 340,
        '300x250': 170
    },


    /**
    * @description
    * Injects an AdTech ad at the spot where the script is executed
    *
    * @example
    * ads.spot('nrk/sport/sykkel','toppknapp/180x150',2428375);
    *
    * @param page          {String}    Name of the page the ad is included at. Used as prefix in the "alias" provided to AdTech.
    * @param spot          {String}    Name of the ad spot on the page where the ad is injected. Used as postfix in the "alias" provided to AdTech.
    * @param placementId   {int}       Placement ID of the spot in AdTech. This parameter is optional.
    */
    spot: function(page, spot) {
        if (page && spot) {
            var size = spot.split('/')[1];
            var pId = arguments[2] || -1;
            var url = 'http://adserver.adtech.de/addyn|3.0|' + ads.networkId + '|' + pId + '|0|' + ads.sizes[size] + '|ADTECH;cookie=info;alias=' + page + ':' + spot + ';loc=100;size=' + size + ';target=_blank;misc=' + new Date().getTime();
            document.write('<script type=\"text/javascript\" src=\"' + url + '\"> <\/script>');
        }
    }

};


/**
* @description
* Bridge between Open Ad Stream function calls and Ad Tech. This bridge take use of Open Ad Stream function calls and
* maps them to Ad Tech function calls. To use this bridge a config which maps the Open Ad Stream spots to Ad Tech must
* be provided. Please see example on how the configurations should be. If no configuration is provided the bridge will
* operate as an empty function doing nothing. This will prevent call to a non existing function.
*
* NOTE: The config must be provided before this script is included.
*
* @example
* var adTechPositions = {
*     'Top':{'name':'toppbanner/768x150'},
*     'Right1':{'name':'toppknapp/180x150'},
*     'page':'nrk/sport/sykkel'
* };
*
* @param   spot    {String}    Name of the Open Ad Stream spot
*/
if (!OAS_RICH) {
    var OAS_RICH = function(spot) {
        if (typeof adTechPositions !== undefined) {
            if (adTechPositions[spot] && adTechPositions['page']) {
                ads.spot(adTechPositions['page'], adTechPositions[spot].name);
            }
        }
    };
}