(function() {
	var w = window;
	var d = document;
	var location = d.location;
	var referrer = d.referrer;
	var nullvalue = null;

	if (w.fan_ads_link == nullvalue) {
		w.fan_ads_link = 'http://fantasyaffiliatenetwork.com';
	}

	if (
		(w.fan_ads_client_id == nullvalue) ||
		(w.fan_ads_affiliate_id == nullvalue) ||
		(w.fan_ads_campaign_id == nullvalue) ||
		(w.fan_ads_width == nullvalue) ||
		(w.fan_ads_height == nullvalue)
	) {
		w.fan_ads_url = 'http://fan-ads.s3.amazonaws.com/1-1x1-1.gif';
		w.fan_ads_width = (w.fan_ads_width == nullvalue) ? 0 : w.fan_ads_width;
		w.fan_ads_height = (w.fan_ads_height == nullvalue) ? 0 : w.fan_ads_height;
		w.fan_ads_affiliate_id = 0;
		w.fan_ads_campaign_id = 0;
	} else {
		if (w.fan_ads_count == nullvalue) w.fan_ads_count = 1;
		w.fan_ads_url = 'http://fan-ads.s3.amazonaws.com/' + w.fan_ads_client_id + '-' + w.fan_ads_width + 'x' + w.fan_ads_height + '-' + (Math.floor(Math.random() * w.fan_ads_count) + 1) + '.gif';
	}

	d.write('<a href="' + w.fan_ads_link + '">');
	d.write('<img border="0" width="' + w.fan_ads_width + '" height="' + w.fan_ads_height + '" src="' + w.fan_ads_url + '" onerror="javascript:ChangeExtension(this, \'.gif\', \'.jpg\');">');
	//d.write('<img border="0" width="1" height="1" src="http://fantasyaffiliatenetwork.com/campaigns/impressions/' + w.fan_ads_affiliate_id + '/' + w.fan_ads_campaign_id + '" style="position:relative; top:-1px; left:-1px;" />');
	d.write('</a>');
})();

function ChangeExtension(image, from, to) {
	image.src = image.src.replace(from, to);
	image.onerror = '';
}
