$(function(){
	setDatetime();
	fixRTE();
	initIframe();
	parsePngs();
	initFaqContent();
});


function setDatetime() {
	var heute = new Date();
	var jahr = heute.getFullYear();
	var hour = heute.getHours();
	var minutes = heute.getMinutes();
	var seconds = heute.getSeconds();
	var StdAusgabe = ((hour < 10) ? "0" + hour : hour);
	var MinAusgabe = ((minutes < 10) ? "0" + minutes : minutes);
	var SekAusgabe = ((seconds < 10) ? "0" + seconds : seconds);
	var monat = heute.getMonth()+1;
	var MonatAusgabe = ((monat < 10) ? "0" + monat : monat);
	var tag = heute.getDate();
	var TagAusgabe = ((tag < 10) ? "0" + tag : tag);
	var ww = heute.getDay();
	var weekdays = new Array('Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag');
	var theTime = weekdays[ww] + ", "+TagAusgabe+"."+MonatAusgabe+"."+jahr+" | "+StdAusgabe+":"+MinAusgabe+":"+SekAusgabe;

	$('#datetime').html(theTime);
	setTimeout('setDatetime()', 1000);
}


function fixRTE() {
	$('.cBox li').wrapInner('<span></span>');
	$('ul li:first-child').addClass('first');
	$('ul li:last-child').addClass('last');
	$('ol li:first-child').addClass('first');
	$('ol li:last-child').addClass('last');

	$('.cBox a.more:last-child').addClass('lastMore');
}


function initIframe() {
	var iframeLoaded1 = 0;
	$('#calc iframe.hide').bind('load', function(e) {
		iframeLoaded1++;
		if (iframeLoaded1 > 1) {
			$('.cBox_testsieger').addClass('cBox_testsieger_hidden');
			$('.cBox_testsieger .content').slideUp('slow');
			$('.cBox_testsieger h2').html($('#calc iframe').attr('title'));
			$('.teaserButton').hide();
		}
	});

	var iframeLoaded2 = 0;
	$('#calc iframe.scroll').bind('load', function(e) {
		iframeLoaded2++;
		if (iframeLoaded2 > 1) {
			$('html, body').animate({scrollTop:0}, 'slow');
		}
	});
}

function parsePngs() {
	var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
	if (badBrowser) {
	  // get all pngs on page
	  $('img[src$=.png]').each(function() {
	    if (!this.complete) {
	      this.onload = function() { fixPng(this) };
	    } else {
	      fixPng(this);
	    }
	  });
	}
}

var blank = new Image(); blank.src = '/imgs/blank.gif';
function fixPng(png) {
  // get src
  var src = png.src;
  // set width and height
  if (!png.style.width) { png.style.width = $(png).width(); }
  if (!png.style.height) { png.style.height = $(png).height(); }
  // replace by blank image
  png.onload = function() { };
  png.src = blank.src;
  // set filter (display original image)
  png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
}

function initFaqContent() {
	$('.faqContent .cBox p').hide();
	$('.faqContent .cBox h3').click(function(){
		$(this).next().slideToggle('fast');
		$(this).toggleClass('active');
	});
}

ts = {
		vars : [],
		delays : [],
		isIE6 : $.browser.msie && $.browser.version.substr(0,3)=='6.0',
		isIE7 : $.browser.msie && $.browser.version.substr(0,3)=='7.0',
		isIE8 : $.browser.msie && $.browser.version.substr(0,3)=='8.0',
		isFF2 : $.browser.mozilla && (parseFloat($.browser.version) < 1.9)
};


ts_hinttip = {
		active : false,
		
		//register hinttips
		register : function() {
			
			$('.ts-hinttip').each(function () {
				var hinttip = $(this);
				var hinttip_content = hinttip.find('.ts-hinttip-content');

				if(hinttip.hasClass('ts-visible')){
					return;
				}
				
				hinttip_content.html(
					'<div class="ts-hinttip-inner">' +
						hinttip_content.html() +					
						'<div class="ts-hinttip-corner">&nbsp;</div>' +
						'<div class="ts-hinttip-close">&nbsp;</div>' +
					'</div>'
				);
				
				hinttip.show = function(e){
					hinttip.addClass('ts-maximize-zindex');
					if(ts_hinttip.active!=hinttip_content){
						ts_hinttip.close();
						
						ts_hinttip.active = hinttip_content;
						if(e){
							e.stopPropagation();
						}
					}
					hinttip_content.show();
				}
				
				
				hinttip.click(function(e) {
					hinttip.show(e);
				});
				
				// Avoid IE Glitch
				if(hinttip.hasClass('ts-faqtip')){
					hinttip.find('.ts-hinttip-title').hover(
						function() {
							$(this).addClass('ts-hinttip-hover');
						},
						function() {
							$(this).removeClass('ts-hinttip-hover');
						}
					);	
				}
						
			});
			
			$(document).click(function() {
				ts_hinttip.close();
			});
		},
		
		close : function() {
			if (ts_hinttip.active) {
				var t=ts_hinttip.active.closest('.ts-hinttip');
				t.removeClass('ts-maximize-zindex');
				
				if(ts.isIE6){
					ts_hinttip.active.hide();
				}
				else{
					ts_hinttip.active.fadeOut('fast');
				}
				ts_hinttip.active=false;
			}
		}

};

$(function() {
	ts_hinttip.register();
});


