// *********************************************
// FALK AD FUNCTIONS

// Includes falk specific codebase
function includeFalkCodebase() {
	// Falk global code
	var globalHtml = ' \n </scr' + 'ipt>'
	+ '<!-- BEGIN: AdSolution-Tag 4.0: Global-Code -->'
	+ '<scr'+'ipt type="text/javascript" language="javascript" src="http://a.as-us.falkag.net/dat/dlv/aslmain.js"></scr'+'ipt>'
	+ '<scr'+'ipt type="text/javascript" language="javascript" src="http://a.as-us.falkag.net/dat/dlv/aslsubs111.js"></scr'+'ipt>'
	+ '<!-- END: AdSolution-Tag 4.0: Global-Code -->';
	
	document.write(globalHtml);
}	

// This variable tells the site pages that falk ads should always be used.  Set this to true for the falk launch.
// Until then, the flag is set to false and users must get the falkTester cookie to see falk ads.
var alwaysRenderFalk = true;

// Include the falk codebase
includeFalkCodebase();

function falkAd(tag, channel, width, height) {
	this.falkTag = tag;
	this.falkChannel = channel;
	this.falkWidth = width;
	this.falkHeight = height;
	this.renderFalkAd = render_falk_ad;
}

function render_falk_ad() {	

	// Falk specific variables
	Ads_kid=0;
	Ads_bid=0;
	Ads_xl= this.falkWidth;
	Ads_yl= this.falkHeight;
	Ads_xp='';
	Ads_yp='';
	Ads_opt=0;
	Ads_wrd='';
	Ads_prf='';
	Ads_par='';
	Ads_cnturl='';
	Ads_sec=0;
	Ads_channels = this.falkChannel;

	var tagHtml = '<scr' + 'ipt type="text/javascript" language="JavaScript" src="http://a.as-us.falkag.net/dat/njf/52/' + this.falkTag + '"></scr'+'ipt>';

	document.write(tagHtml);
}


// *********************************************
// DART AD FUNCTIONS

var ad_menuTime = 2.5;
var ad_contentTime = 7;
var ad_homeTime = 2.5;

function ad(tag,width,height,minutes)
{
	this.tag     = tag;
	
	this.minutes = minutes || 0;
	this.width   = width  || 468;
	this.height  = height || 60;

	this.timerId = 0;
	this.style = "";
	this.prefix = "http://doubleclick.shockwave.com/adi/";

	this.swap      = ad_swap;
	this.draw      = ad_draw;
	this.drawLayer = ad_drawLayer;
	this.random    = ad_random;

	this.ord = this.random(10000000);

	if (!document.asw_adcount)
	{
		document.asw_adcount = 1;
	}
	else
	{
		document.asw_adcount++;
	}

	this.adId = "asw_advert_" + document.asw_adcount;
	
	if (this.tag.indexOf("sz=") == -1)
	{
		this.tag += 'sz=' + this.width + 'x' + this.height + ';'
	}
	
	document[this.adId] = this;
	
	if (this.minutes)
	{
		this.timerId = setInterval("document."
			+ this.adId + ".swap()", this.minutes * 60 * 1000);
	}
}

function ad_draw()
{
	var html = '&nbsp;';
	if (browser_ie() || browser_ns6())
	{
		if (browser_ie() && !browser_mac())
		{
			html = '<iframe id="' + this.adId
				+ '_ad" src="' + this.prefix + this.tag
				+ 'ord=' + this.ord + '?" marginheight=0 marginwidth=0 border=0 width=' + this.width
				+ ' height=' + this.height + ' scrolling=no frameborder=0></iframe>';
		}
		else
		{
			html = '<iframe id="' + this.adID
				+ '_ad" src="/ad/holder.html?ad=' + escape(this.tag)
				+ '&w=' + escape(this.width) + '&h=' + escape(this.height)
				+ '" marginheight=0 marginwidth=0 border=0 width=' + this.width
				+ ' height=' + this.height + ' scrolling=no frameborder=0></iframe>\n';
		}
		this.style = "iframe";
	}
	else if (browser_ns4())
	{
		html =  '<ilayer visibility="hidden" id="' + this.adId + '_holder" width='
			+ this.width + ' height=' + this.height + '>'
			+ '</ilayer>';
		this.style = "layer";
	}

	document.write(html);
}

function ad_drawLayer()
{
	if (this.style == 'layer')
	{
		var x = document.layers[this.adId + '_holder'].pageX;
		var y = document.layers[this.adId + '_holder'].pageY;
		var html = '<layer src="' + this.prefix + this.tag
			+ 'ord=' + this.ord + '?' + '" '
			+ 'name="' + this.adId + '_ad" '
			+ 'width=' + this.width + ' height=' + this.height + ' '
			+ 'visibility="hidden" '
			+ 'onLoad="moveTo(' + x + ',' + y + ');'
			+ 'clip.width=' + this.width + ';clip.height=' + this.height + ';'
			+ 'visibility=\'show\';"></layer>';
			document.write(html);
	}
}

function ad_swap()
{
	this.ord = this.random(1000000);
	var url = this.prefix + this.tag + "ord=" + this.ord + "?";
	
	if (browser_ie() || browser_ns6())
	{
		var ad;
		if (browser_ie() && !browser_mac())
		{
			document.frames[this.adId + "_ad"].location.replace(url);
		}
		else
		{
			var thedoc = browser_ie() ? document.frames[this.adId + "_ad"].document
				: document.getElementById(this.adId + "_ad").contentDocument;
				
			thedoc.location.replace("/ad/holder.html?ad=" + escape(this.tag)
				+ '&w=' + escape(this.width) + '&h=' + escape(this.height));
		}
	}
	else if (browser_ns4())
	{
		document.layers[this.adId + "_ad"].src = url;
	}
}

function ad_random(range)
{
	var d = new Date();
	var sec = '' + d.getTime();
	sec = parseInt(sec.substring(0,sec.length-1));
	var result = (sec % range) + 1;
	return result;
}

function ad_superstitial(tag)
{
	var superstitial = '';
	if (browser_getVersion() >= 4 && browser_getPlatform() == 'win')
	{
	   if (browser_ns4())
	   {
		  superstitial = '<layer id=superstitial width=4 height=4 left="-10" height="-10" visibility=hidden src="'
			+ 'http://ad.doubleclick.net/adf/' + tag + 'ord=' + ad_random(1000000) + '?"></layer>';
	   }
	   else if (browser_ie())
	   {
		  superstitial = '<div style="position:relative;visibility:hidden;">\n'
			+ '<iframe name=superstitial bgcolor="ffffff" width=4 height=4 marginwidth=0'
			+ ' marginheight=0 border=0 scrolling=no frameborder=0 src="http://ad.doubleclick.net/adf/'
			+ tag + 'ord=' + ad_random(1000000) + '?"></iframe>\n</div>';
	   }
	}

	document.writeln(superstitial);
}
