/*!
 * JavaScript Functions
 */

//Initialize or update cookie
var kcookie = new HashCookie('kdc', 30*24*60*60*1000);
ready = 0;

// Scroll Variablen initialisieren
var teaserName = '#teaserTool';
var scrollYloc = null;
var teaserXYloc = null;
var scrollConst = null;
var footerXYloc = null;
var teaserHeight = null;
var scrollTop = null;
var scroll = null;

// Document Ready Funktion
$(document).ready(function() {

	//Frameblocker
	if (self.name != 'view_frame'){
		if (top.location != self.location) {
			top.location = self.location;
		}
	}

	//Initialize accordion7GStatic
	$('.accordion7GStatic').accordion({
		active: 0,
		autoHeight: true,
		header: "h3"
	});

	//Initialize accordionStatic
	$('.accordionStatic').accordion({
		active: 0,
		autoHeight: true,
		header: "h3"
	});
	
		//Initialize accordionStatic
	$('.accordionStaticBox').accordion({
		active: 0,
		autoHeight: true,
		header: "h3"
	});

	//Initialize accordionLarge
	$('.accordionLarge').accordion({
		active: 0,
		autoHeight: false,
		header: "h3"
	});
	
	//Initialize accordionFaq
	$('.accordionFaq').accordion({
		active: false,
		autoHeight: false,
		header: "h3"
	});

	//if VP is done, change VP Accordion
	if(kcookie.get('KabelAnschluss') == 'Ja' || kcookie.get('KabelDigital') == 'Ja' || kcookie.get('InternetPhone') == 'Ja'){
		$('#accordionContentVPStep1').hide();
		$('#accordionContentVPStep1').css('height', '0px');
		var userDetails = "";
		if(kcookie.get("PLZ") && kcookie.get("Ort") && kcookie.get("Strasse") && kcookie.get("Hausnummer"))
			userDetails = kcookie.get("PLZ") + " " + kcookie.get("Ort") + ", " + kcookie.get("Strasse") + " " + kcookie.get("Hausnummer");
		$('#vpAdress').html(userDetails);
		
		if(kcookie.get('KabelAnschluss') != 'Ja'){
			$('#vpProductAnschluss').find('.vpStatusIcon').attr('src', '/static/img/lay_vp_small_status_na.gif');
			$('#vpProductAnschluss').find('.vpBestellen').hide();
		}
		if(kcookie.get('KabelDigital') != 'Ja'){
			$('#vpProductDigital').find('.vpStatusIcon').attr('src', '/static/img/lay_vp_small_status_na.gif');
			$('#vpProductDigital').find('.vpBestellen').hide();
		}
		if(kcookie.get('InternetPhone') != 'Ja'){
			$('#vpProductPhone').find('.vpStatusIcon').attr('src', '/static/img/lay_vp_small_status_na.gif');
			$('#vpProductPhone').find('.vpBestellen').hide();
		}
		$('#accordionContentVPStep2').show();
	}
	
	//Get start tab for accordion
	var accordionStartTab = 0;	
	if($("input[name='accordionStartTab']").val() > 0) {
		accordionStartTab = ($("input[name='accordionStartTab']").val() - 1);
	}
	else if($("input[name='accordionStartTab']").val() == 0) {
		accordionStartTab = false;
	}

	//Initialize accordion
	$('.accordion').accordion({
		active: accordionStartTab,
		autoHeight: false,
		header: "h3"
	});
	
	//Initialize accordion for Docsis
	$('.accordionDocsis').accordion({
		active: false,
		autoHeight: false,
		collapsible: true,
		header: "h3"
	});
		
	//Initialize slideToggle Flyout
	var activeFlyout = 0;
	var overNaviItem = 0;
	
	activeMenuItemId = $("#mainnavi").find(".active").attr("id");
	
	$("#naviItem1").hover(
		function() {
			overNaviItem = 1;
			if(activeFlyout != 1){
				activeFlyout = 1;
				$("#naviItem1").addClass("active");
				delay = setTimeout(function(){
					if(overNaviItem == 1)
						$("#flyout1").slideDown(300);
				}, 300);
			}
			else{
				clearTimeout(delay);
				activeFlyout = 1;
			}
		},
		function() {
			overNaviItem = 0;
			delay = setTimeout(function(){
					$("#flyout1").slideUp(200, function(){
						activeFlyout = 0;
						if(activeMenuItemId != $("#naviItem1").attr("id"))
							$("#naviItem1").removeClass("active");});
			}, 100);
		}
	);
	$("#flyout1").hover(
		function() {
			clearTimeout(delay);
			activeFlyout = 1;
		},
		function() {
			delay = setTimeout(function(){
					$("#flyout1").slideUp(200, function(){
						activeFlyout = 0;
						if(activeMenuItemId != $("#naviItem1").attr("id"))
							$("#naviItem1").removeClass("active");});
			}, 100);
		}
	);
	
	$("#naviItem2").hover(
		function() {
			overNaviItem = 2;
			if(activeFlyout != 2){
				activeFlyout = 2;
				$("#naviItem2").addClass("active");
				delay = setTimeout(function(){
					if(overNaviItem == 2)
						$("#flyout2").slideDown(300);
				}, 300);
			}
			else{
				clearTimeout(delay);
				activeFlyout = 2;
			}
		},
		function() {
			overNaviItem = 0;
			delay = setTimeout(function(){
					$("#flyout2").slideUp(200, function(){
						activeFlyout = 0;
						if(activeMenuItemId != $("#naviItem2").attr("id"))
							$("#naviItem2").removeClass("active");});
			}, 100);
		}
	);
	$("#flyout2").hover(
		function() {
			clearTimeout(delay);
			activeFlyout = 2;
		},
		function() {
			delay = setTimeout(function(){
					$("#flyout2").slideUp(200, function(){
						activeFlyout = 0;
						if(activeMenuItemId != $("#naviItem2").attr("id"))
							$("#naviItem2").removeClass("active");});
			}, 100);
		}
	);
	
	$("#naviItem3").hover(
		function() {
			overNaviItem = 3;
			if(activeFlyout != 3){
				activeFlyout = 3;
				$("#naviItem3").addClass("active");
				delay = setTimeout(function(){
					if(overNaviItem == 3)
						$("#flyout3").slideDown(300);
				}, 300);
			}
			else{
				clearTimeout(delay);
				activeFlyout = 3;
			}
		},
		function() {
			overNaviItem = 0;
			delay = setTimeout(function(){
					$("#flyout3").slideUp(200, function(){
						activeFlyout = 0;
						if(activeMenuItemId != $("#naviItem3").attr("id"))
							$("#naviItem3").removeClass("active");});
			}, 100);
		}
	);
	$("#flyout3").hover(
		function() {
			clearTimeout(delay);
			activeFlyout = 3;
		},
		function() {
			delay = setTimeout(function(){
					$("#flyout3").slideUp(200, function(){
						activeFlyout = 0;
						if(activeMenuItemId != $("#naviItem3").attr("id"))
							$("#naviItem3").removeClass("active");});
			}, 100);
		}
	);
	
	$("#naviItem4").hover(
		function() {
			overNaviItem = 4;
			if(activeFlyout != 4){
				activeFlyout = 4;
				$("#naviItem4").addClass("active");
				delay = setTimeout(function(){
					if(overNaviItem == 4)
						$("#flyout4").slideDown(300);
				}, 300);
			}
			else{
				clearTimeout(delay);
				activeFlyout = 4;
			}
		},
		function() {
			overNaviItem = 0;
			delay = setTimeout(function(){
					$("#flyout4").slideUp(200, function(){
						activeFlyout = 0;
						if(activeMenuItemId != $("#naviItem4").attr("id"))
							$("#naviItem4").removeClass("active");});
			}, 100);
		}
	);
	$("#flyout4").hover(
		function() {
			clearTimeout(delay);
			activeFlyout = 4;
		},
		function() {
			delay = setTimeout(function(){
					$("#flyout4").slideUp(200, function(){
						activeFlyout = 0;
						if(activeMenuItemId != $("#naviItem4").attr("id"))
							$("#naviItem4").removeClass("active");});
			}, 100);
		}
	);
	
	$("#naviItem5").hover(
		function() {
			overNaviItem = 5;
			if(activeFlyout != 5){
				activeFlyout = 5;
				$("#naviItem5").addClass("active");
				delay = setTimeout(function(){
					if(overNaviItem == 5)
						$("#flyout5").slideDown(300);
				}, 300);
			}
			else{
				clearTimeout(delay);
				activeFlyout = 5;
			}
		},
		function() {
			overNaviItem = 0;
			delay = setTimeout(function(){
					$("#flyout5").slideUp(200, function(){
						activeFlyout = 0;
						if(activeMenuItemId != $("#naviItem5").attr("id"))
							$("#naviItem5").removeClass("active");});
			}, 100);
		}
	);
	$("#flyout5").hover(
		function() {
			clearTimeout(delay);
			activeFlyout = 5;
		},
		function() {
			delay = setTimeout(function(){
					$("#flyout5").slideUp(200, function(){
						activeFlyout = 0;
						if(activeMenuItemId != $("#naviItem5").attr("id"))
							$("#naviItem5").removeClass("active");});
			}, 100);
		}
	);
	
	//Initialize slideToggle Tarifdetails
	$(".tarifDetailBoxHeader").click(function() {
		if ($(".tarifDetailBoxContainer").is(":hidden")) {
			$(".tarifDetailBoxHeader").addClass("tarifDetailBoxActive");
			$(".tarifDetailBoxContainer").slideToggle(1000, function(){
				$(".tarifDetailBoxContainer").find("a").css("position", "relative");
				$(".tarifDetailBoxContainer").find("img").css("position", "relative");
			});
		}
		else {
			$(".tarifDetailBoxContainer").find("a").css("position", "static");
			$(".tarifDetailBoxContainer").find("img").css("position", "static");
			$(".tarifDetailBoxContainer").slideToggle(1000);
			setTimeout('$(".tarifDetailBoxHeader").removeClass("tarifDetailBoxActive")', 1000);
		}
	});
	
	$(".tarifDetailBoxHeader2").click(function() {
		if ($(".tarifDetailBoxContainer2").is(":hidden")) {
			$(".tarifDetailBoxHeader2").addClass("tarifDetailBoxActive");
			$(".tarifDetailBoxContainer2").slideToggle(1000, function(){
				$(".tarifDetailBoxContainer2").find("a").css("position", "relative");
				$(".tarifDetailBoxContainer2").find("img").css("position", "relative");
			});
		}
		else {
			$(".tarifDetailBoxContainer2").find("a").css("position", "static");
			$(".tarifDetailBoxContainer2").find("img").css("position", "static");
			$(".tarifDetailBoxContainer2").slideToggle(1000);
			setTimeout('$(".tarifDetailBoxHeader2").removeClass("tarifDetailBoxActive")', 1000);
		}
	});
    
    $(".tarifDetailBoxWideHeader").click(function() {
		if ($(".tarifDetailBoxWideContainer").is(":hidden")) {
			$(".tarifDetailBoxWideHeader").addClass("tarifDetailBoxWideActive");
			$(".tarifDetailBoxWideContainer").slideToggle(1000, function(){
				$(".tarifDetailBoxWideContainer").find("a").css("position", "relative");
				$(".tarifDetailBoxWideContainer").find("img").css("position", "relative");
			});
		}
		else {
			$(".tarifDetailBoxWideContainer").find("a").css("position", "static");
			$(".tarifDetailBoxWideContainer").find("img").css("position", "static");
			$(".tarifDetailBoxWideContainer").slideToggle(1000);
			setTimeout('$(".tarifDetailBoxWideHeader").removeClass("tarifDetailBoxWideActive")', 1000);
		}
	});

	//Initialize slideToggle Aufklappbox 30, 50, 100
	$(".detailBoxSlideToggle").click(function() {
		if ($(".detailBoxViewContent").is(":hidden")) {
			$(".detailBoxSlideToggle").addClass("detailBoxActive");
			$(".detailBoxViewContent").slideToggle(1000, function(){
				$(".detailBoxViewContent").find("a").css("position", "relative");
				$(".detailBoxViewContent").find("img").css("position", "relative");
				// IE Display Fix
				if($.browser.msie) {
					$(".detailBoxClose").css("display", "block");
				}
			});
		}
		else {
			$(".detailBoxViewContent").find("a").css("position", "static");
			$(".detailBoxViewContent").find("img").css("position", "static");
			// IE Display Fix
			if($.browser.msie) {
				$(".detailBoxClose").css("display", "none");
			}
			$(".detailBoxViewContent").slideToggle(1000);
			setTimeout('$(".detailBoxSlideToggle").removeClass("detailBoxActive")', 1000);
		}
	});
    
    //Initialize slideToggle DocsisTeaser
    $(".teasertoolDocsisHeader").click(function() {
		if ($(".teasertoolDocsisContainer").is(":hidden")) {
			$(".teasertoolDocsisHeader").addClass("teasertoolDocsisHeaderActive");
			$(".teasertoolDocsisContainer").slideToggle(1000, function(){
				$(".teasertoolDocsisContainer").find("img").css("display", "block");
			});
		}
		else {
			$(".teasertoolDocsisContainer").find("img").css("display", "none");
			$(".teasertoolDocsisContainer").slideToggle(1000);
			setTimeout('$(".teasertoolDocsisHeader").removeClass("teasertoolDocsisHeaderActive")', 1000);
		}
	});
	
	//Initialize slideToggle Fussnoten
	$(".subFooterNotesHeader").click(function() {
		if ($(".subFooterNotes").is(":hidden")) {
			$(".subFooterNotesHeader").addClass("subFooterNotesHeaderActive");
			$(".subFooterNotes").slideToggle(1000);
		}
		else {
			$(".subFooterNotes").slideToggle(1000);
			setTimeout('$(".subFooterNotesHeader").removeClass("subFooterNotesHeaderActive")', 1000);
		}
	});

	//Initialize slideToggle Senderübersicht
	$("#senderUebersicht1").click(function() {
		if ($("#senderContainer1").is(":hidden")) {
			$("#senderUebersicht1").addClass("senderuebersichtBoxHeaderActive");
			$("#senderContainer1").slideToggle(1000, function(){
				$(".link").find("a").css("position", "relative");
				$(".senderuebersichtSchliessen").css("position", "relative");
			});
		}
		else {
			$(".senderuebersichtSchliessen").css("position", "static");
			$(".link").find("a").css("position", "static");
			$("#senderContainer1").slideToggle(1000);
			scrollTeaserToolTop();
			setTimeout('$("#senderUebersicht1").removeClass("senderuebersichtBoxHeaderActive")', 1000);
		}
	});
	
	$("#senderUebersichtSchliessen1").click(function() {
			$(".senderuebersichtSchliessen").css("position", "static");
			$(".link").find("a").css("position", "static");
			$("#senderContainer1").slideToggle(1000);
			scrollTeaserToolTop();
			setTimeout('$("#senderUebersicht1").removeClass("senderuebersichtBoxHeaderActive")', 1000);
	});
	
	$("#senderUebersicht").click(function() {
		if ($("#senderContainer").is(":hidden")) {
			$("#senderUebersicht").addClass("senderuebersichtBoxHeaderActive");
			$("#senderContainer").slideToggle(1000, function(){
				$(".link").find("a").css("position", "relative");
				$(".senderuebersichtSchliessen").css("position", "relative");
			});
		}
		else {
			$(".senderuebersichtSchliessen").css("position", "static");
			$(".link").find("a").css("position", "static");
			$("#senderContainer").slideToggle(1000);
			scrollTeaserToolTop();
			setTimeout('$("#senderUebersicht").removeClass("senderuebersichtBoxHeaderActive")', 1000);
		}
	});
	
	$("#senderUebersichtSchliessen").click(function() {
			$(".senderuebersichtSchliessen").css("position", "static");
			$(".link").find("a").css("position", "static");
			$("#senderContainer").slideToggle(1000);
			scrollTeaserToolTop();
			setTimeout('$("#senderUebersicht").removeClass("senderuebersichtBoxHeaderActive");', 1000);
	});
	
	// Teaser Tool
	if(document.getElementById("teaserTool")) {
		// Scroll-, Teaser Tool Position und oberen festen Scroll-Abstand holen
		scrollYloc = parseInt($(teaserName).css('top').substring(0, $(teaserName).css('top').indexOf('px')));
		teaserXYloc = $(teaserName).offset();
		/*/ Höhe auslesen
		scrollConst = scrollYloc+$(document).scrollTop()+teaserXYloc.top;
		alert(scrollConst);*/
		if(document.getElementById("teaserToolBpErgebnis")) {
			scrollConst = 215;
		}
		else if(document.getElementById("teaserToolBpKonfiguration")) {
			scrollConst = 285;
		}
		else if(document.getElementById("teaserToolBpBestaetigung")) {
			scrollConst = 251;
		}
		else if(!document.getElementById("breadcrumb")) {
			scrollConst = 263;
		}
		else {
			scrollConst = 292;
		}
		// Window Scroll Funktion
		$(window).scroll(function() {
			// Footer Position, Teaser Tool Höhe, oberen dynamischen Scroll-Abstand und Scroll-Teaser Tool Position holen
			footerXYloc = $('#footerNavi').offset();
			teaserHeight = $(teaserName).height();
			scrollTop = scrollYloc+$(document).scrollTop();
			scroll = scrollTop+teaserXYloc.top;
			// Teaser Tool scrollen
			if((scroll >= teaserXYloc.top*2) && (footerXYloc.top >= teaserHeight+scrollTop)) {
				offset = scrollTop-scrollConst+'px';
				$(teaserName).animate({top:offset}, {duration:500, queue:false});
			}
			else if(scrollTop == 0) {
				offset = scrollTop+'px';
				$(teaserName).animate({top:offset}, {duration:500, queue:false});
			}
		});
	}
	if(document.getElementById("teaserTool") || document.getElementById("teaserToolStatic")) {
		// Click auf A-Tags setzen
		$('.ui-accordion-header').find('a:last').each(function(intIndex) {
			$(this).bind('click', function() {
				// Seite darstellen, wenn Tab aktiv ist
				if($(this).parent().hasClass('ui-state-active')) {
					// Target abfragen
					if($(this).attr('target') == '_blank') {
						window.open(this.href);
						return false;
					}
					else if($(this).hasClass('popup') && $(this).attr('rel') != '') {
						window.open(this.href, $(this).attr('rel'), 'toolbar=no;location=no,width=700,height=540,scrollbars=no');
						trackLink($(this).attr('rel'), 'Teaser_Tool:'+$(this).attr('rel'));
						return false;
					}
					else {
						self.location.href = this.href;
						return false;
					}
				}
				// Teaser Tool nach oben scrollen, wenn neuer Tab zu gross ist
				setTimeout(function() {
					if($('#contentMarginal').height() > $('#contentMain').height()) {
						offset = '0px';
						$(teaserName).animate({top:offset}, {duration:500, queue:false});
					}
				}, 500);
			});
		});
		// Click auf H-Tags setzen
		$('.ui-accordion-header').each(function(intIndex2) {
			$(this).bind('click', function() {
				// IE Postion Fix
				if($.browser.msie) {
					$('.accordion img').css('position', 'static');
					$('.accordion h3').css('position', 'static');
					$('.accordionVpBox').css('position', 'static');
					$('.accordionFlash').css('position', 'static');
					$('.accordionVpTextBtn').css('position', 'static');
					$('.accordionVpDone').css('position', 'static');
					//$('#ProfileForm').css('position', 'static');
					$('.accordionDocsis img').css('position', 'static');
					$('.accordionDocsis h3').css('position', 'static');
					// Set Timeout Funktion
					setTimeout(function() {
						$('.accordion img').css('position', 'relative');
						$('.accordion h3').css('position', 'relative');
						$('.accordionVpBox').css('position', 'relative');
						$('.accordionFlash').css('position', 'relative');
						$('.accordionVpTextBtn').css('position', 'relative');
						$('.accordionVpDone').css('position', 'relative');
						//$('#ProfileForm').css('position', 'relative');
						$('.accordionDocsis img').css('position', 'relative');
						$('.accordionDocsis h3').css('position', 'relative');
					}, 300);
				}
			});
		});
	}
    
    $('.accordionLargeTabs').accordion({
		active: 0,
		autoHeight: false,
		header: "h3",
		changestart: function(event, click) {
			$(".accordionLargeTextBtn").css("display", "none");
			setTimeout('$(".accordionLargeTextBtn").fadeIn(500)', 500);
		}
	});
    
	$('.layerSpecialContainer').hide();
	var layer =  document.createElement("div");
	$(layer).attr('id', 'layerSpecial');
	$(layer).attr('class', 'layerSpecial');
	$(layer).html($('#layerSpecialTemp').html());
	document.body.appendChild(layer);
	$('#layerSpecialTemp').remove();
	
	var layerSpecial = 0;
	
	$('#infoIconTTSpecial').hover(
			function() {
				layerSpecial = 1;
				var top = $(this).offset().top - 335; //1782
				var left = $(this).offset().left - 347; //347
				$("#layerSpecial").css("top", top.toFixed(0) + "px");
				$("#layerSpecial").css("left", left.toFixed(0) + "px");
				$("#layerSpecial").fadeIn("slow");
			},
			function() {
				layerSpecial = 0;
				setTimeout(function(){
					if(layerSpecial == 0)
						$("#layerSpecial").fadeOut("slow");
				}, 200);
			}
	);
	$('#layerSpecial').hover(
		function(){
			layerSpecial = 1;
		},
		function(){
			layerSpecial = 0;
			setTimeout(function(){
				if(layerSpecial == 0)
					$("#layerSpecial").fadeOut("slow");
			}, 200);
		}
	);
	
	//Special Layer 2
	var layer =  document.createElement("div");
	$(layer).attr('id', 'layerKASpecial');
	$(layer).attr('class', 'layerKASpecial');
	$(layer).html($('#layerKASpecialTemp').html());
	document.body.appendChild(layer);
	$('#layerKASpecialTemp').remove();
	
	var layerKASpecial = 0;
	
	$('#infoIconKASpecial').hover(
			function() {
				layerKASpecial = 1;
				var top = $(this).offset().top - 240; //1782
				var left = $(this).offset().left - 55; //347
				$("#layerKASpecial").css("top", top.toFixed(0) + "px");
				$("#layerKASpecial").css("left", left.toFixed(0) + "px");
				$("#layerKASpecial").fadeIn("slow");
			},
			function() {
				layerKASpecial = 0;
				setTimeout(function(){
					if(layerKASpecial == 0)
						$("#layerKASpecial").fadeOut("slow");
				}, 200);
			}
	);
	$('#layerKASpecial').hover(
		function(){
			layerKASpecial = 1;
		},
		function(){
			layerKASpecial = 0;
			setTimeout(function(){
				if(layerKASpecial == 0)
					$("#layerKASpecial").fadeOut("slow");
			}, 200);
		}
	);
	
	window.document.onscroll = function(){
		$("#layerSpecial").fadeOut("fast");
	}
	
	//Special Layer 3
	var layer =  document.createElement("div");
	$(layer).attr('id', 'layerKASpecial2');
	$(layer).attr('class', 'layerKASpecial2');
	$(layer).html($('#layerKASpecialTemp2').html());
	document.body.appendChild(layer);
	$('#layerKASpecialTemp2').remove();
	
	var layerKASpecial = 0;
	
	$('#infoIconKASpecial2').hover(
			function() {
				layerKASpecial = 1;
				var top = $(this).offset().top - 240; //1782
				var left = $(this).offset().left - 55; //347
				$("#layerKASpecial2").css("top", top.toFixed(0) + "px");
				$("#layerKASpecial2").css("left", left.toFixed(0) + "px");
				$("#layerKASpecial2").fadeIn("slow");
			},
			function() {
				layerKASpecial = 0;
				setTimeout(function(){
					if(layerKASpecial == 0)
						$("#layerKASpecial2").fadeOut("slow");
				}, 200);
			}
	);
	$('#layerKASpecial2').hover(
		function(){
			layerKASpecial = 1;
		},
		function(){
			layerKASpecial = 0;
			setTimeout(function(){
				if(layerKASpecial == 0)
					$("#layerKASpecial2").fadeOut("slow");
			}, 200);
		}
	);
	
	window.document.onscroll = function(){
		$("#layerSpecial2").fadeOut("fast");
	}
	
	// Layer DocsisMap
	if(document.getElementById("layerDocsisMap")) {
		var layerLandkarte = 0;
		$('#layerDocsisMap').hover(
			function() {
				layerLandkarte = 1;
				var top = $(this).offset().top - 403;
				var left = $(this).offset().left - 203;
				$("#layerLandkarte").css("top", top.toFixed(0) + "px");
				$("#layerLandkarte").css("left", left.toFixed(0) + "px");
				$("#layerLandkarte").fadeIn("slow");
			},
			function() {
				layerLandkarte = 0;
				setTimeout(function() {
					if(layerLandkarte == 0)
						$("#layerLandkarte").fadeOut("slow");
				}, 200);
			}
		);
	}
	
	//Initialize pngFix
	$('div.promoHeadline').pngFix();
	$('h1.promoHeadline').pngFix();
	$('h2.promoHeadline').pngFix();
	$('h1.headline').pngFix();
	$('h2.headline').pngFix();
	$('div.headline').pngFix();
	$('div#infoContent').pngFix();
	$('div#newsletterTeaser').pngFix();
	$('div.kdIntPaketPreis').pngFix();
	$('div.pngfix').pngFix();
	$('p.pngfix').pngFix();
	$('div.accordion_white').pngFix();

	//vjustify Anpassung der Höhe bei Multicolumn Boxen
	$(".teaserBoxSmallContentVp").vjustify();
	
	ready = 1;

});

// Cufon Font Replacement
Cufon.replace('#promoContent h1.head')('#promoContent h2.head');
Cufon.replace('#contentMain h1.head')('#contentMain h2.head');
Cufon.replace('#contentMain h2.teaserHeadline');
Cufon.replace('h3.accordionLargeDynTop')('h3.accordionLargeDynMiddle')('h3.accordionLargeDynBottom')('h3.accordionLargeDynTopYellow')('h3.accordionLargeDynMiddleYellow')('h3.accordionLargeDynBottomYellow');
Cufon.replace('.accordionLargeTabs h3')('.accordionLargeTextBtn');
Cufon.replace('h3.accordionTabTop')('h3.accordionTabMiddle')('h3.accordionTabBottom')('h3.accordionTabTopStatic');
Cufon.replace('h3.teaserLinkBoxHeadline')('a.linkboxContentUrl');
Cufon.replace('h3.surveyTeaserHeadline');


if (!window.trackLink) {
	window.trackLink = function (linkName, prop3) {};	
}

var activeInfoLayerId = 0;
function showInfoLayer(el, txt, offsetX, offsetY, style){
	if(ready){
		if(!style) style = "";
		if(!offsetX) offsetX = 0;
		if(!offsetY) offsetY = 0;
		
		activeInfoLayerId = el.id;
		if(!document.getElementById("infoLayer"+el.id)){
			var layer = document.createElement("div");
			layer.setAttribute("id", "infoLayer"+el.id);
			$(layer).addClass('infoLayer');
			$(layer).addClass(style);
			
			var layerTop = document.createElement("div");
			$(layerTop).addClass('infoLayerT');
			var imgTop = document.createElement("img");
			imgTop.setAttribute("src", "/static/img/lay_infolayer_t"+style+".gif");
			layerTop.appendChild(imgTop);
			
			var layerContent = document.createElement("div");
			$(layerContent).addClass('infoLayerContent');
			$(layerContent).html(txt);
			
			var layerBottom = document.createElement("div");
			$(layerBottom).addClass('infoLayerB');
			var imgBottom = document.createElement("img");
			
			imgBottom.setAttribute("src", "/static/img/lay_infolayer_b"+style+".gif");
			layerBottom.appendChild(imgBottom);
			
			layer.appendChild(layerTop);
			layer.appendChild(layerContent);
			layer.appendChild(layerBottom);
			
			document.body.appendChild(layer);
			
			$(layer).hover(
				function() {
					activeInfoLayerId = el.id;
				},
				function() {
					activeInfoLayerId = 0;
					setTimeout(function(){
						if(activeInfoLayerId != el.id)
							$("#infoLayer"+el.id).fadeOut("slow");
					}, 200);
				}
			);
			window.document.onscroll = function(){
				$("#infoLayer"+el.id).fadeOut("fast");
			}
			$(el).mouseout(function(){
				activeInfoLayerId = 0;
				setTimeout(function(){
					if(activeInfoLayerId != el.id)
					$("#infoLayer"+el.id).fadeOut("slow");
				}, 200);
			});
		}
		else{
			layer = $("#infoLayer"+el.id);
		}
		
		var top = $(el).offset().top - $(layer).height() + offsetY - 14;
		var left = $(el).offset().left + offsetX - 55;
		$(layer).css("top", top.toFixed(0) + "px");
		$(layer).css("left", left.toFixed(0) + "px");
		
		setTimeout(function(){
			if(activeInfoLayerId == el.id)
				$(layer).fadeIn("slow");
		}, 300);
	}
}

function showSenderLayer(el, name, beschreibung, sprache, sendezeit, homepage){
	text = '<strong>'+name+'</strong><br /><br />'+beschreibung+'<br /><br />';
	if(sprache)
		text += 'Sprache: '+sprache+'<br /><br />';
	if(sendezeit)
		text += 'Sendezeit: '+sendezeit+'<br /><br />';
	//text += '<a href="'+homepage+'" target="_blank" title="Senderhomepage öffnen">Senderhomepage</a>';
	showInfoLayer(el, text, 55, 14, "_sender");
}

function showInfoLinkLayer(el, txt, homepage, name, offsetX, offsetY, style){
	text = txt+'<a href="'+homepage+'" target="_blank">'+name+'</a>';
	showInfoLayer(el, text, offsetX, offsetY, style);
}

function showInfoExtLayer(el, name, beschreibung, homepage, linkname, offsetX, offsetY, style){
	text = '<strong>'+name+'</strong><br /><br />'+beschreibung+'<br /><br />';
	text += '<a href="'+homepage+'" target="_blank">'+linkname+'</a>';
	showInfoLayer(el, text, offsetX, offsetY, style);
}
function showInfoPopupLayer(el, name, beschreibung, homepage, linkname, offsetX, offsetY, style){
	text = '<strong>'+name+'</strong><br /><br />'+beschreibung+'<br /><br />';
	text += '<a onclick="nlWindowOpen(this.href);return false;" href="'+homepage+'" >'+linkname+'</a>';
	showInfoLayer(el, text, offsetX, offsetY, style);
}

// Teaser Tool nach oben scrollen
function scrollTeaserToolTop() {
	scrollTop = 0;
	offset = scrollTop+'px';
	$(teaserName).animate({top:offset}, {duration:1000, queue:true});
}

$(function() {  
	$('.email').each(function() {  
	var $email = $(this);  
	var address = $email.text()  
	.replace(/\s*\[at\]\s*/, '@')  
	.replace(/\s*\[dot\]\s*/g, '.');  
	$email.html('<a href="mailto:' + address + '">'  
	+ address +'</a>');  
	});  
});  
