var retargeting = {
        
    properties: null,
    
    jsonCallback: function(json) {
        this.properties = json;
        this.writeCotnent(1);
    },
    
    jsonCallbacks: [],
    
    getBanner: function(zoneId, pageType) {
        if (this.properties === null) {
            this.jsonCallbacks[zoneId] = function (zone, type, scope){
                return function(json) {
                    scope.properties = json;
                    scope.writeCotnent(zone, type);
                };
            } (zoneId, pageType, this);
            document.write('<scr'+'ipt type="text/javascript" src="/scripts/pages/de/retargeting/session.php?callback=retargeting.jsonCallbacks['+zoneId+']"></scr'+'ipt>');
        } else {
            this.writeContent(zoneId);
        }
    },
    
    writeCotnent: function(zoneId, pageType) {
        var m3_u = (location.protocol=='https:'?'https://adserver2.brainbits.net/www/delivery/ajs.php':'http://adserver2.brainbits.net/www/delivery/ajs.php');
        var m3_r = Math.floor(Math.random()*99999999999);
        var params = this.getSerializedParams();
        if (!document.MAX_used) document.MAX_used = ',';
        document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
        document.write ("?target=_blank&amp;zoneid=" + zoneId);
        document.write ('&amp;cb=' + m3_r);
        if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
        document.write (document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : ''));
        document.write ("&amp;loc=" + escape(window.location));
        if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
        if (document.context) document.write ("&context=" + escape(document.context));
        if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
        if (params != '') document.write("&amp;" + params);
        if (typeof pageType == 'string') document.write("&amp;pagetype=" + pageType);
        document.write ("'><\/scr"+"ipt>");  
    },
    
    getSerializedParams: function () {
        var params = [];
        for(key in this.properties) {
            params[params.length] = encodeURIComponent(key) + "=" + encodeURIComponent(this.properties[key]);
        }
        return params.join("&amp;");
    }
};



