// Create the mw.ads.google package (if needed).
mw				= typeof(mw) != "undefined" ? mw : {};
mw.ads			= typeof(mw.ads) != "undefined" ? mw.ads : {};
mw.ads.google	= typeof(mw.ads.google) != "undefined" ? mw.ads.google : {};

// Defining the mw.ads.google.afc package for the first time.
if ( typeof(mw.ads.google.afc) == "undefined" )
	{	// Fill in the details.
		mw.ads.google.afc =
			{	// An array of listeners.
				afc_listeners: new Array(),
			
				// Constructor for the default AFCAdRenderer object class.
				AFCAdRenderer: function ()
					{	// This method renders an ad.
						this.renderAd = function (afc_ad, index, total)
							{	// Create a leaderboard.
								if ( afc_ad.google_ad_unit == "leaderboard" )
									{
									} // if ( afc_ad.google_ad_unit == "leaderboard" )

								// Return an image ad.
								else if ( afc_ad.type == "image" ) 
									{	// Get the ad values.
										var visible_url		= afc_ad.visible_url;
										var ad_url			= afc_ad.url;
										var image_url		= afc_ad.image_url;
										var image_width		= Math.max(0, afc_ad.image_width);
										var feedback_url	= google_info.feedback_url;

										// Create the ad content.
										var content = 
											'<div class="creative image google">' + 
												'<div>' + 
													'<a href="' + ad_url + '" target="_top" title="go to ' + visible_url + '" onmouseover="javascript:window.status=\'Go to ' + visible_url + '\'; return true;" onmouseout="javascript:window.status=\'\'; return true;">' + 
														'<img border="0" src="' + image_url + '"  />' +
													'</a>' + 
												'</div>' + 
												'<table class="ads_by_google" border="0" cellpadding="2" cellspacing="0" style="width: ' + image_width + 'px;">' +
													'<tr>' +
														'<td style="text-align: left;"><a href="' + ad_url + '" onmouseover="javascript:window.status=\'Go to ' + visible_url + '\'; return true;" onmouseout="javascript:window.status=\'\'; return true;">Go to ' + visible_url + '</a></td>' +
														'<td style="text-align: right;"><a href="' + feedback_url + '">Feedback - Ads by Google</a></td>' + 
													'</tr>' +
												'</table>' 
											'</div>';

										return content;
									} // else if ( afc_ad.type == "image" ) 

								// Return a Flash video ad.
								else if ( afc_ad.type == "flash" ) 
									{	// Construct the ad content.
										var content =
											'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + google_ads[0].image_width + ' height="' + google_ads[0].image_height + '">' + 
												'<param name="movie" value="' + afc_ad.image_url + '" />' + 
												'<param name="quality" value="high" />' + 
												'<param name="AllowScriptAccess" value="never" />' + 
												'<param name="google_hints" value="' + escape(token) + '" />' + 
												'<embed ' +
													'src="' + afc_ad.image_url + '" ' + 
													'width="' + afc_ad.image_width + '" ' +
													'height="' + afc_ad.image_height + '" ' + 
													'type="application/x-shockwave-flash" ' + 
													'AllowScriptAccess="never" ' + 
													'pluginspace="http://www.macromedia.com/go/getflashplayer">' + 
												'</embed>' + 
											'</object>';

										// Add the feedback link since this ad isn't using the google player.
										try 
											{	if ( afc_ad.image_url.indexOf('googleadplayer.swf') == -1 )
													{	// Get the ad values.
														var visible_url		= afc_ad.visible_url;
														var ad_url			= afc_ad.url;
														var image_url		= afc_ad.image_url;
														var image_width		= Math.max(0, afc_ad.image_width);
														var feedback_url	= google_info.feedback_url;

														// Construct the ad content.
														content += 
															'<table class="ads_by_google" border="0" cellpadding="2" cellspacing="0" style="width: ' + image_width + 'px;">' +
																'<tr>' +
																	'<td style="text-align: left;">' +
																		'<a ' + 
																			'href="' + ad_url + '" ' + 
																			'onmouseover="javascript:window.status=\'Go to ' + visible_url + '\'; return true;" ' + 
																			'onmouseout="javascript:window.status=\'\'; return true;">' +
																			'Go to ' + visible_url + 
																		'</a>' + 
																	'</td>' +
																	'<td style="text-align: right;"><a href="' + feedback_url + '">Feedback - Ads by Google</a></td>' + 
																'</tr>' +
															'</table>';
													}; // if ( afc_ad.image_url.indexOf('googleadplayer.swf') == -1 )
											} // try

										catch (e)
											{
											}; // catch (e)

										return content;
									} // else if ( afc_ad.type == "flash" ) 

								else
									{	// The ad content.
										var content = index > 0 ? '' :  '<div class="header">Ads by Google</div>';

										// Append the text link.
										content += 
											'<div>' + 
												'<a href="' + afc_ad.url + '" ' + 
													'onmouseout="window.status=\'\'" ' +
													'onmouseover="window.status=\'go to ' + afc_ad.visible_url + '\'" ' +
													'style="text-decoration:none">' +
													'<span style="text-decoration:underline;"><strong>' + afc_ad.line1 + '</strong><br /></span>' +
													'<span style="color: #000000;" class="descr">' + afc_ad.line2 + '&nbsp;' + afc_ad.line3 + '<br /></span>' + 
													'<span style="text-decoration:underline;">' + afc_ad.visible_url + '</span>' +
												'</a>' + 
											'</div>';

										return content;
									}; // else
							}; // function renderAd (afc_ad, index, total)

						return this;
					}, // class AFCAdRenderer

				// This method adds an AFC listener.
				addListener: function (listener)
					{	this.afc_listeners[this.afc_listeners.length] = listener;
					}, // function addListener (listener)

				// This method handles all AFC load events.
				onAFCAdsLoaded: function (afc_ads, afc_ad_id)
					{	// Add the ad units parameter.
						for ( var index = 0; index < afc_ads.length; index++ )
							{	afc_ads[index].google_ad_unit = google_ad_unit;
							}; // for ( var index = 0; index < afc_ads.length; index++ )

						// Notify all the listeners.
						for ( var index = 0; index < this.afc_listeners.length; index++ ) 
							{	this.afc_listeners[index].onAFCAdsLoaded(afc_ads, afc_ad_id);
							}; // for ( var index = 0; index < this.afc_listeners.length; index++ ) 

					} // function onAFCAdsLoaded (afs_ads, afs_ad_id)		

			}; // mw.ads.google.afs
	}; // if ( typeof(mw.ads.google.afc) == "undefined" )

// Defining the mw.ads.google.afs package for the first time.
if ( typeof(mw.ads.google.afs) == "undefined" )
	{	// Fill in the details.
		mw.ads.google.afs =
			{	// An array of listeners.
				afs_listeners: new Array(),
			
				// Constructor for the default AFSAdRenderer object class.
				AFSAdRenderer: function ()
					{	// This method renders an ad.
						this.renderAd = function (afs_ad, index, total)
							{	// Create a text ad.
								if ( afs_ad.type && (afs_ad.type == "text/wide" || afs_ad.type == "text/narrow") )
									{	return this.renderTextAd(afs_ad, index, total);
									} // if ( afs_ad.type && (afs_ad.type == "text/wide" || afs_ad.type == "text/narrow") )

								// Invalid ad type.
								else
									{	return "";
									}; // else
							}; // function renderAd (afs_ad, index, total)

						// This method returns a text ad.
						this.renderTextAd = function (afs_ad, index, total)
							{	// Render the content.
								var content =
									'<div class="googleAFSTextAd">' +
										'<div class="afs_' + ( afs_ad.type == "text/wide" ? "wide" : "narrow" ) + '">' + 
											'<div class="afs_headline">' +
												'<a onmouseover="javascript:window.status=\'' + 
													afs_ad.visible_url + '\';return true;" ' + 
													'onmouseout="javascript:window.status=\'\';return true;" ' +
													'href="' + afs_ad.url + '">' + afs_ad.line1 + 
												'</a>' +
											'</div>' + 
											'<div class="afs_text">' + 
												'<a onmouseover="javascript:window.status=\'' + 
													afs_ad.visible_url + '\';return true;" ' +
													'onmouseout="javascript:window.status=\'\';return true;" ' +
													'href="' + afs_ad.url + '">' + 
													afs_ad.line2 + 
												'</a>' + 
											'</div>' + 
											'<div class="afs_url">' + 
												'<a onmouseover="javascript:window.status=\'' + 
													afs_ad.visible_url + '\';return true;" ' +
													'onmouseout="javascript:window.status=\'\';return true;" ' +
													'href="' + afs_ad.url + '">' +
													afs_ad.visible_url + 
												'</a>' + 
											'</div>' +
										'</div>' +
									'</div>';

								return content;
							}; // function renderTextAd (afs_ad, index, total)

						return this;
					}, // class AFSAdRenderer

				// This method adds an AFS listener.
				addListener: function (listener)
					{	this.afs_listeners[this.afs_listeners.length] = listener;
					}, // function addListener (listener)

				// This method handles all AFS load events.
				onAFSAdsLoaded: function (afs_ads, afs_ad_id)
					{	// Notify all the listeners.
						for ( var index = 0; index < this.afs_listeners.length; index++ ) 
							{	this.afs_listeners[index].onAFSAdsLoaded(afs_ads, afs_ad_id);
							}; // for ( var index = 0; index < this.afs_listeners.length; index++ ) 

					} // function onAFSAdsLoaded (afs_ads, afs_ad_id)		

			}; // mw.ads.google.afs
	}; // if ( typeof(mw.ads.google.afs) == "undefined" )

// Register an AFC listener.
mw.ads.google.afc.addListener
	(	{	onAFCAdsLoaded: function (ads, ad_id) 
				{	// Instantiate the renderer.
					var renderer = new mw.ads.google.afc.AFCAdRenderer();

					// The rendered ad content.
					var ad_content = new Array();

					// Render the ads.
					for ( var index = 0; index < ads.length; index++ )
						{	ad_content[index]	= renderer.renderAd(ads[index], index, ads.length);
						}; // for ( var index = 0; index < ads.length; index++ )	

					// Get the ad container.
					var ad_container = document.getElementById(ad_id);

					// Place the ads.
					if ( ad_container )
						{	for ( var index = 0; index < ad_content.length; index++ )
								{	ad_container.innerHTML += ad_content[index];
								}; // for ( var index = 0; index < ad_content.length; index++ )
						}; // if ( ad_container )
				} // function onAFCAdsLoaded (ads)
		}
	);

// Register an AFS listener.
mw.ads.google.afs.addListener
	(	{	onAFSAdsLoaded: function (ads, ad_id) 
				{	// Nothing to do.
					if ( ads.length <= 0 ) 
						{	return;
						}; // if ( ads.length <= 0 ) 

					// Instantiate the renderer.
					var renderer = new mw.ads.google.afs.AFSAdRenderer();

					// The ad content.
					var ad_content = new Array();

					// Generate all the ad content.
					for ( var index = 0; index < ads.length; index++ )
						{	// Render the ad content.
							ad_content[index]	= renderer.renderAd(ads[index], index, ads.length);
						}; // for ( var index = 0; index < ads.length; index++ )

					// Get the results ad div.
					var results_box_ad = ad_id == "google_creative_4" ? document.getElementById("results_ad") : false;

					// Create the results ad.
					if ( results_box_ad )
						{	results_box_ad.innerHTML = 
								'<div class="googleAFSAds">' + 
									'<div class="ad_header">Sponsored Links</div>' + 
									ad_content[0] + 
								'</div>' + 
								results_box_ad.innerHTML;
						}; // if ( results_box_ad )

					// Get the place holder for the entry ads.
					var ad_container = document.getElementById(ad_id);

					if ( ad_container )
						{	// The remaining ad content.
							var content = "";

							// Create the remaining ad content.
							for ( var index = ad_id == "google_creative_4" ? 1 : 0; index < ad_content.length; index++ )
								{	content += ad_content[index];
								}; // for ( var index = ad_id == "google_creative_4" ? 1 : 0; index < ad_content.length; index++ )

							// Set the ad content.
							ad_container.innerHTML	= 
									( content != "" ?
										'<div class="googleAFSAds">' + 
											'<div class="ad_header">Sponsored Links</div>' + 
											content +
										'</div>'
										:
										'' 
									) + 
									ad_container.innerHTML;
						}; // if ( ad_container )
				} // function onAFSAdsLoaded (ads)
		}
	);

// This function handles all AFC load events.
function google_ad_request_done (afc_ads) 
	{	// Forward off to our ASF package.
		mw.ads.google.afc.onAFCAdsLoaded(afc_ads, google_ad_id);
	}; // function google_ad_request_done (afc_ads) 

// This function handles all AFS load events.
function google_afs_request_done (afs_ads) 
	{	// Forward off to our ASF package.
		mw.ads.google.afs.onAFSAdsLoaded(afs_ads, google_ad_id);
	}; // function google_afs_request_done (afs_ads) 


var google_ad_unit		= ""; //Note: The name of an ad unit ("rect" or "leaderboard")
var sRect				= ""; //Content of rect unit 
var sLead				= ""; //Content of leaderboard unit 
var creative_1_loaded	= false;
var creative_2_loaded	= false;
var creative_3_loaded	= false;
var creative_4_loaded	= false;


function google_write_ad (google_ads)
	{	// Get the number of ads returned.
		var google_num_ads = google_ads.length;

		// No ads returned.
	    if ( google_num_ads <= 0 ) 
			return "";

		// Return an image advertisement.
		if ( google_ads[0].type == "image" ) 
			{	// Get the ad values.
				var visible_url		= google_ads[0].visible_url;
				var ad_url			= google_ads[0].url;
				var image_url		= google_ads[0].image_url;
				var image_width		= Math.max(0, google_ads[0].image_width);
				var feedback_url	= google_info.feedback_url;

				// Construct the ad.
				var xhtml = 
					'<div class="creative image google">' + 
						'<div>' + 
							'<a href="' + ad_url + '" target="_top" title="go to ' + visible_url + '" onmouseover="javascript:window.status=\'Go to ' + visible_url + '\'; return true;" onmouseout="javascript:window.status=\'\'; return true;">' + 
								'<img border="0" src="' + image_url + '"  />' +
							'</a>' + 
						'</div>' + 
						'<table class="ads_by_google" border="0" cellpadding="2" cellspacing="0" style="width: ' + image_width + 'px;">' +
							'<tr>' +
								'<td style="text-align: left;"><a href="' + ad_url + '" onmouseover="javascript:window.status=\'Go to ' + visible_url + '\'; return true;" onmouseout="javascript:window.status=\'\'; return true;">Go to ' + visible_url + '</a></td>' +
								'<td style="text-align: right;"><a href="' + feedback_url + '">Feedback - Ads by Google</a></td>' + 
							'</tr>' +
						'</table>' 
					'</div>';

				return xhtml;
			} // if ( google_ads[0].type == "image" ) 

		// Return a Flash video advertisement.
		else if ( google_ads[0].type == "flash" ) 
			{  var xhtml =
					'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + google_ads[0].image_width + ' height="' + google_ads[0].image_height + '">' + 
						'<param name="movie" value="' + google_ads[0].image_url + '" />' + 
						'<param name="quality" value="high" />' + 
						'<param name="AllowScriptAccess" value="never" />' + 
						'<param name="google_hints" value="' + escape(token) + '" />' + 
						'<embed src="' + google_ads[0].image_url + '" width="' + google_ads[0].image_width + '" height="' + google_ads[0].image_height + '" type="application/x-shockwave-flash" AllowScriptAccess="never" pluginspace="http://www.macromedia.com/go/getflashplayer"></embed>' + 
					'</object>';

				try 
					{	if ( google_ad.image_url.indexOf('googleadplayer.swf') == -1 )
							{	var visible_url		= google_ads[0].visible_url;
								var ad_url			= google_ads[0].url;
								var image_url		= google_ads[0].image_url;
								var image_width		= Math.max(0, google_ads[0].image_width);
								var feedback_url	= google_info.feedback_url;
								xhtml += 
									'<table class="ads_by_google" border="0" cellpadding="2" cellspacing="0" style="width: ' + image_width + 'px;">' +
										'<tr>' +
											'<td style="text-align: left;"><a href="' + ad_url + '" onmouseover="javascript:window.status=\'Go to ' + visible_url + '\'; return true;" onmouseout="javascript:window.status=\'\'; return true;">Go to ' + visible_url + '</a></td>' +
											'<td style="text-align: right;"><a href="' + feedback_url + '">Feedback - Ads by Google</a></td>' + 
										'</tr>' +
									'</table>';
									/**
									'<table class="ads_by_google" border="0" cellpadding="2" cellspacing="0" style="width: ' + google_ads[0].image_width + 'px;">' + 
										'<tr>' +
											'<td style="text-align: left;"><a href="' + google_ads[0].url + '" onmouseover="javascript: window.status=\'Go to ' + google_ads[0].visible_url + '\'; return true;" onmouseout="javascript:window.status=\'\'; return true;">Go to ' + google_ads[0].visible_url + '</a></td>' + 
											'<td style="text-align: right;">Ads by Google</td>' + 
										'</tr>' +
									'</table>'; 
									**/
							}; // if ( google_ad.image_url.indexOf('googleadplayer.swf') == -1 )
					} // try

				catch (e)
					{
					}; // catch (e)

				return xhtml;
			} // else if ( google_ads[0].type == "flash" ) 

		// Return a leaderboard advertisement.
		else if ( google_ad_unit == "leaderboard" ) 
			{	var xhtml = 
					'<table width="728" height="90" cellpadding="0" cellspacing="0" border="0"><tr><td valign="middle" align="center">' +
					 '<a href="' + google_ads[0].url + '" ' +
                     'onmouseout="window.status=\'\'" ' +
                     'onmouseover="window.status=\'go to ' +
                     google_ads[0].visible_url + '\'" ' +
                     'style="text-decoration:none">' +
                     '<span style="text-decoration:underline;font-size:14pt">' +
                     '<b>' + google_ads[0].line1 + '</b><br></span>' +
                     '<span style="color:#000000;font-size:11pt">' +
                     google_ads[0].line2 + '&nbsp;' +
                     google_ads[0].line3 + '<br></span>' +
                     '<span style="text-decoration:underline;color:#000099;font-size:12pt">' +
                     google_ads[0].visible_url + '</span></a><br>' +
					 '</td></tr><tr><td bgcolor="336699" align="right">' +
	  				'<span style="font-size:10px;color:FFFFFF;font-family: verdana, tahoma, helvetica, sans-serif;">Ads by Google&nbsp;</span>'	+
					'</td></tr></table>';

				return xhtml;
			} // else if ( google_ad_unit == "leaderboard" ) 

		// Return text link advertisements.
		else 
			{	var xhtml = '<div class="header">Ads by Google</div>';

				// Append each text ad.
				for ( var i=0; i < google_ads.length; ++i ) 
					{	xhtml += 
							'<br />' + 
							'<a href="' + google_ads[i].url + '" ' + 
								'onmouseout="window.status=\'\'" ' +
								'onmouseover="window.status=\'go to ' + google_ads[i].visible_url + '\'" ' +
								'style="text-decoration:none">' +
								'<span style="text-decoration:underline;"><strong>' + google_ads[i].line1 + '</strong><br /></span>' +
								'<span style="color: #000000;" class="descr">' + google_ads[i].line2 + '&nbsp;' + google_ads[i].line3 + '<br /></span>' + 
								'<span style="text-decoration:underline;">' + google_ads[i].visible_url + '</span>' +
							'</a><br />';
					}; // for ( var i=0; i < google_ads.length; ++i ) 

				return xhtml;
			}; // else
	}; // function google_write_ad (google_ads)

function google_ad_request_done_10_06_2008 (google_ads) 
	{   var sLead = "";

		// No ads found.
		if ( google_ads.length < 1 ) 
			{	// document.write( "0 ads returned. <br>"); 
				if (google_ad_unit == "leaderboard")
					{	if ( !creative_2_loaded )
							{	if ( (document.location + "").indexOf("/thesaurus?") >= 0 )
									{	sLead = '<iframe id="tribal_leaderboard" src="/thes_leaderboard.html" border="0" frameborder="0" height="240" marginHeight="0" marginWidth="0" scrolling="no" width="728"></iframe>';				
									}
								else
									{	sLead = '<iframe id="tribal_leaderboard" src="/tribal_leaderboard.html" border="0" frameborder="0" height="240" marginHeight="0" marginWidth="0" scrolling="no" width="728"></iframe>';				
									}; // else
							}
						else 
							{	sLead = '<iframe id="tribal_leaderboard" src="/tribal_fusion_bottom.html" border="0" frameborder="0" height="240" marginHeight="0" marginWidth="0" scrolling="no" width="728"></iframe>';				
							}; // else 
					};
			} // if ( google_ads.length < 1 ) 
	
		// Google 3 unit wide ads.
		else if ( google_ad_unit == "rect" )
			{	var view = google_write_ad(google_ads);
		
				// Set the first creative.
				var creative = document.getElementById(google_ad_id);

				if ( creative )
					{	creative.innerHTML	= view;
					}; // if ( creative )	

				return;
			} // if ( google_ad_unit == "rect" )

		// Note: google_ad_unit is now "leaderboard"
		else 
			{	sLead = google_write_ad(google_ads);
			}; // else 

		// Set the 2nd or 3rd creative content.
		var creative = document.getElementById(!creative_2_loaded ? "google_creative_2" : "google_creative_3");
		if ( creative && sLead != "" )
			{	creative.innerHTML	= sLead + creative.innerHTML;
				if ( !creative_2_loaded )
					{	creative_2_loaded = true;
					} // if ( !creative_2_loaded )
				else
					{	creative_3_loaded = true;
					}; // else
			}; // if ( creative && sLead != "" )
};  // function google_ad_request_done (google_ads) 





