// random number to be added to the DoubleClick URLs to prevent caching
//var ord=Math.random()*10000000000000000;
var ord=Math.ceil(Math.random()*100);
function Advertisement(id, host, url, width, height){
	this.id = id;
	this.host = host;
	this.url = url;
	this.width = width;
	this.height = height;
}
var companionAdvertisements = new Array();
var currentCompanion = null;
var dcTimeout = null;
var dcTimeoutLength = 20000;
var dcDoTimeout = false;

function setCompanionAds(dc_seed) {
	for ( i in companionAdvertisements ) {
		currentCompanion = companionAdvertisements[i];
		re = new RegExp("dc_seed=;", "ig");
		if (!dc_seed || dc_seed=="null") {
	 		currentCompanion.url = currentCompanion.url.replace(re, "");		 
	 	} else {
	 		currentCompanion.url = currentCompanion.url.replace(re, "dc_seed=" + dc_seed + ";");
	 	}
		var s = document.getElementById(currentCompanion.id);
		var iframeName = "iframe_" + currentCompanion.id;
		if (s) {
			s.innerHTML = '<iframe id="' + iframeName + '" name="' + iframeName + '" src="' + currentCompanion.host + '/adi/' + currentCompanion.url + 'ord=' + ord + '?" width="' + currentCompanion.width + '" height="' + currentCompanion.height + '" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0">' + '</iframe>';
		}
		// add a timeout/refresh to the skyscraper 'companion'
		if (iframeName.match("skyscraper") && dcDoTimeout) {
 			var dcTimeout=setInterval("dc_timeout('" + iframeName + "');",dcTimeoutLength);
 		}
	}
}

function dc_timeout(iframeName) {
	//get src of iframe, and replace the ord random number with a new number
	var src = document.getElementById(iframeName).src;
	document.getElementById(iframeName).src=src.substring(0,src.indexOf("ord=")) + "ord=" + Math.random()*10000000000000000;
}

var enableDebug = true;
var debugOutput = null;
function logCallback(text) {
	if (enableDebug && document.location.search.match(/(\?|\&)debug=true(&?)/)) {
		var c = document.getElementById('video_popup_container');
		if (c) {
			var p = c.parentNode;
			if (!debugOutput) debugOutput = document.createElement('textarea');
			debugOutput.setAttribute('style','position:absolute; top:0; left:420px; height: 500; width:420px; border: black 1px solid; background:#eee;');
			debugOutput.style.position='absolute'; 
			debugOutput.style.top='0';
			debugOutput.style.left='420px'; 
			debugOutput.style.height='500px'; 
			debugOutput.style.width='420px'; 
			debugOutput.style.border='black 1px solid'; 
			debugOutput.style.background='#eee';
			p.appendChild(debugOutput);
		}
		if (debugOutput) debugOutput.value += text + "\n---\n";
	}
}

