	// Create the page id for all these ads.
	var page_id = Math.round(Math.random() * 10000000000);
	
	// A list of creatives to render.
	var creatives = new Array();

	// The ad global data.
	ad_area		= "GEN";
	ad_keyword	= "";
	mw_accipiter_global_ad_data = new Array();

	// This function retrieves a value placed on a creative's URL.
	function getCreativeValue (name, def_value)
		{	// Get the creative query string.
			var value = getURLValue("" + document.location, name, def_value);

			return value;
		}; // function getCreativeValue (name, def_value)

	// This function retrieves a value off of the URL of the top-most page that contains the creative.
	function getTopRefPageValue (name, def_value)
		{	// Get the creative query string.
			var value = getURLValue(getTopRefPageURL(), name, def_value);

			return value;
		}; // function getTopRefPageValue (name, def_value)

	// This function returns the URL of the top-most page that contains the creative.
	function getTopRefPageURL ()
		{	var value = "" + window.top.window.document.location.href;
			return value;
		}; // function getTopRefPageURL ()

	// This function retrieves a value off an URL.
	function getURLValue (the_url, name, def_value)
		{	// Get the creative query string.
			the_url	= "&" + ( the_url.indexOf("?") >= 0 ? the_url.substring(the_url.indexOf("?") + 1) : "" );

			// Construct the string we are going to look for.
			var search	= "&" + name + "=";

			// Found the value.
			if ( the_url.indexOf(search) >= 0 )
				{	var value	= the_url.substring(the_url.indexOf(search) + search.length);
					value		= value.indexOf("&") >= 0 ? value.substring(0, value.indexOf("&")) : value;
					return value;
				} // if ( the_url.indexOf(search) >= 0 )

			// No value was provided; therefore, return the default value.
			else
				{	return def_value;
				}; // else
		}; // function getURLValue (the_url, name, def_value)

	// This function loads a creative.
	function loadCreative (id, type, pos, keyword, cat, rest)
		{	// Add the creative.
			creatives					= new Array();
			creatives[creatives.length]	= { type: type, pos: pos };

			// Now get it from the server.
			getCreatives(id, keyword, cat, rest);
		}; // function loadCreative (id, type, pos, keyword, cat, rest)

	// This function loads all the creatives.
	function loadCreatives ()
		{	// Get the number of creatives.
			var num_creatives = creatives ? creatives.length : 0;

			// Load each creative.
			for ( var index = 0; index < num_creatives; index++ )
				{	// Get the div that should contain the creative.
					var container = document.getElementById("INV" + (index + 1));

					// Load the creative since we have something to work with.
					if ( container )
						{	// Get the creative's values.
							var creative	= creatives[index];
							var id			= creative.id;
							var type		= creative.type;
							var pos			= creative.pos;
							var width		= creative.width;
							var height		= creative.height;
							var keyword		= creative.keyword;
							var cat			= typeof(mw_accipiter_global_ad_data["CAT"]) != "undefined" ? mw_accipiter_global_ad_data["CAT"] : "";

							// Construct the creative URL.
							var url = '/display_creative.html?id=' + ad_area + '&type=' + type + '&pos=' + pos + '&keyword=' + escape(keyword) + '&pid=' + page_id + '&cat=' + escape(cat) + 
									( typeof(debug_ads) != "undefined" ? '&debug=yes' : '') + "&rest=";

							for ( var name in mw_accipiter_global_ad_data )
								{	if ( name != "CAT" )
										{	url += name + "=" + escape(mw_accipiter_global_ad_data[name] + "&");
										}; 
								}; // for ( var name in mw_accipiter_global_ad_data )

							// Set the container's inner HTML.
							container.innerHTML			= '<iframe name="creative_' + pos + '" src="" frameborder="no" scrolling="no" width="' + width + '" height="' + height + '" style="margin: 0 auto;"></iframe>';
							container.childNodes[0].src = url;
						}; // if ( container )
				}; // for ( var index = 0; index < num_creatives; index++ )
		}; // function displayCreative (type, pos)

	// This function retrieves the creative data from the bserver.
	function getCreatives (id, keyword, cat, rest)
		{	// Cache-busting and pageid value.
			var aamRnd = Math.round(Math.random() * 10000000000);						

			// Parse the creative values.
			var url = "" + document.location;
			url		= "&" + ( url.indexOf("?") >= 0 ? url.substring(url.indexOf("?") + 1) : "" );

			// Grab the page id.
			var page_id	= url;
			page_id		= page_id.indexOf("&pid=") >= 0 ? page_id.substring(page_id.indexOf("&pid=") + 5) : "";
			page_id		= page_id.indexOf("&") >= 0 ? page_id.substring(0, page_id.indexOf("&")) : page_id;

			aamRnd = page_id != "" ? page_id : aamRnd;

			// Get the gender and date of birth.
			var gender	= typeof getCookie == "function" ? getCookie("wod_gender", "none") : "none";
			gender		= gender == "f" ? "F" : gender;
			gender		= gender == "m" ? "M" : gender;
			var yob		= typeof getCookie == "function" ? getCookie("wod_yob", "none") : "none";

			// Data to append on all creatives.
			creative_global_data = 
				"/site=MW/area=" + id + 
				"/keyword=" + keyword + 
				"/CAT=" + cat + 
				( gender !== "none" ? "/GENDER=" + escape(gender) : "" ) + 
				( gender !== "none" ? "/DOB=" + escape(yob) : "" ) +
				( rest != "" ? "/" + rest.replace(/&/g, "/") : "" );

			creative_global_data = creative_global_data.replace(/\/$/, "");

			// Adserver URL.
			adserver = "http://eb.adbureau.net/bserver";

			// Ad tag targeting values which will be appended to each ad request section in the bserver ad call.
			allAdTags = "/AAMALL" + creative_global_data + "/acc_random="  + aamRnd + "/pageid=" + aamRnd;
		
			// Get the number of creatives.
			var num_creatives = creatives ? creatives.length : 0;

			// The bserver call.
			var url = adserver + allAdTags;

			// Construct the bserver call.
			for ( var index = 0; index < num_creatives; index++ )
				{	// Get the next creative.
					var creative = creatives[index];

					// Get its values.
					var var_name	= "AAMB" + (index + 1);
					var type		= "aamsz=" + creatives[index].type;
					var pos			= "pos=" + creatives[index].pos;

					// Add the creative to the url.
					url += "/" + var_name + "/" + type + "/" + pos;

					// Setup the variable for the creative.
					eval("AAMB" + (index + 1) + "='';");
				}; // for ( var index = 0; index < num_creatives; index++ )		

			// Make the bserver call.
			document.write('<scr' + 'ipt text="text/javascript" src="' + url + '?"></scri' + 'pt>');					
		}; // function getCreatives (id, keyword, cat)


	// This function displays the creatives.
	function displayCreatives ()
		{	// Get the number of creatives.
			var num_creatives = creatives ? creatives.length : 0;
		
			// Now render each creative's div.
			for ( var index = 0; index < num_creatives; index++ )
				{	var invDiv	= 'INV' + ( index + 1 );	
					
					// Get the creative.
					var creative = eval("AAMB" + (index + 1));

					// Display it.
					document.write('<div id="' + invDiv + '">' + creative + '</div>');					
				}; // for ( var index = 0; index < num_creatives; index++ )
		}; // function displayCreatives ()

	// This function places a creative on the webpage.
	function placeCreative (id, type, pos, keyword)
		{	// An hash of width's and heights.
			var dims				= new Array();
			dims["BANNER.tb"]               = new Array("728", "90");
                        dims["BANNER.top"]               = new Array("728", "90");
                        dims["BANNER.bb"]               = new Array("728", "90");
                        dims["BANNER.bot"]               = new Array("728", "90");
                        dims["300x250.rec1"]    = new Array("300", "250");
                        dims["300x250.top"]    = new Array("300", "250");
                        dims["300x250.rec2"]    = new Array("300", "250");
                        dims["300x250.bot"]    = new Array("300", "250");
                        dims["300x250.rec"]             = new Array("300", "250");
                        dims["300x600.halfpage"]                = new Array("300", "600");
			dims["SKYSCRAPER.sky1"]		= new Array("160", "600");
			dims["SKYSCRAPER.top"]         = new Array("160", "600");
			dims["200x90.top"]	= new Array("200", "90");
			dims["210x47.top"]	= new Array("210", "47");						
			
			// Set the dimensions.
			var width	= ( dims[type + "." + pos] ) ? dims[type + "." + pos][0] : 100;
			var height	= ( dims[type + "." + pos] ) ? dims[type + "." + pos][1] : 100;
		
			// Add the creative info to be loaded later.
			creatives[creatives.length] = { id: id, type: type, pos: pos, width: width, height: height, keyword: keyword };
			
			// Output the containing element.
			document.write('<div id="INV' + creatives.length + '" style="height: ' + height + 'px; width: ' + width + 'px; margin: 0 auto;"></div>');
		}; // function placeCreative (id, type, pos, keyword)

	// This function sets the data to appended to all the creatives.
	function setGlobalCreativeData (area, keyword)
		{	ad_area		= area;
			ad_keyword	= keyword;
		}; // function setGlobalCreativeData (area, keyword)

	// This function sets the data to appended to all the creatives.
	function setAdGlobalData (id, value)
		{	mw_accipiter_global_ad_data[id] = value;
		}; // function setAdGlobalData (id, value)


	// This function gets the language of the displayed term.
	function getTermLang ()
		{	// Get the content area.
			var area = document.getElementById("content").innerHTML.toLowerCase();

			// Determine if this is an English word.
			return area.indexOf("<dd class=\"lang\">english</dd>") >= 0 ? "ENG" : "SPAN";
		}; // function getTermLang ()


