function requestCrossDomain( site, callback ) {
	if ( !site ){
		alert('No site was passed.');
		return false;
	}
	var yql = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from html where url="' + site + '"') + '&format=xml&callback=?';
	$.getJSON( yql, cbFunc );

	function cbFunc(data){
	if ( data.results[0] ) {
		data = data.results[0].replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '');
		if ( typeof callback === 'function') {
			callback(data);
		}
	}
	else throw new Error('Nothing returned from getJSON.');
	}
}

$(function(){
td = window.location.hostname;
$domain = (td.split('www.').length>1) ? td : "www."+td;
$ads = new Array();


$divs = $('div')
        .each(function (arr) {
		$type = $(this).attr('fpm');
		if($type){
		base = "http://flyingpenguinsmedia.com/";
		lib = "adnet/";
		file = "ad2.php";
		mExt = Math.floor(Math.random()*9871);
		randExt = "?se="+mExt+"&domain="+$domain;
		baseurl = base+lib+file+randExt;
		
			tmp = new Object();
			tmp.id = "fpm_"+arr;
			tmp.element = $(this).get(0).tagName;
			tmp.height = $(this).height();
			tmp.width = $(this).width();
			
			
			tmp.parent = new Object();
			tmp.parent.tagName = $(this).parent(0).get(0).tagName;
			tmp.parent.width = $(this).parent(0).width();
			tmp.parent.height = $(this).parent(0).width();
			
			this.id = "fpm_"+arr;
				requestCrossDomain(baseurl,function(ref) { 
				return function(results){  
					$(ref).html(results); 
					//grab results info
					direct = "#fpm_"+arr+" img";
					$(direct).width('100%');

				 } 
			}(this));
				
			$ads[$ads.length] = [arr,$type];
			//console.log(tmp);
		}
        });
		

//console.log($ads);
//alert("Console logged");
});
