/**
 * @file: core::advertisings.js.part
 * @version: 2.1
 * @since: 2011-06-20
 */

/**
 * DEFINE GLOBAL VARS
 */
var readyAdvertisingsToLoad = new Array();		/* Array mit aktivierbaren ADV-Container */
var appLeaderboardAltContent = "";				/* Alternativer Inhalt für den Leaderboard, falls der Wallpaper geladen wird */
var appResizeInUse = false;						/* Flag für den DOM - WindowResize (endlosschleife wird dadurch unterbrochen) */
var appWallpaperType = false;					/* Flag / typ, damit der Wallpaper geladen wird */
var appPregameHideGame = false;					/* Flag, um das Spiel zu "muten" */
var appPregameTimer = false;					/* Object - PregameTimer */
var currentPregameTimerPositionCounter = 0;		/* TMP - TimerZeit */
var maxPregameContainerSize = 300;				/* Größe des Sliders */
var pregameAdvTimer = 10;						/* Zeit, nachdem das Spiel angezeigt wird */
var pregameAdvShowTimer = 3;					/* Zeit, nachdem der "Spiel direkt laden" Link angezeigt wird */
var pregameRefreshInterval = 1;					/* Interval zum aktualisieren des Timers (in Sekunden) */
var pregameAutoShowGame = true;					/* Flag, damit das Spiel nach Ablauf des Timers automatisch geladen wird */
var leaderboardTopDistance = null;				/* Abstand des Leaderboards vom topContent */

/**
 * function mf_wall_init
 * 
 * set wallpapers 
 * @req: (hi-media)
 * @related_params: mf_wall_x, mf_wall_y, mf_wall_center, appWallpaperType, mf_top_size
 */
var mf_wall_x = 363;
var mf_wall_y = 0;
var mf_wall_center = true;
var mf_top_size = 0;

function mf_wall_init(mf_topAd, mf_rightAd){
	mf_top_size = mf_topAd;
	appWallpaperType = "hi_media";
}

/**
 * function mf_wall_check
 * 
 * set wallpapers 
 * @req: (monetising-partners)
 * @related_params: appWallpaperType
 */
function mf_wall_check(){
	if (typeof(adtype) != 'undefined'){
		if (adtype == 'wallpaper'){
			// Schiebe Skyscraper rechtsbundig an Leaderboard
			appWallpaperType = "monpar";
		}
		if (adtype == 'expwallpaper') {
			// Schiebe Sky rechts unter das Leaderboard
			appWallpaperType = "monpar_ex";
		}
	}
	if (typeof(bgcolor) != 'undefined' && bgcolor != null){
		// Farbe mogliche Bereiche ein
		$("#fullcontent_container").css("background","#1E1E1E");
		$("#precontent_container").css("border-top",bgcolor);
		$("#fullcontent_container").animate({backgroundColor: bgcolor},3000);
	}
	if (typeof(bgimage) != 'undefined' && bgimage != null){
		// Setze Hintergrund Bild
	}
	if (typeof(adclick) != 'undefined' && adclick != null){
		// Verlinke bei Klick auf Hintergrund auf adclick
		/*$("#fullcontent_container").click(function() {
			window.open(adclick,"_blank");
		});*/
	}
}

/**
 * function app_setAdvertisingToLoad
 *
 * @related_params: readyAdvertisingsToLoad
 */
function app_setAdvertisingToLoad(advType){
	readyAdvertisingsToLoad[readyAdvertisingsToLoad.length] = advType;
	return true;
}

/**
 * Funktion, die die Werbungs Container aktiviert und der Reihe nach positioniert
 *
 */
function app_activateAdvertisingContainers(){
	mf_wall_check();
	/** check the window width + height for skyscraper **/
	app_checkWindowSizeForAdvertising();
	
	/* activate adv container - force all (maybe 'removing' elements) */
	app_reposAdvertisingRightSkyscraperContainer(true);
	app_reposAdvertisingLeftSkyscraperContainer(true);
	app_reposAdvertisingLeaderboardContainer(true);
	app_reposAdvertisingSquareContainer(true);
	app_reposAdvertisingRectangleContainer(true);
	
	app_reposAdvertisingPregameContainer();
	app_handlePregameAdvertising();
	return false;
}

/**
 * Funktion, die einen neuen Werbecontainer erstellt
 *
 */
function app_addAdvertisingContainer(advType,advContent){
	advContainerPhObj = $("#app_advertising_"+advType);
	placeholderContainerPhObj = $("#app_advertising_"+advType+"_ph");

	if (placeholderContainerPhObj.length == 0 || advContent == ""){
		return false;
	}

	/* append container to document, if it doesn't exists */
	if (advContainerPhObj.length == 0){
		advC = "<div id='app_advertising_"+advType+"'></div>";
		$("#advertising_load_area").append(advC);
		advContainerPhObj = $("#app_advertising_"+advType);
	}

	/* create tmp container ID */
	rCId = "rand_c_"+advType;
	document.writeln("<div id='"+rCId+"'>");
	eval(advContent);
	document.writeln("</div>");
	advContainerPhObj.append($("#"+rCId));

	//$("#square_outer_container").css("display","block");
	app_reposAdvertisingSquareContainer(true);
	return true;
}

/**
 * Funktion, die überprüft, ob Adv-Container vorhanden sind
 *
 */
function app_isAdvertisingAvailable(caT){
	for (ciP=0;ciP<readyAdvertisingsToLoad.length;ciP++){
		if (readyAdvertisingsToLoad[ciP] == caT){
			return true;
		}
	}
	return false;
}

/**
 * Funktion, die die Fenstergröße für Skyscraper links/rechts prüft
 *
 */
function app_checkWindowSizeForAdvertising(){
	if ($(window).width() < advertisingWindowSizeX){
		$("#app_advertising_skyscraper_right").remove();
		$("#app_advertising_skyscraper_left").remove();
		$("#content_container").removeClass();
		$("#precontent_container").removeClass();
	}
}


/**
 * Funktion, die einen bestimmten WerbungsContainer neupositioniert und ggf. aktiviert
 *
 */
function app_reposAdvertisingPhContainer(advContainerKey,activateContainer){
	advContainerPhObj = $("#"+advContainerKey);
	placeholderContainerPhObj = $("#"+advContainerKey+"_ph");

	if (advContainerPhObj.length == 0 || placeholderContainerPhObj.length == 0){
		return false;
	}
	
	advContainerPhObj.offset(placeholderContainerPhObj.offset());
	
	if (activateContainer && (!advContainerPhObj.is(':visible'))){
		advContainerPhObj.css("position","absolute");
		advContainerPhObj.fadeIn(2500);
	}
}

/**
 * Funktion zum anzeigen der Werbung "Rectangle"
 *
 */
function app_reposAdvertisingRectangleContainer(activateContainer){
	advContainerPhObj = $("#app_advertising_rectangle");
	placeholderContainerPhObj = $("#app_advertising_rectangle_ph");
	
	if (advContainerPhObj.length == 0 || placeholderContainerPhObj.length == 0 || advContainerPhObj.html() == ""){
		return false;
	}	
	
	advContainerPhObj.offset(placeholderContainerPhObj.offset());
	
	if (activateContainer && (!advContainerPhObj.is(':visible'))){
		advContainerPhObj.width(placeholderContainerPhObj.width());
		advContainerPhObj.css("position","absolute");
		advContainerPhObj.fadeIn(2500);
	}
}

/**
 * Funktion zum anzeigen der Werbung "Square"
 *
 */
function app_reposAdvertisingSquareContainer(activateContainer){
	advContainerPhObj = $("#app_advertising_square");
	placeholderContainerPhObj = $("#app_advertising_square_ph");
	
	if (advContainerPhObj.length == 0 || placeholderContainerPhObj.length == 0 || advContainerPhObj.html() == ""){
		$("#square_outer_container").css("display","none");
		return false;
	}
	
	advContainerPhObj.offset(placeholderContainerPhObj.offset());
	
	if (activateContainer && (!advContainerPhObj.is(':visible'))){
		advContainerPhObj.css("position","absolute");
		advContainerPhObj.fadeIn(2500);
	}
}

/**
 * Funktion zum anzeigen der Werbung "Skyscaper Rechts"
 *
 */
function app_reposAdvertisingRightSkyscraperContainer(activateContainer){
	advContainerObj = $("#app_advertising_skyscraper_right");
	contentContainer = $("#content_container");
	
	if (advContainerObj.length == 0){
		return true;
	}
	
	ccOffset = contentContainer.offset();
	ccOffset.left = ccOffset.left+contentContainer.width()+10;
	ccOffset.top = ccOffset.top+10;
	
	advContainerObj.offset(ccOffset);
	if (activateContainer && (!advContainerObj.is(':visible')) && (app_specialHandleForSkyscraper(appWallpaperType,advContainerObj))){
		advContainerObj.addClass("app_advertising_skyscraper");
		advContainerObj.css("position","absolute");
		advContainerObj.fadeIn(1500);
	}
}



/**
 * Funktion zum anzeigen der Werbung "Skyscaper Links"
 *
 */
function app_reposAdvertisingLeftSkyscraperContainer(activateContainer){
	advContainerObj = $("#app_advertising_skyscraper_left");
	contentContainer = $("#content_container");
	
	if (advContainerObj.length == 0){
		return true;
	}
	
	ccOffset = contentContainer.offset();
	ccOffset.left = ccOffset.left-180;
	ccOffset.top = ccOffset.top+10;
	
	advContainerObj.offset(ccOffset);
	if (activateContainer && (!advContainerObj.is(':visible')) && (!appWallpaperInit)){
		advContainerObj.addClass("app_advertising_skyscraper");
		advContainerObj.css("position","absolute");
		advContainerObj.fadeIn(1500);
	}else if(appWallpaperInit){
		/* stay */
	}
}

/**
 * Funktion, die den LeaderboardContainer neupositioniert und ggf. aktiviert
 * abhängig, ob ein wallpaper aktiviert ist
 *
 */
function app_reposAdvertisingLeaderboardContainer(activateContainer){
	advContainerPhObj = $("#app_advertising_leaderboard");
	placeholderContainerPhObj = $("#app_advertising_leaderboard_ph");

	if (advContainerPhObj.length == 0 || placeholderContainerPhObj.length == 0){
		return false;
	}

	/* check special handle for leaderboard */
	if(app_specialHandleForLeaderboard(appWallpaperType,advContainerPhObj)){
		/* do it only the first time */
		if (activateContainer){
			/* set distance for pageType */
			switch(currentPageType){
				case "game":
					if (leaderboardTopDistance === null){
						/* do nothing */
					}else if (leaderboardTopDistance < 15){
						$("#leaderboard_outer_container").children(".adv_info_text").appendTo("#leaderboard_outer_container");
						$("#leaderboard_outer_container").css("margin-top",leaderboardTopDistance);
					}else if (leaderboardTopDistance > 58){
						$("#leaderboard_outer_container").prependTo(".game__bottomLeftContainer");
						$("#leaderboard_outer_container").css("margin-top",(leaderboardTopDistance-58));
						$("#leaderboard_outer_container").css("margin-bottom",10);
					}else{
						$("#leaderboard_outer_container").css("margin-top",(leaderboardTopDistance-15));
					}
				break;
				case "home":
				case "category":
				case "search":
					if (leaderboardTopDistance === null){
						/* do not change */
					}else if(leaderboardTopDistance < 0){
						/*$("#leaderboard_outer_container").css("margin-top",0);*/
					}else{
						/*$("#leaderboard_outer_container").css("margin-top",leaderboardTopDistance);*/
					}
				break;
				default:
					/* do nothing */
				break;
			}
		}
		advContainerPhObj.offset(placeholderContainerPhObj.offset());
	}

	if (activateContainer && (!advContainerPhObj.is(':visible'))){
		advContainerPhObj.css("position","absolute");
		advContainerPhObj.fadeIn(1500);
	}
	return true;
}

/**
 * Funktion zum anzeigen der Werbung "Pregame"
 *
 */
function app_reposAdvertisingPregameContainer(reposContainerOnly){
	((!reposContainerOnly)?reposContainerOnly=false:null);
	
	advPregameContainer = $("#app_advertising_pregame");
	advPregamePhContainer = $("#app_advertising_pregame_ph");
	gameOverlay = $("#game_overlay_container");
	gameContainer = $("#game_content");
	gameBgContainer = $("#game_background_content");
	
	if (advPregameContainer.length == 0){
		return false;
	}
	
	/*
	 * DEPRECATED??? - check it!
	 * show game, if pregameContainer does not exist
	 */
	if (advPregameContainer.length == 0){
		gDim = getGameDimensions(true);
		gameContainer.width(gDim[0]);
		gameContainer.height(gDim[1]);
		
		gameContainer.css("clear","both");
		gameContainer.css("float","none");
		gameContainer.css("overflow","hidden");
		advPregamePhContainer.remove();
		
		/* toggle gameZoom */
		toggleGameZoom(showGameToggle);
		
		levelContainerControl("game");
		return false;
	}
	
	/* check movie-length, if existing */
	app_renewPregameTimer("hi_media");
		
	/* set pregame container position */
	apO = advPregamePhContainer.offset();
	
	/* browserhack, do not change! */
	if (apO){
		advPregameContainer.css("top",apO.top);
		advPregameContainer.css("left",apO.left);
	}
	if (reposContainerOnly){
		return true;
	}
	
	/* set pregame container dimensions */
	advPregameContainer.width(gameOverlay.width()-20); /* - 20 px :: pregameContainer has a 10px padding... */
	advPregameContainer.css("position","absolute");
	
	if (!advPregameContainer.is(':visible')){
		advPregameContainer.show();
	}	
		
	/* set gameContainer + gameBackgroundContainer to minimum! */	
	gameContainer.width(0);
	gameContainer.height(0);	
	gameBgContainer.width(0);
	gameBgContainer.height(0);
	
	/* 'mute' game */
	if (appPregameHideGame){
		gameContainer.hide();
		gameBgContainer.hide();
	}
	
	/* set fixed height for PregameAdvertisingContainer */
	if ((advPregameContainer.height()+20) < gameOverlay.height()){
		advPregameContainer.height(gameOverlay.height()-19);
	}
	
	/* set advertisingPlaceholderContainer height */
	advPregamePhContainer.height(advPregameContainer.height()+19); /* +19 px :: pregameContainer has a 10px padding, placeholder not... (but 1px border...) */
	
	/* reset gameArea */
	window.setTimeout("advPregamePhContainer.height(advPregameContainer.height()+19); checkPregameStateDiff();",110);
}


/**
 * Funktion zum abschalen der Werbung "Pregame" und anzeigen des Spiels
 *
 */
function app_showGame(){
	if (appPregameTimer){
		clearInterval(appPregameTimer);
		appPregameTimer = false;
	}
	
	gameContainer = $("#game_content");
	gameBgContainer = $("#game_background_content");
	advPregameContainer = $("#app_advertising_pregame");
	advPregamePhContainer = $("#app_advertising_pregame_ph");
	
	if (!gameContainer.is(':visible')){
		gameContainer.show();
		gameBgContainer.show();
	}
		
	gDim = getGameDimensions(true);
	
	gameBgContainer.width("");
	gameBgContainer.height("");
	
	gameContainer.width("");
	gameContainer.height("");
	gameContainer.css("clear","both");
	gameContainer.css("float","none");
	gameContainer.css("opacity","0");
	gameContainer.css("overflow","hidden");
	advPregamePhContainer.remove();
	
	/* toggle gameZoom */
	toggleGameZoom(showGameToggle);
	
	gameContainer.animate({opacity: 1},1000);
	advPregameContainer.fadeOut(1000);
	
	/* necessary, to do a smooth toggle on the pregame containers */
	cRes = app_reposAdvertisingLeaderboardContainer(true);
	if (cRes){
		window.setTimeout("checkPregameStateDiff();",100);
		window.setTimeout("checkPregameStateDiff();",120);
		window.setTimeout("checkPregameStateDiff();",200);
	}
}

/**
 * Funktion und Variablen, die den Countdown (Prozentsatz + Slider) der Werbung "Pregame" aktiviert
 *
 * zugehörige Parameter: appPregameTimer , currentPregameTimerPositionCounter, maxPregameContainerSize, pregameAdvShowTimer
 */
function app_handlePregameAdvertising(){
	pregameSlider = $("#pregame_slider");
	
	if (pregameSlider.length == 0){
		return false;
	}
	
	if (!appPregameTimer){
		pregameSlider.animate({width: maxPregameContainerSize, backgroundColor: "#46A7E8"},(pregameAdvTimer*1000));
		appPregameTimer = setInterval('app_handlePregameAdvertising()',(pregameRefreshInterval*1000));
	}
	
	if (currentPregameTimerPositionCounter <= (pregameAdvTimer)){
		currentContainerSize = Math.round(currentPregameTimerPositionCounter*(maxPregameContainerSize/pregameAdvTimer));
		$("#pregame_slider_text").html(Math.round((currentContainerSize/maxPregameContainerSize)*100)+" %");
	}else if(pregameAutoShowGame){
		app_showGame();
	}else{
		clearInterval(appPregameTimer);
		appPregameTimer = false;
	}
	
	if (currentPregameTimerPositionCounter >= pregameAdvShowTimer && pregameAdvShowTimer !== false){
		$("#pregame_wait_img").fadeOut(500);
		$("#pregame_show_link").fadeIn(1500);
		pregameAdvShowTimer = false;
	}
	currentPregameTimerPositionCounter += pregameRefreshInterval;
}

/**
 * Funktion, die spezielle Bedingungen überprüft, um ggf. den Wallpaper zu laden
 * @related_to: app_reposAdvertisingLeaderboardContainer
 */
function app_specialHandleForLeaderboard(adType,sh_advContainerPhObj,topSize){
	if (adType == false){
		return true;
	}
	
	switch (adType){
		case "hi_media":
			(!mf_top_size) ? mf_top_size=90 : null;
			(!topSize) ? topSize=mf_top_size : null;
			
			contentContainer = $("#content_container");
			contentContainer.animate({"padding-top": (mf_top_size + 25)},1500,function() {
				app_reposAllAdvertisingContainers();
			});
		
			ccOffset = contentContainer.offset();
			ccOffset.left = ccOffset.left+contentContainer.width()-728;
			ccOffset.top = 0;
			sh_advContainerPhObj.offset(ccOffset);
			sh_placeholderContainerPhObj = $("#app_advertising_leaderboard_ph");
			sh_placeholderContainerPhObj.html(appLeaderboardAltContent);
		break;
		case "monpar":
			/* continue 'normal' handle ... */
			return true;
		break;
		default:
			/* nothing to change */
		break;
	}
	return false;
}

/**
 * Funktion, die spezielle Bedingungen überprüft, um ggf. den Wallpaper zu laden
 * @related_to: app_reposAdvertisingSkyscraperRightContainer
 */
function app_specialHandleForSkyscraper(adType,sh_advContainerObj,topSize){
	if (adType == false){
		return true;
	}
	
	switch (adType){
		case "hi_media":
			sh_advContainerObj.html("");
			sh_advContainerObj.remove();
		break;
		case "monpar_ex":
			(!mf_top_size) ? mf_top_size=90 : null;
			(!topSize) ? topSize=mf_top_size : null;
		
			sh_advContainerObj.fadeIn(1500);
			
			/** this must be constant, otherwise it will not work correctly! **/
			
			app_shfs_topDistance = 25;
			app_shfs_leftMove = -728;
			
			app_shfs_Leaderboard = $("#hockeystick_leaderboard");
			app_shfs_Skyscraper = $("#hockeystick_skyscraper");
			
			app_shfs_Leaderboard.css("position","relative");
			app_shfs_Leaderboard.css("left",(app_shfs_leftMove+app_shfs_Skyscraper.width())+"px");
						
			contentContainer = $("#content_container");
			contentContainer.animate({"padding-top": (topSize + app_shfs_topDistance)},1500,function() {
				app_reposAllAdvertisingContainers();
			});
			
			return true;
		break;
		case "monpar":
			/** this must be constant, otherwise it will not work correctly! **/
			app_shfs_topDistance = 25;
			app_shfs_leftMove = -728;
			
			/** move contentContainer **/
			(!mf_top_size) ? mf_top_size=90 : null;
			(!topSize) ? topSize=mf_top_size : null;
			
			contentContainer = $("#content_container");
			contentContainer.animate({"padding-top": (mf_top_size + app_shfs_topDistance)},1500,function() {
				app_reposAllAdvertisingContainers();
			});
			
			/** move hockeystick_leaderboard **/
			app_shfs_Leaderboard = $("#hockeystick_leaderboard");
			app_shfs_Leaderboard.css("position","absolute");
			app_shfs_Leaderboard.css("left",app_shfs_leftMove+"px");
			return true;
		break;
		default:
			/* nothing to change */
		break;
	}
	return false;
}


/**
 * Funktion zum verändern von PregameParametern
 */
function app_setAdvertisingParam(setParam,setValue){
	(!setValue)? setValue=false : null;
	switch(setParam){
		case "pregameTimer":
			pregameAdvTimer = setValue;
		break;
		case "minPregameTimer":
			if (pregameAdvTimer < setValue){
				pregameAdvTimer = setValue;
			}			
		break;
		case "pregameAbortTimer":
			pregameAdvShowTimer = setValue;
		break;
		case "pregameRefreshInterval":
			pregameRefreshInterval = setValue;
		break;
		case "pregameMute":
			appPregameHideGame = true;
		break;
		case "pregameUnmute":
			appPregameHideGame = false;
		break;
		case "pregameIgnoreAutostart":
			pregameAutoShowGame = false;
		break;
		case "pregameForceAutostart":
			pregameAutoShowGame = true;
		break;
		case "leaderboardAltContent":
			appLeaderboardAltContent = setValue;
		break;
		case "wallpaperInit":
			appWallpaperInit = true;
			mf_top_size = setValue;
		break;
		case "wallpaperFor":
			appWallpaperType = setValue;
		break;
		case "wallpaperDistance":
			mf_top_size = setValue;
		break;
		case "leaderboardTopDistance":
			leaderboardTopDistance = setValue;
		break;
		case "pregameInnerAdsDefaults":
			app_setAdvertisingParam("minPregameTimer",13);
			app_setAdvertisingParam("pregameAbortTimer",false);
		break;
		case "pregame_MP_Video_Defaults":
			app_setAdvertisingParam("minPregameTimer",30);
			app_setAdvertisingParam("pregameAbortTimer",7);
			app_setAdvertisingParam("pregameMute",true);
			app_setAdvertisingParam("pregameIgnoreAutostart",true);
			if (setValue){
				app_setAdvertisingParam("pregameTimer",setValue);
			}
		break;
		case "preload":
			switch(setValue){
				case "mt_pregame":
				case "pregame_MP_Defaults":
					app_setAdvertisingParam("pregameMute");
					app_setAdvertisingParam("minPregameTimer",30);
				break;
				case "pregame_MP_Video_Defaults":
					app_setAdvertisingParam("minPregameTimer",30);
					app_setAdvertisingParam("pregameAbortTimer",7);
					app_setAdvertisingParam("pregameMute",true);
					app_setAdvertisingParam("pregameIgnoreAutostart",true);
					if (setValue){
						app_setAdvertisingParam("pregameTimer",setValue);
					}
				break;
			}
		break;
		default:
			return false;
		break;
	}
	return true;
}

/**
 * Funktion zum erneuern des Pregame Timers
 *
 */
function app_renewPregameTimer(pregameManType){
	elObjPregameContainer = $("#app_advertising_pregame_content");

	if (elObjPregameContainer.length == 0){
		return false;
	}

	switch (pregameManType){
		case "hi_media":
			/* abbrechen, wenn mf_videoAdVars nicht existiert */
			if (typeof mf_videoAdVars == 'undefined'){
				return false;
			}
			
			elTheNodeId = elObjPregameContainer.children("div:first-child").attr("id");
			if (!elTheNodeId){
				elTheNodeId = elObjPregameContainer.children("center").children("div:first-child").attr("id");
			}
			
			/* abbrechen, wenn NodeContainerId nicht existiert */
			if (!elTheNodeId){
				return false;
			}
			
			/* get currentObject from eval function */
			evalFnct = "currentVideoObject = mf_videoAdVars."+elTheNodeId;
			eval(evalFnct);

			if (!currentVideoObject){
				return false;
			}

			/* set videoLenght */
			newVideoLength = currentVideoObject.videoLength;
			if (newVideoLength > 0){
				app_setAdvertisingParam("pregameTimer",newVideoLength);
			}

			/* set videoSkipable */
			if (typeof currentVideoObject.videoSkippable != 'undefined'){
				if (!currentVideoObject.videoSkippable){
					app_setAdvertisingParam("pregameAbortTimer",false);
				}
			}

			/* mute game, it's a video ad */
			app_setAdvertisingParam("pregameMute");
		break;
		default:
			/* do nothing */
		break;
	}
}

/**
 * Funktion zum neu positionieren aller ADV-Container
 *
 */
function app_reposAllAdvertisingContainers(){
	app_toggleResizeInUse(true);
	for (cP=0;cP<readyAdvertisingsToLoad.length;cP++){
		switch(readyAdvertisingsToLoad[cP]){
			case 'app_advertising_skyscraper_right':
				app_reposAdvertisingRightSkyscraperContainer(false);
			break;
			case 'app_advertising_skyscraper_left':
				app_reposAdvertisingLeftSkyscraperContainer(false);
			break;
			case 'app_advertising_leaderboard':
				app_reposAdvertisingLeaderboardContainer(false);
			break;
			case 'app_advertising_rectangle':
				app_reposAdvertisingRectangleContainer(false);
			break;
			case 'app_advertising_square':
				app_reposAdvertisingSquareContainer(false);
			break;
			default:
				/** unknown containerType - do nothing **/
			break;
		}
	}
	/** only repos and not restart the container |true| **/
	app_reposAdvertisingPregameContainer(true);
	app_toggleResizeInUse(false);
}

/**
 * Funktion zum "ausser Kraft setzen" der AutoPositionierung der Werbungscontainer
 *
 */
function app_toggleResizeInUse(resizeStatus){
	appResizeInUse = resizeStatus;
	return true;
}

/**
 * Funktion zum setzen des Cookies für die Fenstergröße für die Skyscraper Rechts/Links
 *
 */
function app_handleAdvCookie(){	
	/** keine Fenstergröße gesetzt **/
	winSize = $(window).width();
		
	/** erste Bedingung: Größe null oder noch nicht festgelegt :: zweite Bedingung: Fenstergröße hat sich während der Sitzung verändert **/
	if ((advertisingWindowSize == "" || advertisingWindowSize == 0) || advertisingWindowSize != winSize){
		$.ajax({
			url: "/home/remote_set_windowsize/"+winSize,
			async: false
		});
	}
}

/**
 * handle window resize event
 *
 * @globals app_resizeInUse
 */
$(window).resize(function() {
  	if (!appResizeInUse){
		app_reposAllAdvertisingContainers();
	}
});

/**
 * handle after DOM events for adv
 */
afterDOMLoad("app_handleAdvCookie();");
afterDOMLoad("app_activateAdvertisingContainers();");
var dom_leaderboardFunction = "eId('app_advertising_leaderboard_ph').style.height=observedValue+'px'; app_reposAllAdvertisingContainers();";
afterDOMLoad("app_observeContainer('app_advertising_leaderboard','offsetHeight',dom_leaderboardFunction,true);");

/**
 * alt-leaderboard-target, if leaderboard is used for wallpaper
 */
app_setAdvertisingParam("<a href='http://www.kraloyun.com'><img src='http://cdn.kaisergames.de/www.kraloyun.com/images/alt_adv_leaderboard.jpg' alt='' /></a>");


