// Google Ads

gAds = [];
gSkip = 0;

// Gads callback
function google_ad_request_done(ads) {
	if (ads.length == 0) {
		// We can inject third party ads here
		return;
	}

	if (ads[0].type == 'flash') {
	} else if (ads[0].type == 'image') {
	} else if (ads[0].type == 'html') {
	} else {
		// Text ads, the default
		for (i = 0; i < ads.length; i++) {
			gAds.push(ads[i]);
		}

		// Debug here
		// alert('Got back ' + gAds.length + ' Ads');
	}
}

// Get an ad from the stack
function get_ad() {
	if (gAds.length > 0) {
		ad = gAds[gSkip];
		gSkip = gSkip + 1;
		return (ad);
	}

	return(false);
}

// Format an ad for display
function display_ad(ad, join_lines) {
	if (!ad) {
		return (false);
	}

	var html;
	html  = '<div class="g_ad">';
	html += '<div class="g_ad_t"><a target="_new" href="' + ad.url + '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to ' + ad.visible_url + '\'; return true">' + ad.line1 + '</a></div>';
	html += '<div class="g_ad_d">';
	html += join_lines ? ad.line2 + ' ' + ad.line3 : ad.lin32 + '<br/>' + ad.line3;
	html += '</div>';
	html += '<div class="g_ad_u"><a target="_new" href="' + ad.url + '" onmouseout="window.status=\'\'" onmouseover="windowstatus=\'go to' + ad.visible_url + '\'; return true">' + ad.visible_url + '</a></div>'
	html += '</div>'; 

	return(html)
}

// Show a group of formatted ads
function display_ads(num, join_lines) {
	var i = 0;
	var html;

	html  = '<div class="g_info"><a href="' + google_info.feedback_url + '\">Ads by Google</a></div>';
	while (ad = get_ad()) {
		html += display_ad(ad, join_lines);
		i = i + 1;
		if (i >= num) {
			break;
		}
	}

	document.write(html);
}
