/*
 * nri_oas_lib.js
 * 
 * NRi ad delivery utility functions.
 * 
 * requires:
 * 	- nri_std_lib.js
*/


/*
 * declare nri.oas namespace
 */
nri.oas = function(){};

nri.oas.place_ads = function()
{
	var $ = jQuery;
	var ads = $(".oas_ad");
	
	for (var pos_offset=false,pos=false,id=false,i=0; i < ads.length; i++)
	{
		id = ads[i].id;
		
		pos = $("#"+id+"_pos");
		if (!pos)continue;
		$(ads[i]).prependTo(pos);
		$(ads[i]).css({display:'block',visibility:'visible',position:'relative'});
	}	
}

/**
 * nri.oas.info()
 * 
 * Display useful information about OAS targeting variables
 */
nri.oas.info = function()
{
	var msg = new Array();
	var outmsg = "";
	
	msg[msg.length] = "Server:\n\t" + OAS_url;
	msg[msg.length] = "Site page:\n\t" + OAS_sitepage;
	msg[msg.length] = "Positions:\n\t" + OAS_listpos;
	msg[msg.length] = "Query:" + OAS_query.replace(/&drupalkwd=/g,"\n\t");
	
	for(var i = 0; i < msg.length; i++) outmsg += msg[i] + "\n\n";
	alert(outmsg);
}

// some third-party ads attempt to modify a non-parent ancestor element
// (read: <body>) in the DOM, which freaks out IE. If this is IE, place ads
// onload to work around this problem. For any other browser, load the ads
// as soon as the DOM is stable!
// ammended 7/14 SPP: fire on load in every browser to address other
//      stability issues...
//if ($.browser.msie)
jQuery(window).load( nri.oas.place_ads );
//else $( nri.oas.place_ads );