jQuery.support.cors = true;
var div_id = makeid();

document.write('<div id="' + div_id + '"></div>');
$.ajax({
    url: 'http://media.weespernieuws.nl/wcf/Content.svc/getAdContent?api=wnxy7b=&prefix=' + prefix + '&mobile=false&w=' + w + '&h=' + h + '&positie=' + pos + '&max=' + max + '&vp=' + vp + '&rnd=' + div_id + '&advobject=' + advobject,
    async: false,
    dataType: 'jsonp',

    error: function (XMLHttpRequest, status, error) {
        alert(error);
    },
    cache: false,
    success: function (data) {
        var c_adds = 0;
        var html = "";
        var tod = "";
        var advtod = "";
        $.each(data, function () {
            c_adds += 1;

            //locatie, href, h, w, voorpagina, titel, tekst,vervolgpagina, id
            var htmlc = '<img class="adv' + this.w + '_' + this.h + '" width="' + this.w + '" height="' + this.h + '" src="' + this.locatie + '" />';

            if (this.vervolgpagina || this.href.length < 10) {
                html += htmlc;
            } else {
                html += '<a href="' + this.href + '" target="_blank" onclick="recordOutbound(this, \'Advertenties Extern\', \'' + this.href + ' ' + this.id + '\');">' + htmlc + "</a>";
            }
            tod = this.rnd;
            advtod = this.advobject;
        });

        $("#" + tod).append(html);
        trackView(this.href + ' ' + this.id);

        if (c_adds != 0)
            $("#" + advtod).show();
    }
});

function makeid() {
    var text = "";
    var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    for (var i = 0; i < 5; i++)
        text += possible.charAt(Math.floor(Math.random() * possible.length));
    return text;
}
