var site = 'FP';
var adserver = "http://adsdot.adbureau.net";
var random = Math.round(Math.random() * 10000000000);
if (!pageNum) var pageNum = Math.round(Math.random() * 10000000000);
var engines = new Array("google", "yahoo", "msn", ".aol.", "a9.com", "prweb.com", ".ask.", ".alltheweb.", ".altavista.", ".dogpile.");
// Declare a source code for each engine.
engines["google"] = 80;
engines["yahoo"] = 81;
engines["msn"] = 82;
engines[".aol."] = 83;
engines["a9.com"] = 84;
engines["prweb.com"] = 85;
engines[".ask."] = 86;
engines[".alltheweb."] = 87;
engines[".altavista."] = 88;
engines[".dogpile."] = 89;
$(document).ready(function() {
		
	var qs = new String(window.location.search.substring(1));
	var ref_array = qs.match(/referrer=(\d{1,2})/i);
	var ref = getCookie('ref');
	if (!ref) ref='01';
	if(ref_array){
		ref = ref_array[1];
		if (ref.length != 2) ref = 0+ref ;
		setCookie('ref', ref);
	} else {
		var allurl = (self != top) ? parent.document.referrer : document.referrer; 
		allurl = allurl.toLowerCase();
		for (i=0; i<engines.length; i++) {
			var result = allurl.indexOf(engines[i]);
			if (result != -1) {
				var ref = engines[engines[i]];
				setCookie('ref', ref);
			}
		}
	}
	
	$("div.bannerfeed").each(function() { 
		var t = $(this).attr('id');
		var w = $(this).width();
		var h = $(this).height();
		var a = $(this).attr('rel');
		if (t) {
			var linkSubstring = 'acc_random='+random+'/SITE='+site+'/AREA='+a+'/AAMSZ='+w+'x'+h+'/FP_POSITION='+t+'/REFERRER='+ref+'/pageid=' + pageNum;
			//alert(linkSubstring);
			var iframe = document.createElement('iframe');
			iframe.setAttribute('src',adserver+'/hserver/'+linkSubstring);
			iframe.setAttribute('width',w);
			iframe.setAttribute('height',h);
			iframe.setAttribute('scrolling','no');
			iframe.setAttribute('frameBorder','0');
			iframe.setAttribute('marginHeight','0');
			iframe.setAttribute('marginWidth','0');
			
			document.getElementById(t).appendChild(iframe);
		}
	});
});

function setCookie(name, value){
	// Our cookie
	var expiresAt = new Date();
	expiresAt.setFullYear(expiresAt.getFullYear() + 1);
	document.cookie = name+"="+value+ "; expires=" + expiresAt.toGMTString() +"; path=/";
}
function getCookie(Name) {   	

	var search = Name + "="; 
	if (document.cookie.length > 0) { 
	// if there are any cookies      
	offset = document.cookie.indexOf(search)       

	if (offset != -1) { 
		// if cookie exists          
		offset += search.length          
		// set index of beginning of value         
		end = document.cookie.indexOf(";", offset)          
		// set index of end of cookie value         
		if (end == -1)             
			end = document.cookie.length         
			return unescape(document.cookie.substring(offset, end))      
		}    
	}
}