﻿function google_flash_ad(google_ads) {
	var ad =
		'<a href=\"' + google_info.feedback_url + '\" style="color:000000">Ads by Google</a><br/>' +
		'<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_ad.image_width + '" height="' +
		google_ad.image_height + '"> <param name="movie" value="' +
		google_ad.image_url + '">' +
		'<param name="quality" value="high">' +
		'<param name="AllowScriptAccess" value="never">' +
		'<embed src="' +
		google_ad.image_url + '" width="' +
		google_ad.image_width + '" height="' +
		google_ad.image_height +
		'" type="application/x-shockwave-flash"' +
		' AllowScriptAccess="never" ' +
		' pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>';

	return ad;
}

function google_image_ad(google_ads) {
	var ad =
		'<a href=\"' + google_info.feedback_url + '\" style="color:000000">Ads by Google</a><br/>' +
		'<a href="' +
		google_ads[0].url + '" target="_top" title="go to ' +
		google_ads[0].visible_url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' +
		google_ads[0].visible_url + '\';return true"><img border="0" src="' +
		google_ads[0].image_url + '"width="' +
		google_ads[0].image_width + '"height="' +
		google_ads[0].image_height + '"></a>';

	return ad;
}

function google_ad_request_done(google_ads) {

	// Verify that there are actually ads to display.
	if (google_ads.length == 0) {
		return;
	}

	var html = "";
	
	// If an image or flash ad is returned, display that ad.
	// Otherwise, build a string containing all of the ads and
	// then use a document.write() command to print that string.
	switch (google_ads[0].type) {
		case "flash":
			html = google_flash_ad(google_ads)
			break;
		case "image":
			html = google_image_ad(google_ads)
			break;
		case "html":
			html = google_ads[0].snippet;
			break;
		default:
			if (google_ads.length == 1)	{ 

				html += '<div>';

				for(i = 0; i < google_ads.length; ++i) {
						html += '<div class="AdContainer' + (i == 0 ? "" : "") +'">' +
						'<div><a class="AdTitle" href="' + google_ads[i].url + '">' + google_ads[i].line1 + '</a><a class="AdLink" href="' +google_ads[i].url + '">' + google_ads[i].visible_url + '</a></div>' + 
						'<span class="AdText">' + google_ads[i].line2 + '&nbsp;' + google_ads[i].line3 + '</span>'+
						'</div>';
				}
				
				html += '<div class="AdBy"><a href=\"' + google_info.feedback_url + '\">Ads by Google</a></div><div style="clear:left;"></div></div>';
				
			} else if (google_ads.length > 1) {
						
				html += '<div>';

				for(i = 0; i < google_ads.length; ++i) {
						html += '<div class="AdContainer' + (i == 0 ? "" : "") +'">' +
						'<div><a class="AdTitle" href="' + google_ads[i].url + '">' + google_ads[i].line1 + '</a><a class="AdLink" href="' +google_ads[i].url + '">' + google_ads[i].visible_url + '</a></div>' + 
						'<span class="AdText">' + google_ads[i].line2 + '&nbsp;' + google_ads[i].line3 + '</span>'+
						'</div>';
				}
				
				html += '<div class="AdBy"><a href=\"' + google_info.feedback_url + '\">Ads by Google</a></div><div style="clear:left;"></div></div>';
			}
		break;
	}

	document.write(html);
}

