//Flackern von CSS-Backgrounds im IE verhindern
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

(function($) {
	$.fn.extend({
		lastChild:function(options) {
			/**
			* cssClass {String} - The CSS class to apply to the last child element
			* tags {Array} - The names of tags that are allowed to receive the class name
			*/
			var defaults = {cssClass:'last-child', tags:['div', 'li', 'p', 'th', 'tr', 'td', 'dd']};
			if(typeof options === 'string') {
				options = $.extend(defaults, {cssClass:options});
			} else if(typeof options === 'object') {
				options = $.extend(defaults, options);
			} else {
				options = defaults;
			}
			return this.each(function() {
				var $children = $(this).children();
				if($children.length) {
					var $last = $children.last(), tag = $last[0].tagName.toLowerCase();
					for(var i = 0, len = options.tags.length; i < len; ++i) {
						if(options.tags[i] == tag) {
							if(!$last.hasClass(options.cssClass)) {
								$last.addClass(options.cssClass);
							}
							break;
						}
					}
					// Add last child class to children
					$children.each(function() {$(this).lastChild(options);});
				}
			});	// return
		}
	});
})(jQuery);

/**
 * jQuery.ScrollTo - Easy element scrolling using jQuery.
 * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
 * Dual licensed under MIT and GPL.
 * Date: 5/25/2009
 * @author Ariel Flesler
 * @version 1.4.2
 *
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 */
;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);

/**
* Tabify - Tabbed content with ease 1.4
* jan.jarfalk@unwrongest.com, http://www.unwrongest.com
* MIT License - http://www.opensource.org/licenses/mit-license.php
*/
(function($){
     $.fn.extend({
         tabify: function( callback ) {
			function getHref(el){
				hash = $(el).find('a').attr('href');
				hash = hash.substring(0, hash.length - 4);
				return hash;
			}
			
		 	function setActive(el){
				$(el).addClass('active');
				$(getHref(el)).show();
				$(el).siblings('li').each(function(){
					$(this).removeClass('active');
					$(getHref(this)).hide();
				});
			}
			
			return this.each(function() {
				var self = this;
				var	callbackArguments 	=	{'ul':$(self)};
				$(this).find('li a').each(function(){
					$(this).attr('href',$(this).attr('href') + '-tab');
				});
				
				function handleHash(){
                    try {
                        if(location.hash && $(self).find('a[href=' + location.hash + ']').length > 0){				
                            setActive($(self).find('a[href=' + location.hash + ']').parent());
                        }
                    } catch(e) {
                        //hashes could contain invalid expressions
                    }
				}
				
				if(location.hash){
					handleHash();
				}
					
				setInterval(handleHash,100);
				
				$(this).find('li').each(function(){
					if($(this).hasClass('active')){
						$(getHref(this)).show();
					} else {
						$(getHref(this)).hide();
					}
				});
				
				if(callback){
					callback(callbackArguments);
				}	
				
            }); 
        } 
    }); 
})(jQuery);

 /**
 * TipTip
 * Copyright 2010 Drew Wilson  www.drewwilson.com
 * code.drewwilson.com/entry/tiptip-jquery-plugin
 * Version 1.4 ###comcomVersion by TN###   -   Updated: 26.10.2011
 * added forceDefaultPosition, closeBtn bei keepAlive, border am Pfeil
 * This TipTip jQuery plug-in is dual licensed under the MIT and GPL licenses:  http://www.opensource.org/licenses/mit-license.php  http://www.gnu.org/licenses/gpl.html
 */
(function($){$.fn.tipTip=function(options){var defaults={activation:"hover",keepAlive:false,maxWidth:"200px",edgeOffset:3,defaultPosition:"bottom",forceDefaultPosition:false,delay:400,fadeIn:200,fadeOut:200,attribute:"title",content:false,enter:function(){},exit:function(){}};var opts=$.extend(defaults,options);if($("#tiptip_holder").length<=0){var tiptip_holder=$('<div id="tiptip_holder" style="max-width:'+opts.maxWidth+';"></div>');var tiptip_content=$('<div id="tiptip_contentWrap"><a id="tiptip_closeBtn" class="cta01 close icon" href="#">Schlie&szlig;en</a><div id="tiptip_content"></div></div>');var tiptip_arrow=$('<div id="tiptip_arrow"></div>');$("body").append(tiptip_holder.html(tiptip_content).prepend(tiptip_arrow.html('<div id="tiptip_arrow_inner_border"></div><div id="tiptip_arrow_inner"></div>')));}else{var tiptip_holder=$("#tiptip_holder");var tiptip_content=$("#tiptip_content");var tiptip_arrow=$("#tiptip_arrow");}var tiptip_closeBtn=$('#tiptip_closeBtn');return this.each(function(){var org_elem=$(this);if(opts.keepAlive==false){tiptip_closeBtn.remove();}if(opts.content){var org_title=opts.content;}else{var org_title=org_elem.attr(opts.attribute);}if(org_title!=""){if(!opts.content){org_elem.removeAttr(opts.attribute);}var timeout=false;if(opts.activation=="hover"){org_elem.hover(function(){active_tiptip();},function(){if(!opts.keepAlive){deactive_tiptip();}});if(opts.keepAlive){tiptip_closeBtn.click(function(){},function(){deactive_tiptip();return false;});}}else if(opts.activation=="focus"){org_elem.focus(function(){active_tiptip();}).blur(function(){deactive_tiptip();});}else if(opts.activation=="click"){org_elem.click(function(){active_tiptip();return false;}).hover(function(){},function(){if(!opts.keepAlive){deactive_tiptip();}});if(opts.keepAlive){tiptip_closeBtn.click(function(){},function(){deactive_tiptip();return false;});}}function active_tiptip(){opts.enter.call(this);tiptip_content.html(org_title);tiptip_holder.hide().removeAttr("class").css("margin","0");tiptip_arrow.removeAttr("style");var top=parseInt(org_elem.offset()['top']);var left=parseInt(org_elem.offset()['left']);var org_width=parseInt(org_elem.outerWidth());var org_height=parseInt(org_elem.outerHeight());var tip_w=tiptip_holder.outerWidth();var tip_h=tiptip_holder.outerHeight();var w_compare=Math.round((org_width-tip_w)/2);var h_compare=Math.round((org_height-tip_h)/2);var marg_left=Math.round(left+w_compare);var marg_top=Math.round(top+org_height+opts.edgeOffset);var t_class="";var arrow_top="";var arrow_left=Math.round(tip_w-12)/2;if(opts.defaultPosition=="bottom"){t_class="_bottom";}else if(opts.defaultPosition=="top"){t_class="_top";}else if(opts.defaultPosition=="left"){t_class="_left";}else if(opts.defaultPosition=="right"){t_class="_right";}if(!opts.forceDefaultPosition){var right_compare=(w_compare+left)<parseInt($(window).scrollLeft());var left_compare=(tip_w+left)>parseInt($(window).width());}else{var right_compare=false;var left_compare=false;}if((right_compare&&w_compare<0)||(t_class=="_right"&&!left_compare)||(t_class=="_left"&&left<(tip_w+opts.edgeOffset+5))){t_class="_right";arrow_top=Math.round(tip_h-13)/2;arrow_left=-12;marg_left=Math.round(left+org_width+opts.edgeOffset);marg_top=Math.round(top+h_compare);}else if((left_compare&&w_compare<0)||(t_class=="_left"&&!right_compare)){t_class="_left";arrow_top=Math.round(tip_h-13)/2;arrow_left=Math.round(tip_w);marg_left=Math.round(left-(tip_w+opts.edgeOffset+5));marg_top=Math.round(top+h_compare);}if(!opts.forceDefaultPosition){var top_compare=(top+org_height+opts.edgeOffset+tip_h+8)>parseInt($(window).height()+$(window).scrollTop());var bottom_compare=((top+org_height)-(opts.edgeOffset+tip_h+8))<0;}else{var top_compare=false;var bottom_compare=false;}if(top_compare||(t_class=="_bottom"&&top_compare)||(t_class=="_top"&&!bottom_compare)){if(t_class=="_top"||t_class=="_bottom"){t_class="_top";}else{t_class=t_class+"_top";}arrow_top=tip_h;marg_top=Math.round(top-(tip_h+5+opts.edgeOffset));}else if(bottom_compare|(t_class=="_top"&&bottom_compare)||(t_class=="_bottom"&&!top_compare)){if(t_class=="_top"||t_class=="_bottom"){t_class="_bottom";}else{t_class=t_class+"_bottom";}arrow_top=-12;marg_top=Math.round(top+org_height+opts.edgeOffset);}if(t_class=="_right_top"||t_class=="_left_top"){marg_top=marg_top+5;}else if(t_class=="_right_bottom"||t_class=="_left_bottom"){marg_top=marg_top-5;}if(t_class=="_left_top"||t_class=="_left_bottom"){marg_left=marg_left+5;}tiptip_arrow.css({"margin-left":arrow_left+"px","margin-top":arrow_top+"px"});tiptip_holder.css({"margin-left":marg_left+"px","margin-top":marg_top+"px"}).attr("class","tip"+t_class);if(timeout){clearTimeout(timeout);}timeout=setTimeout(function(){tiptip_holder.stop(true,true).fadeIn(opts.fadeIn);},opts.delay);}function deactive_tiptip(){opts.exit.call(this);if(timeout){clearTimeout(timeout);}tiptip_holder.fadeOut(opts.fadeOut);}}});}})(jQuery);



/*~~~ JQuery-Scripting ~~~*/

var infoInTimeout;
var infoOutTimeout;

var initialKwikInterval;
var intervalKwikCounter = 0;

$(function(){
    $('html').addClass('js');
	$('.ie7 #contentWrapper, .ie8 #contentWrapper').lastChild();
	$(".hasToolTip").tipTip();
	$(".hasScToolTip").tipTip({activation: "click", keepAlive: true, forceDefaultPosition: true, content: "<p><strong>Wo steht die Maklernnummer?</strong><br />Die Maklernummer haben Sie von uns zusammen mit Ihrer Courtagezusage erhalten. Sie finden sie au&szlig;erdem in jeder Abrechnung, die wir Ihnen schicken.</p><p><strong>Maklernummer nicht zur Hand?</strong><br />Unser Kundenservice hilft Ihnen gerne weiter.<br /><strong>0800 2214747</strong> (Anruf kostenfrei)</p>"});
	$('#topNav a, #rightNav a').attr('title', '');
	
	$('input[type=text]').focus( function( objEvent ){$(this).select();}); //Standardverhalten von inputs (überall)
    $('#housekeeping input[type=text]') //Standardverhalten von inputs (nur im housekeeping)
		.each(function(){
			$(this).data('originalValue', $(this).attr('value'));
		})
		.focus( function( objEvent ){
			$(this).val('');
		})
		.blur( function( objEvent ){
			if ($(this).val() == '') $(this).val($(this).data('originalValue'));
	});

	$('.scrollTop').click( function( objEvent ){
		$('body').scrollTo( $('#topNav').position().top, 500 );
    });
	
    initMDD();
	
    $('#legalToggler a').click( function( objEvent ){
        toggleLegal();
        return false;
    });
	
    $('a.noClick').click(function( objEvent ){
        return false;
    });

/* ------ Such- und Filterbox SBO ------------------ */
	$('#searchOptionsToggler').click( function( objEvent ){
        toggleSearchOptions(); return false;
    });
	$('.searchBox.scalable').css({'min-height': $('.searchOptions').height()});

	/* ------ Ende Such- und Filterbox SBO ------------------ */
	
	if($("div.info").length >= 1) {
    	$('div#footer').before('<div id="jsInfoBox" class="info"></div>'); //Neue Bubble wird angelegt
	}
	
    //Hilfe-Bubble öffnen
    $('div.info:not(#jsInfoBox)').mouseover( function( objEvent ){
        showInfoBox($(this));
    }); 
    
    //Hilfe-Bubble schliessen
    $('div.info:not(#jsInfoBox)').mouseout( function( objEvent ){
        hideInfoBox();
    });			
	
    //Befindet man sich mit der Maus über der Bubble selbst
    $('div#jsInfoBox').mouseover( function( objEvent ){ //Hilfe-Bubble öffnen
        clearTimeout(infoOutTimeout);
    }); 		
    $('div#jsInfoBox').mouseout( function( objEvent ){ //Hilfe-Bubble schliessen
        hideInfoBox();
    });						
	
    initCarousel(); //Karoussells initialisieren (wenn's welche gibt)

    // Für Reiter-Elemente
    $('.tabbedBox').tabify();   //Tab-Management
    //Rechnet Anzahl der Tabs aus und erhält vom CSS entsprechende Breitenangaben
    switch($('.tabbedBox').children('li').length){ 
        case 2:  $('.tabbedBox').addClass('twoTabs'); break;
        case 3:  $('.tabbedBox').addClass('threeTabs'); break;
        case 4:  $('.tabbedBox').addClass('fourTabs'); break;
        case 5:  $('.tabbedBox').addClass('fiveTabs'); break;
        case 6:  $('.tabbedBox').addClass('sixTabs'); break;
        case 7:  $('.tabbedBox').addClass('sevenTabs'); break;
        case 8:  $('.tabbedBox').addClass('eightTabs'); break;
        case 9:  $('.tabbedBox').addClass('nineTabs'); break;
        case 10: $('.tabbedBox').addClass('tenTabs'); break;
    }

    //Errechnet die Zeilenanzahl der Tabs und vergibt entsprechende Klassen
    var highestLI = 0;

    $('.tabbedBox').children('li').each(function() {
         if($(this).height() > highestLI) highestLI = $(this).height();
		 //console.log(highestLI);
    });
    if(highestLI <= 44){ $('.tabbedBox').addClass('singleRow'); }
        else if(highestLI <= 63){ $('.tabbedBox').addClass('doubleRow'); }
        else if(highestLI <= 81){ $('.tabbedBox').addClass('tripleRow'); }

    //Bei Signposts mit Bild wird die Höhe des Wrapper-Elements ausgerechnet
    //$('.signpostDouble.promoImage').css({'height': ( $('.signpostDouble.promoImage').height() - 20 )+'px'});
        //if ($('html').hasClass('ie8')) { $('.signpostDouble.promoImage').css({'height': ( $('.signpostDouble.promoImage').height() - 37 )+'px'}); }

    //Öffnet Litebox aka Colorbox auf Microsites
	if ($('html.ie6').length < 1){
		if($("#openColorBoxWithArrow").length >= 1) { 
			$("#openColorBoxWithArrow").colorbox({width:700, inline:true, href:"#formWrapper", close: "Schlie&szlig;en", overlayClose:false, onOpen:function(){highlightOpenerBox();}, onClosed:function(){kickOpenerBox();}});
		}
		if($(".openColorBox").length >= 1) {
			$(".openColorBox").colorbox({width:700, inline:true, href:"#formWrapper", close: "Schlie&szlig;en", overlayClose:false });		
		}
	}

	/* KWIK */
	$('.kwicks').kwicks({  
        max : 513, 
		event: 'mouseenter'
    }); 
	
	//Initial sollen alle Elemente durchgehovert werden, damit dem Benutzer klar wird, dass es sich bei dem Kwik um ein interaktives Element handelt
	initialKwikInterval = setInterval(kwikDemo,3000);
	$('.kwicks li').mouseover(function() { clearInterval(initialKwikInterval);});

});


function kwikDemo () {
	if(intervalKwikCounter <= 3) {
		//if($('.kwicks li:nth-child(' + intervalKwikCounter + ')').length >= 1) $('.kwicks li:nth-child(' + intervalKwikCounter + ')').mouseleave();
		if(intervalKwikCounter == 3) $('.kwicks li:nth-child(' + intervalKwikCounter + ')').mouseleave();
		intervalKwikCounter++;
		if(intervalKwikCounter <= 3) $('.kwicks li:nth-child(' + intervalKwikCounter + ')').mouseenter();
	}
	else clearInterval(initialKwikInterval);	
}

function highlightOpenerBox() {
	$('html').scrollTo('#masthead');
    $('.openerBox').clone().appendTo('.openerBox');      //Damit die OpenerBox beim öffnen der Lightbox über dem Overlay liegt,
    $('.openerBox .openerBox').addClass('clone');        //wird dieses geklont und Positioniert

    //In diesem Falle wird die Lightbox nach links gerückt und mit einem Pfeil versehen
    if($('.openerBox').length >= 1) {
		$('#colorbox').addClass('focussed').append('<div id="arrow">&nbsp;</div>');
	}
}

function kickOpenerBox() {
    $('.openerBox').remove('.clone');           //Löschen der überlagerten OpenerBox
    $('#colorbox.focussed').remove('#arrow');   //Und gibt's einen Pfeil, wird dieser auch gelöscht
    $('#colorbox').removeClass('focussed');     //Zu guter letzt die Klasse weg
    
}

function showInfoBox(hoverObj) {

    hoverObj.children('div.content').css({
        'display': 'none'
    })					//Alte Hover-Aktion "unterdrücken"
	
    $('div#jsInfoBox').children().remove();										//Alte Boxen und timeouts killen
    clearTimeout(infoOutTimeout);
	
    //Einblenden nach 500ms
    infoInTimeout = setTimeout( function(){
        hoverObj.children('div.content').clone().appendTo($('div#jsInfoBox'));	//...mit entsprechenden Contents gefüllt
	
		var offset	= hoverObj.offset();
        var topPos  = offset.top;									//Position berechnen
        var leftPos = offset.left;
		
		if($('html').hasClass('ie7')) topPos = $("html").scrollTop() + offset.top;
			
        $('div#jsInfoBox .content').css({
            'display':'block'
        }); 					//Einblenden
        $('div#jsInfoBox').css({
            'opacity': 'hide',
            'display': 'block',
            'top' : topPos,
            'left': leftPos
        }).animate({
            'opacity':'show'
        }, 300);
    }, 400);

}

function hideInfoBox() {	

    clearTimeout(infoInTimeout);

    //Ausfaden
    infoOutTimeout = setTimeout( function(){
        $('div#jsInfoBox').animate({
            'opacity':'hide'
        }, 200).css({
            'display':'none'
        }).children().remove();
    }, 500);
	
}

var carouselVertTimeout;
var carouselHorTimeout;

// Carousels initialisieren
function initCarousel(){
	
	//Durchblättern Vertikalkarussell
    $('div.carouselVert').each(function() {
        if($(this).find('.blockContentWrapper').length <= 0) $(this).find('.blockContent').each(function() {
           $(this).children().wrapAll('<div class="blockContentWrapper" />');
        });
		
		$(this).find('dt > a').each(function(){
			//console.log($(this).height());
			if($(this).height() > 18) $(this).parent('dt').addClass("doubleLine");
		});
		
        carouselVertTimeout = setTimeout(animateCarouselVert, 7000, $(this));
    });
	
	//Klick auf Tab im Vertikalkarussell
	$('div.carouselVert dt a').mouseenter( function( objEvent ){
        openCarouselTab($(this), 'vertical');
        return false;
    });
		$('div.carouselVert').mouseover( function( objEvent ) {
			clearTimeout(carouselVertTimeout);	
		});
		
		$('div.carouselVert').mouseleave( function( objEvent ) {
			carouselVertTimeout = setTimeout(animateCarouselVert, 7000, $(this));	
		});

	//Durchblättern Horizontalkarussell
    $('div.carouselHor').each(function() {

        if($(this).find('dd').length > 1) {
            carouselHorTimeout = setTimeout(animateCarouselHor, 7000, $(this));
        }
        else {
            $(this).find('dt').css({'display': 'none'});
            clearTimeout(carouselHorTimeout);
        }
    });

	//Klick auf Tab im Horizontalkarussell
    $('div.carouselHor dt a').click( function( objEvent ){
        clearTimeout(carouselHorTimeout);
        carouselHorTimeout = setTimeout(animateCarouselHor, 7000, $(this));
        openCarouselTab($(this), 'horizontal');
        return false;
    });
}

// Verhalten Horizontales Carousel nach Klick
function openCarouselTab(myObj, myType){
	
	if(myType == 'horizontal') {
	
		var myIndex = myObj.index() + 2; //Index des geklickten Elements abfragen
		
		//Entsprechendes Tab aktiv setzen
		myObj.parent().find('a.active').removeClass('active');
		myObj.addClass('active');
	
		//Alte Contents ausblenden und neue gemäß Index einblenden
		myObj.parent().parent().children('dd.active').animate({'opacity':'hide'}, 100, function() {
				myObj.parent().parent().children('dd.active').removeClass('active');
				myObj.parent().parent().children('dd:nth-child('+myIndex+')').css({'opacity':'hide'}).animate({'opacity':'show'}, 300).addClass('active');
			});
		
	}
	else if(myType == 'vertical') {
		
		//Alte Contents ausblenden und neue gemäß Index einblenden
		myObj.parent().parent().find('dd.active .blockContentWrapper').stop().animate({'opacity':0}, 300, function() {
			if($.browser.msie) this.style.removeAttribute('filter'); 
            $(this).parent().parent().removeClass('active');
				myObj.parent().next().find('.blockContentWrapper').css({'opacity':0}).animate({'opacity':1}, 300, function() {if($.browser.msie) this.style.removeAttribute('filter'); }).parent().parent().addClass('active');
		
			myObj.parent().parent().find('dt.active').removeClass('active');	//DTs umstellen
				myObj.parent().addClass('active');
				
			myObj.parent().parent().find('dd.ddImage.active').removeClass('active');
				myObj.parent().next().next().css({'opacity':0}).animate({'opacity':1}, 300, function() {if($.browser.msie) this.style.removeAttribute('filter'); }).addClass('active');
		
		});
	}
}

// Automatisches Durchbl?ttern des horizontalen Carousels
function animateCarouselHor(myObj){

        //Preview-Bl?cke ausblenden und den n?chsten einblenden
        if(myObj.find('dt a.active').next().is('a')) {
            myObj.find('dt a.active').removeClass('active').next().addClass('active');
        }
        else {
            myObj.find('dt a.active').removeClass('active');
            myObj.find('dt a').first().addClass('active');
        }
		
        //Aktiven Content ausblenden und den nächsten einblenden
        if(myObj.find('dd.active').next().is('dd')) {
            myObj.find('dd.active').animate({'opacity':'hide'}, 100, function() {
               myObj.find('dd.active').removeClass('active').next().css({'opacity':'hide'}).animate({'opacity':'show'}, 300).addClass('active');
			   carouselHorTimeout = setTimeout(animateCarouselHor, 7000, $(this).parent().parent(".carouselHor"));
            });
        }
        else {
            myObj.find('dd.active').animate({'opacity':'hide'}, 100, function() {
               myObj.find('dd.active').removeClass('active');
               myObj.find('dd').first().css({'opacity':'hide'}).animate({'opacity':'show'}, 300).addClass('active');
			   carouselHorTimeout = setTimeout(animateCarouselHor, 7000, $(this).parent().parent(".carouselHor"));
            });
        }

}

// Automatisches Durchbl?ttern des vertikalen Carousels
function animateCarouselVert(myObj){

	myObj = $('div.carouselVert'); //QUICKFIX: myObj wird in IE7 u 8 nicht sauber übergeben >> Macht vermutlich Probleme wenn mehrere Carousels auf einer Seite sind

    //Aktiven Content ausblenden und den nächsten einblenden
    if(myObj.find('dd.active:not(.ddImage)').next().next().next().is('dd')) {
        myObj.find('dd.active .blockContentWrapper').animate({'opacity':0}, 300, function() {
            $(this).parent().parent().removeClass('active').next().next().next().children().children('.blockContentWrapper').css({'opacity':0}).animate({'opacity':1}, 300, function() { if($.browser.msie) this.style.removeAttribute('filter'); }).parent().parent().addClass('active');

            //Preview-Bl?cke ausblenden und den n?chsten einblenden
            if(myObj.find('dt.active').next().next().next().is('dt')) {
                myObj.find('dt.active').removeClass('active').next().next().next().addClass('active');
            }
            else {
                myObj.find('dt.active').removeClass('active');
                myObj.find('dt').first().addClass('active');
            }
			
			    //Aktives Image ausblenden und das nächste einblenden
				if(myObj.find('dd.ddImage.active').next().next().next().is('dd.ddImage')) {
					myObj.find('dd.ddImage.active').removeClass('active').next().next().next().css({'opacity':0}).animate({'opacity':1}, 300, function() { if($.browser.msie) this.style.removeAttribute('filter');	}).addClass('active');
				}
				else {
					myObj.find('dd.ddImage.active').removeClass('active');
					myObj.find('dd.ddImage').first().css({'opacity':0}).animate({'opacity':1}, 300, function() {if($.browser.msie) this.style.removeAttribute('filter'); }).addClass('active');
				}
			
			carouselVertTimeout = setTimeout(animateCarouselVert, 7000, $(this).parent('.carouselVert'));
	
        });
    }
    else {
        myObj.find('dd.active .blockContentWrapper').animate({'opacity':0}, 300, function() {
            $(this).parent().parent().removeClass('active');
            myObj.find('dd').first().children().children('.blockContentWrapper').css({'opacity':0}).animate({'opacity':1}, 300, function() { if($.browser.msie) this.style.removeAttribute('filter'); }).parent().parent().addClass('active');

            //Preview-Bl?cke ausblenden und den n?chsten einblenden
            if(myObj.find('dt.active').next().next().next().is('dt')) {
                myObj.find('dt.active').removeClass('active').next().next().next().addClass('active');
            }
            else {
                myObj.find('dt.active').removeClass('active');
                myObj.find('dt').first().addClass('active');
            }
			
			    //Aktives Image ausblenden und das nächste einblenden
				if(myObj.find('dd.ddImage.active').next().next().next().is('dd.ddImage')) {
					myObj.find('dd.ddImage.active').removeClass('active').next().next().next().css({'opacity':0}).animate({'opacity':1}, 300, function() {if($.browser.msie) this.style.removeAttribute('filter'); }).addClass('active');
				}
				else {
					myObj.find('dd.ddImage.active').removeClass('active');
					myObj.find('dd.ddImage').first().css({'opacity':0}).animate({'opacity':1}, 300, function() { if($.browser.msie) this.style.removeAttribute('filter'); }).addClass('active');
				}

			carouselVertTimeout = setTimeout(animateCarouselVert, 7000, $(this).parent('.carouselVert'));

        });
    }

}

function initMDD(){
    $('#topNav > li > ul').each( function(){
        //Breiten der DropDowns ermitteln und festlegen
        if($(this).children('li.promotionalModule').length > 0){ //Promotional Module vorhanden: größere breite, 4 items in einer Reihe
            maxPerRow = 4;
        } else {
            maxPerRow = 3;
        }
        multiplier = ($(this).children('li').length <= maxPerRow)? $(this).children('li').length : maxPerRow;
        $(this).css({
            'width': 240 * multiplier
            });
		
        //leftPosition ermitteln und wenn nötig festlegen
        delta = 960 - ($(this).parent('li').position().left - 30 + $(this).width());
        $(this).css({
            'left': (delta < 0) ? delta - 30 : -30
            });
		
        //promotional Height auf Höhe der umgebenden UL minus eigenen margin setzen
        $(this).find('li.promotionalModule').each( function(){
            $(this).css({
                'min-height': $(this).parent('ul').height() - 18
                });
        });
		
        //Senkrechte Divider erzeugen und setzen
        dividerCount = ($(this).children('li.promotionalModule').length > 0) ? multiplier - 2 : multiplier - 1;
        for(i=1; i<=dividerCount; i++){
            $('<div class="divider"></div>').appendTo($(this)).css({
                'height': $(this).height() - 36,
                'left': i * 240
            });
        }
    });//ul each

    //events binden
    $('#topNav > li:has(ul)').mouseover( function( objEvent ){
        mouseoverForMegaDropDown($(this));
    });
    $('#topNav > li:has(ul)').mouseout( function( objEvent ){
        mouseoutForMegaDropDown($(this));
    });
}



var mddInTimeout;
var mddOutTimeout;

function mouseoverForMegaDropDown(myHost) {
    if($('#topNav .deepHover').length > 0){ //wenn schon einer auf ist, direkt wechseln
        clearTimeout(mddOutTimeout);
        myMDD = myHost.find('a + ul');
        $('#topNav .deepHover > a + ul').css({
            'display':'none'
        });
        $('#topNav .deepHover').removeClass('deepHover');
		
        myHost.addClass('deepHover');
        myMDD.css({
            'display':'block'
        });
	
    } else {
        clearTimeout(mddOutTimeout); //wird nicht geschlossen, wenn man nur kurz raus war
        myMDD = myHost.find('a + ul');
        mddInTimeout = setTimeout( function(){
            $('#topNav').removeClass('mddClosed');
            myHost.addClass('deepHover');
            myMDD.animate({
                'opacity':'show'
            }, 200);
        }, 500);
    }
	
}
function mouseoutForMegaDropDown(myHost) {
    clearTimeout(mddInTimeout); //wird nicht mehr geöffnet wenn man schon wieder runter ist
    mddOutTimeout = setTimeout( function(){
        myMDD = myHost.find('a + ul');
        $('#topNav').addClass('mddClosed');
        myHost.removeClass('deepHover')
        myMDD.animate({
            'opacity':'hide'
        }, 200);
    }, 500);
}

function toggleLegal() {
    $('#legal').animate({
        'height' : 'toggle'
    }, 300, function(){
        $('body').scrollTo( $('#legal').position().top, 500 );
    });
    $('#legalToggler').toggleClass('open');
}

function toggleSearchOptions(){
	if($('#searchOptionWrapper').css('display') == 'block'){
		$('#searchOptionWrapper').animate({'height':'hide'}, 500, function(){
			$('.searchBox').animate({'min-height': $('.searchOptions').height()}, 500);
		});
		$('#searchOptionsToggler').removeClass('back icon').text('Filteroptionen anzeigen');
	} else {
		$('#searchOptionWrapper').animate({'height': 'show'}, 500, function(){
			$('.searchBox').animate({'min-height': $('#searchOptionWrapper').height() + $('#searchOptionWrapper').prev().height() + 10}, 500);
		});
		$('#searchOptionsToggler').addClass('back icon').text('Filteroptionen verbergen');
		
		
	}
}

/****** KWIK ******/

$.fn.kwicks = function(options) {
		var defaults = {
			isVertical: false,
			sticky: false,
			defaultKwick: 0,
			event: 'mouseover',
			spacing: 0,
			duration: 500
		};
		var o = $.extend(defaults, options);
		var WoH = (o.isVertical ? 'height' : 'width'); // WoH = Width or Height
		var LoT = (o.isVertical ? 'top' : 'left'); // LoT = Left or Top

		var arrowPosX 		= 186;
		var headlinePosX 	= 20;
		var arrowOpacity	= 1;

		return this.each(function() {
			container = $(this);
			var kwicks = container.children('li');
			var normWoH = kwicks.eq(0).css(WoH).replace(/px/,''); // normWoH = Normal Width or Height
			
			if(!o.max) o.max = (normWoH * kwicks.size()) - (o.min * (kwicks.size() - 1));
				else o.min = ((normWoH * kwicks.size()) - o.max) / (kwicks.size() - 1);

			// set width of container ul
			if(o.isVertical) {
				container.css({
					width : kwicks.eq(0).css('width'),
					height : (normWoH * kwicks.size()) + (o.spacing * (kwicks.size() - 1)) + 'px'
				});
			} else {
				container.css({
					width : (normWoH * kwicks.size()) + (o.spacing * (kwicks.size() - 1)) + 'px',
					height : kwicks.eq(0).css('height')
				});
			}

			// pre calculate left or top values for all kwicks but the first and last
			// i = index of currently hovered kwick, j = index of kwick we're calculating
			var preCalcLoTs = []; // preCalcLoTs = pre-calculated Left or Top's
			for(i = 0; i < kwicks.size(); i++) {
				preCalcLoTs[i] = [];
				// don't need to calculate values for first or last kwick
				for(j = 1; j < kwicks.size() - 1; j++) {
					if(i == j) preCalcLoTs[i][j] = o.isVertical ? j * o.min + (j * o.spacing) : j * o.min + (j * o.spacing);
						else preCalcLoTs[i][j] = (j <= i ? (j * o.min) : (j-1) * o.min + o.max) + (j * o.spacing);
				}
			}

			// loop through all kwick elements
			kwicks.each(function(i) {
				var kwick = $(this);
				// set initial width or height and left or top values
				// set first kwick
				if(i === 0) kwick.css(LoT, '0px');

				// set last kwick
				else if(i == kwicks.size() - 1) kwick.css(o.isVertical ? 'bottom' : 'right', '0px');
				// set all other kwicks
				else {
					if(o.sticky) kwick.css(LoT, preCalcLoTs[o.defaultKwick][i]);
						else kwick.css(LoT, (i * normWoH) + (i * o.spacing));
				}
				// correct size in sticky mode
				if(o.sticky) {
					if(o.defaultKwick == i) {
						kwick.css(WoH, o.max + 'px');
						kwick.addClass('active');
					} else kwick.css(WoH, o.min + 'px');

				}
				kwick.css({
					margin: 0,
					position: 'absolute'
				});

				kwick.find('.header h3').css({'left': headlinePosX+'px'});
				kwick.find('.header .arrowDown').css({'display':'block', 'left': arrowPosX+'px'});

				kwick.bind(o.event, function() {
					// calculate previous width or heights and left or top values
					var prevWoHs = []; // prevWoHs = previous Widths or Heights
					var prevLoTs = []; // prevLoTs = previous Left or Tops
					kwicks.stop().removeClass('active');
					for(j = 0; j < kwicks.size(); j++) {
						prevWoHs[j] = kwicks.eq(j).css(WoH).replace(/px/, '');
						prevLoTs[j] = kwicks.eq(j).css(LoT).replace(/px/, '');
					}
					var aniObj = {};
					aniObj[WoH] = o.max;
					var maxDif = o.max - prevWoHs[i];
					var prevWoHsMaxDifRatio = prevWoHs[i]/maxDif;
					kwick.addClass('active').addClass('whatever').animate(aniObj, {
						step: function(now) {
							// calculate animation completeness as percentage
							var percentage = maxDif != 0 ? now/maxDif - prevWoHsMaxDifRatio : 1;
							// adjsut other elements based on percentage
							kwicks.each(function(j) {
								if(j != i) kwicks.eq(j).css(WoH, prevWoHs[j] - ((prevWoHs[j] - o.min) * percentage) + 'px');
								if(j > 0 && j < kwicks.size() - 1) { // if not the first or last kwick
									kwicks.eq(j).css(LoT, prevLoTs[j] - ((prevLoTs[j] - preCalcLoTs[i][j]) * percentage) + 'px');
								}
								arrowPosXSmall	= 186 - (166 * percentage);
								arrowPosX 		= 186 + (206 * percentage);
								headlinePosX 	=  20 + (206 * percentage);
								arrowOpacity	= (1 - percentage);
								h3Opacity		= (1 - (percentage*2));
								
								if($(this).hasClass('active')) {
									 $(this).find('.header .arrowDown').css({'opacity': arrowOpacity, 'left':arrowPosX+'px'});	
									 $(this).find('.header h3').css({'opacity':1, 'left': headlinePosX+'px'});	
								}
								else {
									 $(this).find('.header .arrowDown').css({'opacity':1, 'left':arrowPosXSmall+'px'});	
									 $(this).find('.header h3').css({'opacity': h3Opacity, 'left': headlinePosX+'px'});	
								}
								
							});
						},
						duration: o.duration,
						easing: o.easing
					});		
				});
			});
			if(!o.sticky) {
				container.bind("mouseleave", function() {
					var prevWoHs = [];
					var prevLoTs = [];
					kwicks.removeClass('active').stop();
					for(i = 0; i < kwicks.size(); i++) {
						prevWoHs[i] = kwicks.eq(i).css(WoH).replace(/px/, '');
						prevLoTs[i] = kwicks.eq(i).css(LoT).replace(/px/, '');
					}
					var aniObj = {};
					aniObj[WoH] = normWoH;
					var normDif = normWoH - prevWoHs[0];
					kwicks.eq(0).animate(aniObj, {
						step: function(now) {
							var percentage = normDif != 0 ? (now - prevWoHs[0])/normDif : 1;
							for(i = 1; i < kwicks.size(); i++) {
								kwicks.eq(i).css(WoH, prevWoHs[i] - ((prevWoHs[i] - normWoH) * percentage) + 'px');
								if(i < kwicks.size() - 1) kwicks.eq(i).css(LoT, prevLoTs[i] - ((prevLoTs[i] - ((i * normWoH) + (i * o.spacing))) * percentage) + 'px');
							}
						},
						duration: o.duration,
						easing: o.easing
					});
					kwicks.find('.header .arrowDown').stop().animate({'left': '186px', 'opacity':1},o.duration);	
					kwicks.find('.header h3').stop().animate({'left': '20px', 'opacity':1},o.duration);
				});

			}
		});
};


        /***************/


function poptext(URL, breite, hoehe)
{
    if (!breite){
        var breite=450;
    }
    if (!hoehe)	{
        var hoehe=450;
    }
	
    var top=(screen.availHeight-hoehe)/2;
    var left=(screen.availWidth-breite)/2;
    var args = "height="+hoehe+", width="+breite+",menubar=0,resizable=1,scrollbars=1,status=0,titlebar=0,toolbar=0,left="+left+",top="+top;
    poptextwin=window.open(URL,'poptextname',args);
    poptextwin.focus();
}     

function getHost()
{
    //die beiden tlds (.de, .at) und staging-pfade abfedern
    var scriptHost;

    scriptHost = window.location.protocol + '//' + window.location.host;

    return scriptHost;
}
