var site = 'WOL';
var adserver = "http://adsdot.adbureau.net";
var random = Math.round(Math.random() * 10000000000);
if (!pageNum) var pageNum = Math.round(Math.random() * 10000000000);

$(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);
	} 	
	$("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+'/WOL_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))      
		}    
	}
}