//	JavaScript Document
//	Function: Switch animated Gif's


	/****** CHANGES ONLY HERE: START ******/
	/*
		'Thementeaser' start on Thursday and (normally) are set to run one week
		Enddate can be the string "open", if no enddate is defined.
	*/
	
	/*
		Always set this to the real number of teasers!
		If more than one 'Thementeaser' should rotate, enter the same start and end date!
		Leave out leading zeroes in the dates! E.g. 02.01.2009 must be written as 2.2.2009!!!
	*/
	
	var images = 1;


	var teaser_0 = {nam: "HannahMontana2", start: "1.1.2009", end: "31.12.2019"};

	
	/****** CHANGES ONLY HERE: END ******/
	//	Date vars
	var currentDate  = new Date();
	var currentDay 	 = currentDate.getDate();
	/*var currentMonth = currentDate.getMonth();*/ // Caution: January is 0, not 1!
	var currentMonth = currentDate.getMonth()+1;
	var currentYear  = currentDate.getYear();
	//var currentYear  = currentDate.getFullYear();		
	
	var homeLocation;
	var resiHomeLoc     = false;
	var loungeHomeLoc   = false;
	var loungeProdLoc   = false;
	var currentImg;
	var imgStart;
	var imgEnd;
	var counter		= 0;

	/*** Residential: Start ******/
	var imgPath	= "/kundencenter/export/de/residential/resources_rs/gfx/teaser/right_teaser/r_teaser_hometv_top_";
	var imglink	= "http://www.alice.de/vod/";
	
	var topImage 	= document.getElementById("r_hometv_T_Img_top");		//|-->	kleiner Teaser rechts auf Unterseiten
	var topLink 	= document.getElementById("r_hometv_T_Link_top");		//|-->	Image Link
	var bottomLink 	= document.getElementById("r_hometv_T_Link_bottom");		//|-->	Button Link

	var hometeaserPath 	= "/kundencenter/export/de/residential/resources_rs/gfx/teaser/hometeaser/content/r_smallteaser_homeTV_video_";	//Teaser auf Startseite
	var infoLink		= "http://www.alice.de/vod/";	// Wert für Deepverlinkung in homeTV
	var orderLink		= "/kundencenter/export/de/residential/produkte/alice_fun/index.html?intcmp=hometv_teaser_start_";			// Link Button "Bestellen"

	var resihomeImage	= document.getElementById("homeTV_Image");
	var resihomeLink_Img	= document.getElementById("homeTV_Image_Link");
	var resihomeLink_Info	= document.getElementById("homeTV_Info_Link");
	var resihomeLink_Order	= document.getElementById("homeTV_Order_Link");
	/****** Residential: End ******/

	/****** Lounge:Start ******/
	var homeImgPath  = "/kundencenter/export/system/modules/de.hansenet.kc08/resources/residential/gfx/tsr/te/tsr_A/tsr_A_homeTV_";		//Teaser der Startseite
	//var homeImgLink  = "/kundencenter/IncludeStaticContent.do?selID=AL_TE";
	var homeImgLink  = "http://www.alice-dsl.de/vod/cm/catalogpage/32/Startseite.html";		
	var prodImgPath	 = "/kundencenter/export/system/modules/de.hansenet.kc08/resources/residential/gfx/tsr/te/tsr_B/tsr_B_homeTV_";		//Teaser in "Produkte & Optionen"
	//var prodImgLink	 = "/kundencenter/IncludeStaticContent.do?selID=AL_TE";
	var prodImgLink	 = "http://www.alice-dsl.de/vod/cm/catalogpage/32/Startseite.html";

	var homeAElement	= document.getElementById('tsr_1');
	var homeAElement_2	= document.getElementById('tsr_2');
	var homeAElement_3	= document.getElementById('tsr_0');

	var homeImage;
	var homeImage_2;
	var homeImage_3;
	var homeLink;
	var prodDivElement	= document.getElementById('tsr_B_OpthomeTV');
	var prodImage;
	var prodLink;
	
	var homeTVApp		= "false";
	if (typeof flashvars != 'undefined' && typeof flashvars.dynamicTeaser != 'undefined') {
		homeTVApp = flashvars.dynamicTeaser;
	}

	/****** Lounge: End ******/	
	
	/****** Teaser-Swtich für Residential Seiten ******/
	function switchTeaser_Resi (location) {
		if (location == "Residential") {
			topImage.src	= imgPath + [currentImg.nam] + ".gif";
			topLink.href	= imglink + "?intcmp=hometv_teaser_r_top_" + [currentImg.nam];
			bottomLink.href	= imglink + "?intcmp=hometv_teaser_r_top_" + [currentImg.nam];

			topLink.target="_blank";
			bottomLink.target="_blank";
		}
		else if (location == "Residential_Home") {
			resihomeImage.src	= hometeaserPath + [currentImg.nam] + ".gif";
			resihomeLink_Img.href	= infoLink + "?intcmp=hometv_teaser_start_" + [currentImg.nam];
			resihomeLink_Info.href	= infoLink + "?intcmp=hometv_teaser_start_" + [currentImg.nam];
			
			resihomeLink_Info.target = "_blank";	//|-->	open vod in its own window

			resihomeLink_Order.href	= orderLink +[currentImg.nam];
		}
	}
	
	/****** Teaser-Switch für Lounge Seiten *******/
	function switchTeaser_Lounge() {
		if (loungeHomeLoc) {
			homeImage[0].src  = homeImgPath + [currentImg.nam] + ".gif";
			// geaendert: &intcmp=... UND target blank hinzugefuegt
			homeAElement.href = homeImgLink + "?intcmp=tsr_A_homeTV_" + [currentImg.nam];
			homeAElement.target = "_blank";
			setTeaser();
		}
		else {
			prodImage[0].src = prodImgPath + [currentImg.nam] + ".gif";
			// geaendert: &intcmp=... UND target blank hinzugefuegt
			prodLink[0].href = prodImgLink + "?intcmp=tsr_B_homeTV_" + [currentImg.nam];
			prodLink[0].target = "_blank";
		}
	}

	/****** Teaser-Switch für Seiten mit homeTV-Applikation ******/
	function switchTeaser_homeTVApp () {
		if (flashvars.homeTVTeaser == "" || flashvars.homeTVTeaser == 'undefined') {
			flashvars.homeTVTeaser = currentImg.nam;
		}
		loadSWF();
	}

	
	
	/****** Switch Applikation ******/
	function switchImage () {
		//	set randum number based on the number of teasers
		var randNum = Math.round(0 + (images-1)*(Math.random()));
		var randNum = 0;
			
		//	create currentImg-object based on "teaser_" and randNum value
		currentImg = eval("teaser_"+randNum);
		imgStart = currentImg.start.split(".");
		
		if (currentImg.end != "open") {
			imgEnd = currentImg.end.split(".");
		}
		
		/*if (currentImg.end != "open") {
			//	split the date information of the currentImg into day, month and year
			imgEnd = currentImg.end.split(".");
			for (var i = 0; i < imgEnd.length; i++) {
				imgEnd[i] = parseInt(imgEnd[i]);
			}
		}*/
		
		if (topImage != null && topImage != 'undefined') {
			homeLocation = "Residential";
		}

		else if (resihomeImage != null && resihomeImage != 'undefined') {
			homeLocation = "Residential_Home";
			resiHomeLoc  = true;
		}

		else if (homeTVApp == 'true') {}

		else {
			homeLocation = "Lounge";
			
			if (prodDivElement != null && prodDivElement != 'undefined') {
				prodImage = prodDivElement.getElementsByTagName('img');
				prodLink  = prodDivElement.getElementsByTagName('a');
				
				loungeHomeLoc = false;
			}
			
			else if (homeAElement != null && homeAElement != 'null' && homeAElement != 'undefined') {
				homeImage = homeAElement.getElementsByTagName('img');
				homeImage_2 = homeAElement_2.getElementsByTagName('img');
				homeImage_3 = homeAElement_3.getElementsByTagName('img');
				
				loungeHomeLoc = true;
			}
			else {
				return;
			}
		}

		//	prüfe, ob enddatum des teasers definiert
		if (typeof(imgEnd) != "undefined") {
			if (currentMonth < imgEnd[1]  && imgStart[1] <= currentMonth) {
				//if (imgStart[0] <= currentDay) {
					if (homeLocation == "Residential" || homeLocation == "Residential_Home") {
						switchTeaser_Resi (homeLocation);
					}
					else if (homeTVApp == 'true') {
						switchTeaser_homeTVApp();
					}
					else {
						switchTeaser_Lounge();
					}
				//}
				/*else {
					//	switchImage();
					console.log('Starttag: '+imgStart[0]+' Aktueller Tag: '+currentDay);
				}*/
			}

			else if (currentMonth == imgEnd[1]) {
				if (imgStart[0] <= currentDay  && imgStart[1] <= currentMonth) {
					if (homeLocation == "Residential" || homeLocation == "Residential_Home") {
						switchTeaser_Resi (homeLocation);
					}
					else if (homeTVApp == 'true') {
						switchTeaser_homeTVApp ();
					}
					else {
						switchTeaser_Lounge();
					}

				}
			}
			
			else if (currentMonth == imgEnd[1] && currentDay <= imgEnd[0]) {
				if (imgStart[1] < currentMonth) {
					if (homeLocation == "Residential" || homeLocation == "Residential_Home") {
						switchTeaser_Resi (homeLocation);
					}
					else if (homeTVApp == 'true') {
						switchTeaser_homeTVApp ();
					}
					else {
						switchTeaser_Lounge();
					}

				}
				
				else if (imgStart[1] == currentMonth && imgStart[0] <= currentDay) {
					if (homeLocation == "Residential" || homeLocation == "Residential_Home") {
						switchTeaser_Resi (homeLocation);
					}
					else if (homeTVApp == 'true') {
						switchTeaser_homeTVApp ();
					}
					else {
						switchTeaser_Lounge();
					}
				}
				
				else {
					checkSystemDate(imgEnd[2], imgEnd[1], imgEnd[0]);
				}	
			}
			
			else {
				checkSystemDate(imgEnd[2], imgEnd[1], imgEnd[0]);
			}
		}
		
		else {
			checkSystemDate(imgEnd[2], imgEnd[1], imgEnd[0]);
		}
	}
		
	/*** Check Date to avoid script error ***/
	function checkSystemDate (year, month, day) {

		if (currentYear < year && currentMonth < month && currentDay < day) {
		//if (currentYear == year && currentMonth == month && currentDay == day) {
			switchImage();
		}
		else {
			counter++;
			if (counter <= 5) {
				switchImage();
			}
			else {
				return false;
			}
		}
	}
	
	
	/*** Set Teaser in Alice Lounge ***/
	function setTeaser () {

		/*** Before Login ***/
		if ((LoggedIn == false) || (typeof(LoggedIn)=='undefined')) {}
			
		/*** After Login ***/
		else {
			homeImgPath  = "/kundencenter/export/system/modules/de.hansenet.kc08/resources/residential/gfx/tsr/te/tsr_A/tsr_A_";
					
	
			/*** Teaser 1 (links) ***/

/*
			homeImage_3[0].src  = homeImgPath + "GW_oktoberfest.gif";
			homeAElement_3.href = "/kundencenter/IncludeStaticContent.do?selID=AL_AW_GW_WIESN";
			homeAElement_3.target = "_self";
			homeAElement_3.title = "Oktoberfest Gewinnspiel"; 
*/

			homeImage_3[0].src  = homeImgPath + "OptIntSec.gif"; 
			homeAElement_3.href = "IncludeStaticContent.do?includeurl=%2Fkundencenter%2Fexport%2Fde%2Fal%2Fpo%2Foptionen%2Fsicherheit%2Finetsec%2Findex.html&selID=AL_POR_OP";
			homeAElement_3.title = "Option Internet Security";
			homeAElement_3.target = "_self";


			/*** Teaser 2 (mitte) ***/
			/* Teaser mitte */
			homeImage[0].src  = homeImgPath + 'homeTV_' + [currentImg.nam] + ".gif";
			homeAElement.href = homeImgLink + "&intcmp=tsr_A_homeTV_" + [currentImg.nam];
			homeAElement.target = "_self";
			homeAElement.title = "Klicken Sie hier für 'TV & Movies'!"; 
			
			/*** Teaser 3 (rechts) ***/
/*
			homeImage_2[0].src  = homeImgPath + "skins123.gif";
			homeAElement_2.href = "http://alice.123skins.de/de/index.html";
			homeAElement_2.target = "_blank";
			homeAElement_2.title = "Skins 123";
*/

			homeImage_2[0].src  = homeImgPath + "KWK_normal.gif"; 
			homeAElement_2.href = "/selfcare/content/segment/kundencenter/alicewelt/kundenwerbenkunden/";
			homeAElement_2.title = "Kunden werben Kunden";

/*
			homeImage_2[0].src  = homeImgPath + "OptIntSec.gif"; 
			homeAElement_2.href = "IncludeStaticContent.do?includeurl=%2Fkundencenter%2Fexport%2Fde%2Fal%2Fpo%2Foptionen%2Fsicherheit%2Finetsec%2Findex.html&selID=AL_POR_OP";
			homeAElement_2.title = "Option Internet Security";
			homeAElement_2.target = "_self";
*/
			
			
			/* Teaser, die nur für Mobile Basic Kunden gelten */
			moImgPath  = "/kundencenter/export/system/modules/de.hansenet.kc08/resources/mobileonly/gfx/tsr/tsr_A/tsr_A_";
			
			if(MobileOnly && (MobileOnly == true)) {
				
				/* Teaser links */
				homeImage_3[0].src  = homeImgPath + "skins123.gif";
				homeAElement_3.href = "http://alice.123skins.de/de/index.html";
				homeAElement_3.target = "_blank";
				homeAElement_3.title = "Skins 123";

				/* Teaser mitte */
				homeImage[0].src  = moImgPath + "bedienungsanleitung.gif"; 
				homeAElement.href = "/kundencenter/export/de/download/anleitungen/privatkunden_anleitungen/option_mobile/bedienungsanleitung.pdf?intcmp=tsr_B_Mobilfunk";
				homeAElement.target = "_blank";
				homeAElement.title = "Klicken Sie hier für das PDF mit der Bedienungsanleitung!";

				/* Teaser rechts*/
				homeImage_2[0].src  = moImgPath + "rufnummernmitnahme.gif"; 
				homeAElement_2.href = "/kundencenter/export/de/download/anleitungen/privatkunden_anleitungen/option_mobile/rufnummernportierung_info.pdf?intcmp=tsr_B_Mobilfunk";
				homeAElement_2.target = "_blank";
				homeAElement_2.title = "Klicken Sie hier für unser das PDF zur Rufnummernportierung!";
/*				
				homeImage_2[0].src  = homeImgPath + "anno1404_august.gif";
				homeAElement_2.href = "/kundencenter/IncludeStaticContent.do?selID=AL_AW_GW_ANNO";
				homeAElement_2.target = "_self";
				homeAElement_2.title = "ANNO 1404 Gewinnspiel";  
 */
				/* homeImage_2[0].alt= ""; */
			}
			
		}
	}
switchImage();