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_afs_request_done(google_ads) {
sLead = "";
    /*
     * Verify that there are actually ads to display.
     */	 
    var google_num_ads = google_ads.length;
    if (google_num_ads <= 0) 
      return;

    var wideAds = "";   //wide ad unit html text
    var narrowAds = "";   //narrow ad unit html text
 
    for(i = 0; i < google_num_ads; i++){
      if (google_ads[i].type=="text/wide"){  
      //** render a wide ad
        wideAds+='<span class="ad_line1">' +
                 '<a onmouseover="javascript:window.status=\'' + 
                 google_ads[i].visible_url + '\';return true;" ' +
                 'onmouseout="javascript:window.status=\'\';return true;" ' +
                 'href="' + google_ads[i].url + '">' + 
		 google_ads[i].line1 + '</a></span><br />';
        wideAds+='<span class="ad_text">' + 
			'<a onmouseover="javascript:window.status=\'' + 
                 google_ads[i].visible_url + '\';return true;" ' +
                 'onmouseout="javascript:window.status=\'\';return true;" ' +
                 'href="' + google_ads[i].url + '">' + 
				google_ads[i].line2 + '</a></span><br />';
        wideAds+='<div class="ad_url">' + 
			'<a onmouseover="javascript:window.status=\'' + 
                 google_ads[i].visible_url + '\';return true;" ' +
                 'onmouseout="javascript:window.status=\'\';return true;" ' +
                 'href="' + google_ads[i].url + '">' +
				google_ads[i].visible_url + '</a></div>';
      } else {
        //render a narrow ad
        narrowAds+='<span class="ad_line1">' +
                 '<a onmouseover="javascript:window.status=\'' + 
                 google_ads[i].visible_url + '\';return true;" ' +
                 'onmouseout="javascript:window.status=\'\';return true;" ' +
                 'href="' + google_ads[i].url + '">' + 
                 google_ads[i].line1 + '</a></span><br>';
        narrowAds+='<span class="ad_text">' + 
			'<a onmouseover="javascript:window.status=\'' + 
                 google_ads[i].visible_url + '\';return true;" ' +
                 'onmouseout="javascript:window.status=\'\';return true;" ' +
                 'href="' + google_ads[i].url + '">' + 
			google_ads[i].line2 + '</a></span><br>';
        narrowAds+='<span class="ad_text">' + 
			'<a onmouseover="javascript:window.status=\'' + 
                 google_ads[i].visible_url + '\';return true;" ' +
                 'onmouseout="javascript:window.status=\'\';return true;" ' +
                 'href="' + google_ads[i].url + '">' + google_ads[i].line3 + '</a></span><br>';
        narrowAds+='<div class="ad_url">' + 
			'<a onmouseover="javascript:window.status=\'' + 
                 google_ads[i].visible_url + '\';return true;" ' +
                 'onmouseout="javascript:window.status=\'\';return true;" ' +
                 'href="' + google_ads[i].url + '">' + google_ads[i].visible_url + '</a></div>';
      }
    }
    if (narrowAds != "") {
      narrowAds = '<div class="ad_header" style="color: #999999; text-align:left">' +
                  'Sponsored Links</div>' + narrowAds;
    }
    if (wideAds != "") {
      wideAds = '<div class="ad_header" style="color: #999999; text-align:left">' +
                      'Sponsored Links</div>' + wideAds;
    }

    //** Write HTML for wide and narrow ads to the proper <div> elements
    //document.getElementById("wide_ad_unit").innerHTML = wideAds;
    //document.getElementById("narrow_ad_unit").innerHTML = narrowAds;

	sLead = wideAds;

	// Set the 2nd or 3rd creative content.
	var creative = document.getElementById("google_creative_4");
	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_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(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




