/*
	Sample script for SOI ad integration
*/
window.myAd = {
	loadScript: function(which) {
			if (!window.SOI_WERBUNG) return;

			var site_script = 'Fem/testedichde.js';

			var src = '';
			switch (which) {
				case 'global':
					src = 'http://adserver.71i.de/global_js/globalV6.js';
					break;
				case 'site':
					if (site_script) src = 'http://adserver.71i.de/global_js/Sites/' + site_script;
					break;
			}
			if (!src) return;

			document.write('<script src="' + src + '" type="text/javascript"><\/script>');
		},
	insertAd: function(ad_id) {
			if (!window.SOI_WERBUNG) return;
			if (!window.SoiAd) return;

			var go = false;
			switch (ad_id) {
				case 'popup1':
					go = window.SOI_PU1;
					break;
				case 'fullbanner2':
					go = window.SOI_FB2;
					break;
				case 'skyscraper1':
					go = window.SOI_SC1;
					break;
				case 'rectangle1':
					go = window.SOI_RT1;
					break;
			}
			if (!go) return;

			SoiAd.write(ad_id);
		},
	finishAd: function(ad_id, mode) {
			switch (mode) {
				case 'move':
					this.moveAd(ad_id);
					break;
			}

			this.adjustLayoutForAd(ad_id, mode);
		},
	moveAd: function(ad_id) {
			if (!window.SOI_WERBUNG) return;
			if (!window.SoiAd) return;

			SoiAd.moveAd(ad_id, 'ad-' + ad_id + '-postponed', 'ad-' + ad_id);
		},
	adjustLayoutForAd: function(ad_id, mode) {
			var container = document.getElementById('ad-' + ad_id);
			if (!container) return;

			var exists = window.SoiAd ? SoiAd.exists(ad_id) : false;

			if (exists) {
				// Let class-defined styles win.
				SoiAd.removeStyleAttribute(container);

				if (SoiAd.reserveSowefoSpace(ad_id)) {
					container.style.backgroundColor = 'transparent';
					container.style.backgroundImage = 'none';
					container.style.borderColor     = 'transparent';
				}
				else if (SoiAd.isBlockpixel(ad_id)) {
					container.style.display = 'none';
				}
			}

			if (ad_id == 'popup1') {
				if (exists) {
					var is_powercurtain = SoiAd.isPowercurtain(ad_id);
					if (is_powercurtain) SoiAd.setAutoHeight(ad_id, 'ad-' + ad_id);
				}
				else {
					// May insert fallback into container 'ad-' + ad_id
					// If so, the style attribute (display, visibility) must be removed via:
					// SoiAd.removeStyleAttribute(container);
				}
			}
			else {
				var width  = 0;
				var height = 0;

				if (exists) {
					width  = SoiAd.getWidth(ad_id);
					height = SoiAd.getHeight(ad_id);
				}

				if (ad_id == 'fullbanner2') {
					if (exists) {
						var is_powerbanner = SoiAd.isPowerbanner(ad_id);
						var is_pushdown    = SoiAd.isPushdown(ad_id);
						var is_wallpaper   = SoiAd.isWallpaper(ad_id);

						if (is_pushdown || is_powerbanner) {
							SoiAd.setAutoHeight(ad_id, 'ad-' + ad_id);
						}
						else if (is_wallpaper) {
							container.style.height = '90px';
						}
						else if (width && width != 728) {
							// May be disabled
							container.style.left = (137 + 728 - width) + 'px';
						}
					}
					else {
						// May insert fallback into container 'ad-' + ad_id
						// See comment for popup1 case
					}
				}
				else if (ad_id == 'rectangle1') {
					if (exists) {
						var is_halfpage = SoiAd.isHalfpage(ad_id);
						if (is_halfpage) SoiAd.setAutoHeight(ad_id, 'ad-' + ad_id);
					}
					else {
						container.style.display = 'none';
						// May insert fallback into container 'ad-' + ad_id
						// See comment for popup1 case
						// Do not set display to 'none', if fallback content is inserted.
					}
				}
				else if (ad_id == 'skyscraper1') {
					if (exists) {
						if (width && width > 160) {
							container.style.width = width + 'px';
						}
					}
					else {
						// May insert fallback into container 'ad-' + ad_id
						// See comment for popup1 case
					}
				}
			}
		}
};
