// adc2 headers
var adc_creative_1993_clicks = [];
var adc_creative_1993_events = [];
var ADCENTRIC = ADCENTRIC || { };
ADCENTRIC.lang = ADCENTRIC.lang || { };

ADCENTRIC.lang.namespace = function(nsname) {
var nodes = nsname.split(".");
var obj = window;

for (var i = 0; i < nodes.length; i++) {
 obj[nodes[i]] = obj[nodes[i]] || { };
 obj = obj[nodes[i]];
 }
 return obj;
};

//document.write('<div id="redux_cpa" style="position:absolute;left:-1000px;top:-1000px;width:1px;height:1px"></div>');

ADCENTRIC.lang.namespace("ADCENTRIC.env.util");
ADCENTRIC.lang.namespace("ADCENTRIC.tracking");

ADCENTRIC.tracking.EventPixelDispatcher = function() {
        var witness_event_queue = new Array();
        var queue_processing = false;
        var pixel = new Image();

        function process_queue() {
                queue_processing = true;
                pixel.onload = function() {
                        pixel = new Image();
                        if (witness_event_queue.length > 0) {
                                process_queue();
                        } else {
                                queue_processing = false;
                        }
                };
                
                pixel.src = witness_event_queue.shift();
        }

        function maybe_process_queue() {
                if (!queue_processing) {
                        process_queue();
                        return true;
                }
                return false;
        }

        function cache_bust(url) {
                var qindex = url.indexOf("?");
                var random = "r=" + Math.random();

                if (qindex < 0) {
                        random = "?" + random;
                } else if (qindex != (url.length - 1)) {
                        random = "&" + random;
                }
                return(url + random);
        }

        return {
dispatch: function(event_pixel_url, dont_cache_bust) {
                  var url = event_pixel_url;

                  if (!dont_cache_bust) {
                          url = cache_bust(url);
                  }
                  witness_event_queue.push(url);
                  return maybe_process_queue();
          }
        };
};

ADCENTRIC.env.util.getPublisherTrackerURL = function(oid_str) {
	var oid_string = oid_str.toLowerCase();
	var publisher_cpa_tracker_url = "";
	var location = top.document.location.href.toLowerCase();
	
	if(oid_string.indexOf("undertonenetwork") != -1){
		publisher_cpa_tracker_url = "http://xads.zedo.com/ads2/t?o=99649;h=425140;z=" + Math.random();
	}else if(oid_string.indexOf("aol") != -1){
		publisher_cpa_tracker_url = "http://ace-tag.advertising.com/action/type=411144433/bins=1/rich=0/mnum=1516/site=695501/logs=0/betr=mntrltrsm_cs=2";
	}else if(oid_string.indexOf("quakemarketing") != -1){
		publisher_cpa_tracker_url = "http://ad.yieldmanager.com/pixel?id=104250&t=2";
	}else if(oid_string.indexOf("redmccombs") != -1){
		publisher_cpa_tracker_url = "http://ad.ca.doubleclick.net/activity;src=1620403;type=touyr551;cat=mondm436;ord=" + (Math.random() * 10000000000000) + "?";
	}else if(oid_string.indexOf("redduxmedia") != -1){
		publisher_cpa_tracker_url = "https://affiliate.ucpatracker.com/rd/px.php?hid=1080&sid=159&transid=720";
	}else if(oid_string.indexOf("suite66") != -1){
		publisher_cpa_tracker_url = "http://ad.ad-flow.com/pixel?id=104393&t=2&rand=" + Math.random();
	}else if(oid_string.indexOf("valueclick") != -1){
		publisher_cpa_tracker_url = "https://secure.fastclick.net/w/roitrack.cgi?aid=6262&rand=" + Math.random();
	}else if(oid_string.indexOf("yahoo") != -1){
		publisher_cpa_tracker_url = "http://ad.yieldmanager.com/pixel?id=105518&t=1";
	}else if(oid_string.indexOf("msn") != -1){
		publisher_cpa_tracker_url = "http://switch.atdmt.com/action/msnCA_TM_MoreInfo_300408";
	}else if(oid_string.indexOf("olive") != -1){
		publisher_cpa_tracker_url = "http://ads.olivebrandresponse.com/pixel?id=107411&t=2";
	}else if(oid_string.indexOf("casale") != -1){
		publisher_cpa_tracker_url = "http://r.casalemedia.com/r?u=130083";
	}else if(oid_string.indexOf("adconion") != -1){
		publisher_cpa_tracker_url = "http://adopt.euroclick.com/conv.eu?adv=2675&rnd=" + Math.random();
	}else if(oid_string.indexOf("tribal") != -1){
		publisher_cpa_tracker_url = "http://a.tribalfusion.com/ti.ad?client=258153&ev=1";
	}else if(oid_string.indexOf("activeresponse") != -1){
		publisher_cpa_tracker_url = "http://ad.firstadsolution.com/pixel?id=114048&t=2";
	}else if(oid_string.indexOf("etype") != -1){
		publisher_cpa_tracker_url = "http://ad.acceleratorusa.com/pixel?id=114735&t=2";
	}else if(oid_string.indexOf("adnet") != -1){
		publisher_cpa_tracker_url = "http://ad.adnetinteractive.com/pixel?id=115804&t=2";	
	}
	
	return publisher_cpa_tracker_url;
}

ADCENTRIC.tracking.trackCPAClick = function(oid_value) {
	var oid = oid_value.toLowerCase();
	var location = top.document.location.href.toLowerCase();
	var cpa_publisher_url = ADCENTRIC.env.util.getPublisherTrackerURL(oid);
	//var cpa_adc_url = "http://adc2.adcentriconline.com/adcentric/direct_count/267/1/7335;1992.gif";
	var cpa_adc_url = "http://adc2.adcentriconline.com/adcentric/direct_count/267/1/7335;2064.gif";
	var dispatcher = new ADCENTRIC.tracking.EventPixelDispatcher();
	var cache_bust_pixel = true;
	
	if(oid.indexOf("adnet") != -1){
		cache_bust_pixel = false;
	}
	
	dispatcher.dispatch(cpa_adc_url);
	if(cpa_publisher_url){
	
		if(cache_bust_pixel){
			dispatcher.dispatch(cpa_publisher_url);
		
			if(oid.indexOf("quakemarketing") != -1){
				dispatcher.dispatch("http://ad.yieldmanager.com/pixel?id=106429&t=2");
			}
		}else{
			dispatcher.dispatch(cpa_publisher_url, true);
		
			if(oid.indexOf("quakemarketing") != -1){
				dispatcher.dispatch("http://ad.yieldmanager.com/pixel?id=106429&t=2");
			}
		}
	}
	
	
	return;
}

