var google_adnum = 0;

function google_ad_request_done(google_ads) {
	/*
	 * This function is required and is used to display the ads that are
	 * returned from the JavaScript request. You should modify the
	 * document.write commands so that the HTML they write out fits with your
	 * desired ad layout.
	 */
	var s = '';
	var i;

	/*
	 * Verify that there are actually ads to display.
	 */
	if (google_ads.length == 0) {
		return;
	}


	/*
	 * 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.
	 */

	if (google_ads[0].type == "flash") {

		s += '<div class="sw_google_flash_ad">';

		s += '<a href=\"'
				+ google_info.feedback_url
				+ '\" class="sw_google_flash_ad_feedback_link" target="_blank">Google-Anzeigen</a> '
				+ '<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>';

		s += '</div>';

	} else if (google_ads[0].type == "image") {

		s += '<div class="sw_google_image_ad">';

		s += '<a href=\"'
				+ google_info.feedback_url
				+ '\" class="sw_google_image_ad_feedback_link" target="_blank">Google-Anzeigen</a> <a href="'
				+ google_ads[0].url
				+ '"  target="_blank" 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>';

		s += '</div>';

	} else if (google_ads[0].type == "html") {

		s += google_ads[0].snippet;

	} else { //adtype = text



		if (google_ads.length == 1) {

			/*
			 * Partners should adjust text sizes so ads occupy the majority of
			 * ad space.
			 */

			var headline_dynamic_resizing_style = '';
			var text_dynamic_resizing_style = '';
			var link_dynamic_resizing_style = '';
			if (sw_google_max_num_ads > 1) {
				headline_dynamic_resizing_style = 'sw_google_ad_headline_resize_1';
				text_dynamic_resizing_style = 'sw_google_ad_text_resize_1';
				link_dynamic_resizing_style = 'sw_google_ad_link_resize_1';
			}

			s += '<div class="sw_google_ad">';

			s += '<a href=\"'
					+ google_info.feedback_url
					+ '\" class="sw_google_ad_feedback_link sw_google_ad_feedback_link_single" target="_blank">Google-Anzeigen</a>';

			s += '<div class="sw_google_ad_content sw_google_ad_content_single">';

			if(sw_google_ad_bg_hover) {
				s += '<div onmouseover="this.style.backgroundColor = \'' + sw_google_ad_bg_hover + '\'" onmouseout="this.style.backgroundColor = \'transparent\'" style="padding:2px 0 7px 0;">';
			}

			s += '<a class="sw_google_ad_headline sw_google_ad_headline_single ' + headline_dynamic_resizing_style + '" href="'
					+ google_ads[0].url
					+ '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to '
					+ google_ads[0].visible_url
					+ '\';return true" target="_blank"> <span> <b>'
					+ google_ads[0].line1
					+ '</b><br></span></a>'

			var ad_link = '<span class="sw_google_ad_link sw_google_ad_link_single ' + link_dynamic_resizing_style + '"><a href="'
					+ google_ads[0].url
					+ '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to '
					+ google_ads[0].visible_url + '\';return true"  target="_blank">'
					+ google_ads[0].visible_url + '</span> </a> ';

			var ad_text = '<span class="sw_google_ad_text sw_google_ad_text_single ' + text_dynamic_resizing_style + '">'
					+ google_ads[0].line2
					+ '&nbsp;'
					+ google_ads[0].line3
					+ '</span>';

			// Link vor der Url
			if (!sw_google_ad_link_before) {
				s += ad_link;
				if(!sw_google_ad_link_inline) {
					s += '<br>';
				}
				s += ad_text;

			// Link nach der Url
			} else {
				s += ad_text;
				if(!sw_google_ad_link_inline) {
					s += '<br>';
									}
				s += ad_link;
			}

			if(sw_google_ad_bg_hover) {
				s += '</div>';
			}

			s += '</div>';

			s += '</div>';

			if (google_ads[0].bidtype == "CPC") { /* insert this snippet for each ad call */
				google_adnum = google_adnum + 1;
			}


		} else if (google_ads.length > 1) {


			s += '<div class="sw_google_ad">';

			s += '<a href=\"' + google_info.feedback_url + '\" class="sw_google_ad_feedback_link sw_google_ad_feedback_link_multi" target="_blank">Google-Anzeigen</a>'

			/*
			 * For text ads, append each ad to the string.
			 */

			s += '<div class="sw_google_ad_content sw_google_ad_content_multi">';

			var headline_dynamic_resizing_style = '';
			var text_dynamic_resizing_style = '';
			var link_dynamic_resizing_style = '';
			if (sw_google_max_num_ads >= 3 && google_ads.length < 3) {
				headline_dynamic_resizing_style = 'sw_google_ad_headline_resize_2';
				text_dynamic_resizing_style = 'sw_google_ad_text_resize_2';
				link_dynamic_resizing_style = 'sw_google_ad_link_resize_2';
			}

			for (i = 0; i < google_ads.length; ++i) {


				if(sw_google_ad_direction == 'horizontal') {
					itemwidth = Math.round(sw_google_ad_width / sw_google_max_num_ads);
					s += '<div style="width: ' + itemwidth + 'px; float: left;">';
				}
				else {
					s += '<div onmouseover="this.style.backgroundColor = \'' + sw_google_ad_bg_hover + '\'" onmouseout="this.style.backgroundColor = \'transparent\'" class="sw_google_ad_container_multi">';
					if(i > 0) { //dont do the BR here if it is the first ad because of "Google-Anzeigen" having display:block
						//s += '<br />';
					}
				}

				s += '<a class="sw_google_ad_headline sw_google_ad_headline_' + i + ' sw_google_ad_headline_multi ' + headline_dynamic_resizing_style + '" href="'
						+ google_ads[i].url
						+ '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to '
						+ google_ads[i].visible_url
						+ '\';return true" target="_blank"> <span> <b>'
						+ google_ads[i].line1
						+ '</b><br></span></a> '

				var ad_link = ' <span class="sw_google_ad_link sw_google_ad_link_' + i + ' sw_google_ad_link_multi ' + link_dynamic_resizing_style + '"><a href="'
						+ google_ads[i].url
						+ '" onmouseout="window.status=\'\'" onmouseover="window.status=\'go to '
						+ google_ads[i].visible_url + '\';return true" target="_blank">'
						+ google_ads[i].visible_url + ' </span> </a> ';

				var ad_text = ' <span class="sw_google_ad_text sw_google_ad_text_' + i + ' sw_google_ad_text_multi ' + text_dynamic_resizing_style + '">'
						+ google_ads[i].line2
						+ ' '
						+ google_ads[i].line3
						+ '</span>';

				// Link vor der Url
				if (!sw_google_ad_link_before) {
					s += ad_link;
					if(!sw_google_ad_link_inline) {
						s += '<br>';
					}
					s += ad_text;

				// Link nach der Url
				} else {
					s += ad_text;
					if(!sw_google_ad_link_inline) {
						s += '<br>';
					}
					s += ad_link;
				}

				//if(sw_google_ad_direction == 'horizontal') {
				s += '</div>';

				if (google_ads[i].bidtype == "CPC") { /* insert this snippet for each ad call */
					google_adnum = google_adnum + 1;
				}
			}

			s += '</div>';

			s += '</div>';
		}
	}

	document.write(s);
	return;
}

var sw_google_afs_bg_hover = '';
var sw_google_afs_bg = '';
var sw_google_afs_link_inline = false;
var sw_google_afs_link_before = false;

function google_afs_request_done(google_ads) {
	/*
	 * Verify that there are actually ads to display.
	 */
	var google_num_ads = google_ads.length;
	if (google_num_ads <= 0) {
		return;
	}

	var s = ""; // output
	var i = 0;

	var wideAds = "";   // wide ad unit html text
	var narrowAds = "";   // narrow ad unit html text

	var feedbacklink = "";

	// single ad
	if ( google_num_ads == 1 ) {
		feedbacklink = '<a ' +
			' href="https://www.google.com/adsense/support/bin/request.py?contact=afs_violation" ' +
			' class="sw_google_afs_feedback_link sw_google_afs_feedback_link_single" target="_blank">Google-Anzeigen</a>';

		if (google_ads[i].type=="text/wide") {

			var the_headline = '<a href="' + google_ads[i].url + '" class="sw_google_afs_headline sw_google_afs_headline_single">' + google_ads[i].line1 + '</a><br />';
			var the_link = '<span class="sw_google_afs_link"><a href="' + google_ads[i].url + '">' + google_ads[i].visible_url + '</a></span>';
			var the_text = '<span class="sw_google_afs_text">' + google_ads[i].line2 + '</span>';


			wideAds += '<div class="sw_google_afs_container_single sw_google_afs_container_wide" ' +
					' onmouseover="this.style.backgroundColor = \'' + sw_google_afs_bg_hover + '\'" ' +
					' onmouseout="this.style.backgroundColor = \'' + sw_google_afs_bg + '\'" ' +
					' style="background-color: ' + sw_google_afs_bg + ';" >' +
					the_headline;

			if ( !sw_google_afs_link_inline ) {
				the_link += '<br />';
			}
			if ( sw_google_afs_link_before ) {
				wideAds += the_link + ' ' + the_text;
			} else {
				wideAds += the_text + ' ' + the_link;
			}
			wideAds += '</div>';
		}

		// narrow ads
		else if (google_ads[i].type=="text/narrow") {
			var the_headline = '<a href="' + google_ads[i].url + '" class="sw_google_afs_headline sw_google_afs_headline_single">' + google_ads[i].line1 + '</a><br />';
			var the_link = '<span class="sw_google_afs_link"><a href="' + google_ads[i].url + '">' + google_ads[i].visible_url + '</a></span>';
			var the_text = '<span class="sw_google_afs_text">' + google_ads[i].line2 + '</span>';
			var the_text2 = '<span class="sw_google_afs_text2">' + google_ads[i].line3 + '</span>';


			narrowAds += '<div class="sw_google_afs_container_single sw_google_afs_container_narrow" ' +
					' onmouseover="this.style.backgroundColor = \'' + sw_google_afs_bg_hover + '\'" ' +
					' onmouseout="this.style.backgroundColor = \'' + sw_google_afs_bg + '\'" ' +
					' style="background-color: ' + sw_google_afs_bg + ';" >' +
					the_headline;

			if ( !sw_google_afs_link_inline ) {
				the_link += '<br />';
			}
			if ( sw_google_afs_link_before ) {
				narrowAds += the_link + ' ' + the_text + the_text2;
			} else {
				narrowAds += the_text + the_text2 + ' ' + the_link;
			}
			narrowAds += '</div>';
		} else {
		}

		if (wideAds != "") {
			wideAds = '<div class="sw_google_afs_content sw_google_afs_content_single sw_google_afs_content_wide" >'+wideAds+'</div>';
		}
		if (narrowAds != "") {
			narrowAds = '<div class="sw_google_afs_content sw_google_afs_content_single sw_google_afs_content_narrow" >'+narrowAds+'</div>';
		}
	}

	// multiple ads
	else if ( google_num_ads > 1 ) {

		feedbacklink = '<a ' +
			' href="https://www.google.com/adsense/support/bin/request.py?contact=afs_violation" ' +
			' class="sw_google_afs_feedback_link sw_google_afs_feedback_link_multi" target="_blank">Google-Anzeigen</a>';

		for(i = 0; i < google_num_ads; i++) {
			// wide ads
			if (google_ads[i].type=="text/wide") {
				var the_headline = '<a href="' + google_ads[i].url + '" class="sw_google_afs_headline">' + google_ads[i].line1 + '</a>';
				var the_link = '<span class="sw_google_afs_link"><a href="' + google_ads[i].url + '">' + google_ads[i].visible_url + '</a></span>';
				var the_text = '<span class="sw_google_afs_text">' + google_ads[i].line2 + '</span>';


				wideAds += '<div class="sw_google_afs_container_multi sw_google_afs_container_wide" ' +
						' onmouseover="this.style.backgroundColor = \'' + sw_google_afs_bg_hover + '\'" ' +
						' onmouseout="this.style.backgroundColor = \'' + sw_google_afs_bg + '\'" ' +
						' style="background-color: ' + sw_google_afs_bg + ';" >' +
						the_headline;

				if ( !sw_google_afs_link_inline ) {
					the_link += '<br />';
				}
				if ( sw_google_afs_link_before ) {
					wideAds += the_link + ' ' + the_text;
				} else {
					wideAds += the_text + ' ' + the_link;
				}
				wideAds += '</div>';
			}

			// narrow ads
			else if (google_ads[i].type=="text/narrow") {
				var the_headline = '<a href="' + google_ads[i].url + '" class="sw_google_afs_headline">' + google_ads[i].line1 + '</a>';
				var the_link = '<span class="sw_google_afs_link"><a href="' + google_ads[i].url + '">' + google_ads[i].visible_url + '</a></span>';
				var the_text = '<span class="sw_google_afs_text">' + google_ads[i].line2 + '</span>';
				var the_text2 = '<span class="sw_google_afs_text2">' + google_ads[i].line3 + '</span>';


				narrowAds += '<div class="sw_google_afs_container_multi sw_google_afs_container_narrow" ' +
						' onmouseover="this.style.backgroundColor = \'' + sw_google_afs_bg_hover + '\'" ' +
						' onmouseout="this.style.backgroundColor = \'' + sw_google_afs_bg + '\'" ' +
						' style="background-color: ' + sw_google_afs_bg + ';" >' +
						the_headline;

				if ( !sw_google_afs_link_inline ) {
					the_link += '<br />';
				}
				if ( sw_google_afs_link_before ) {
					narrowAds += the_link + ' ' + the_text + the_text2;
				} else {
					narrowAds += the_text + the_text2 + ' ' + the_link;
				}
				narrowAds += '</div>';
			} else {
			}
		}

		if (wideAds != "") {
			wideAds = '<div class="sw_google_afs_content sw_google_afs_content_multi sw_google_afs_content_wide" >'+wideAds+'</div>';
		}
		if (narrowAds != "") {
			narrowAds = '<div class="sw_google_afs_content sw_google_afs_content_multi sw_google_afs_content_narrow" >'+narrowAds+'</div>';
		}
	}

	s += '<div class="sw_google_afs">' + feedbacklink + wideAds + narrowAds + '</div>';
	document.write(s);
}

