if (typeof(aj_server) != 'undefined' && typeof(aj_adspot) != 'undefined' && typeof(aj_page) != 'undefined' && typeof(aj_zone) != 'undefined') {
    aj_tag = aj_server;
    aj_tag += aj_adspot+"/"+aj_page+"/vj?z="+aj_zone;
    
    if (typeof(aj_ch) != 'undefined' && aj_ch != "") {
        aj_tag += "&ch="+aj_ch;
    }
    if (typeof(aj_dim) != 'undefined' && aj_dim != "") {
        aj_tag += "&dim="+aj_dim;
    }   	
    if (typeof(aj_ct) != 'undefined' && aj_ct != "") {
        aj_tag += "&ct="+aj_ct;
    }
    if (typeof(aj_pos) == 'undefined') {
        aj_pos = 1;
    } 
    else {
        aj_pos++;
    }
    aj_tag += "&pos="+aj_pos;

    if (typeof(aj_kw) != 'undefined' && aj_kw != "") {
        aj_tag += "&kw="+aj_kw;
    }

    if (typeof(aj_pv) != 'undefined' && aj_pv == true) {
        if (typeof(aj_pv_rnd) == 'undefined') {
            aj_pv_rnd = Math.round( (Math.random() + "") * 10000000000000000 ) + 1;
        }
        aj_tag += "&pv=" + aj_pv_rnd;
    }

    aj_tag += "&nc=" + Math.round( (Math.random() + "") * 100000000 ) + 1;

    if (typeof(aj_click) != 'undefined' && aj_click != "") {
        aj_tag += "&click="+escape(aj_click);		
    }

    if (aj_adCounter === undefined) {
        var aj_adCounter = 0;
    }
    else {
        aj_adCounter++;
    }

    document.write('<scr'+'ipt onload="ajHQ.scr_onload(' + aj_adspot + ')" onreadystatechange="ajHQ.scr_onrsc(' + aj_adspot + ')" id="tmp_scr_' + aj_adspot + '" language="javascript" src="'+aj_tag+'"></scr'+'ipt>');
    

}

var ajHQ = {

g:function (id) {
    return document.getElementById(id);
},

scr_onload:function (adspot) {
    ajHQ.copy_div_content(adspot);
},

scr_onrsc:function (adspot) {
    var scr = ajHQ.g('tmp_scr_' + adspot);
    if (scr && scr.readyState == 'complete') {
        ajHQ.copy_div_content(adspot);
    }
},

copy_div_content:function (adspot) {
    if (typeof(isAberdeen) === 'undefined') {
        var tmp = ajHQ.g('aje_tmp_' + adspot);
            tmp.removeChild(ajHQ.g('tmp_scr_' + adspot));
            tmp.removeChild(ajHQ.g('aje_scr_' + adspot));

        if(ajHQ.g('aje_' + adspot) && tmp.innerHTML != "") {
            if (typeof(loadLast) === 'undefined') { // check for var given to ads w/ 3rd party scripting 
                 ajHQ.g('aje_' + adspot).innerHTML = tmp.innerHTML;
            }
            else {
                jQuery(function() {
                    ajHQ.g('aje_' + adspot).innerHTML = tmp.innerHTML;
                });
            }
        }
    }
    else {
        var aberdeen_tmp = ajHQ.g('aberdeen_aje_tmp_' + adspot);
            aberdeen_tmp.removeChild(ajHQ.g('tmp_scr_' + adspot));
            aberdeen_tmp.removeChild(ajHQ.g('aje_scr_' + adspot));

        if(ajHQ.g('aberdeen_aje_' + adspot) && (typeof(aberdeen_tmp) != 'undefined' && aberdeen_tmp.innerHTML != "")) {
            if (typeof(loadLast) === 'undefined') { // check for var given to ads w/ 3rd party scripting 
                ajHQ.g('aberdeen_aje_' + adspot).innerHTML = aberdeen_tmp.innerHTML;
            }
        }
        else {
            jQuery(function() {
                ajHQ.g('aberdeen_aje_' + adspot).innerHTML = aberdeen_tmp.innerHTML;
            });
        }
    }
}

}
