var DBV = {
	carrouselDelay: 10
}

var Carrousel = {
	options: {
		delay: 10,			// delay in sec. between rotation
		pause: 15,			// delay in sec. to restart rotation after user action
		time: 250			// delay in msec. for animation
	},
	delay: [],
	flags: {
		count: 0,			// count of total carrousel items
		current: 0,			// current displayed item
		queue: false,		// flag animation running
		interval: Object()	// timeout object (used to stop animation)
	},
	animate: function(e, show){
		var self = Carrousel,
			current = self.flags.current,
			next = (self.flags.current+1<self.flags.count)?self.flags.current+1:0,
			pos = {inX:'100%', outX:'-100%'};
			if (typeof(show)!='undefined'){
				if (show<current) pos = {inX:'-100%', outX:'100%'};
				next = (show<self.flags.count)?show:0;
				if (next<0) next = self.flags.count-1;
			}

		if (next!=current){
			self.flags.queue = true;
			//jQuery('.carrousel-container .carrousel-item'+next).css('left', pos.inX);
			//jQuery('.carrousel-container .carrousel-item'+next).show();
			//jQuery('.carrousel-container .carrousel-item'+next).animate({left:'0%'}, self.options.time, 'linear', function(){self.flags.current = next});
			jQuery('.carrousel-container .carrousel-item'+next).fadeIn(self.options.time, function(){self.flags.current = next});
			//jQuery('.carrousel-container .carrousel-item'+current).animate({left:pos.outX}, self.options.time, 'linear', function(){self.flags.queue = false});
			jQuery('.carrousel-container .carrousel-item'+current).fadeOut(self.options.time, function(){self.flags.queue = false});

			/*
			if (next+1==1) jQuery('.carrousel-pager a.prev').addClass('prev-disabled');
			else jQuery('.carrousel-pager a.prev').removeClass('prev-disabled');
			if (next+1==self.flags.count) jQuery('.carrousel-pager a.next').addClass('next-disabled');
			else jQuery('.carrousel-pager a.next').removeClass('next-disabled');
			*/

			jQuery('.carrousel-pager ul li.show').removeClass('show');
			jQuery('.carrousel-pager ul li:nth-child('+(next+1)+')').addClass('show');
			if (typeof(show)=='undefined'){
				//self.flags.interval = setTimeout(self.animate, self.options.delay*1000);
				self.flags.interval = setTimeout(self.animate, self.delay[next]*1000);
			} else if (self.options.pause>0) {
				self.flags.interval = setTimeout(self.animate, self.options.pause*1000);
			}
		}
	},
	start: function(){
		var self = this;
		//self.flags.interval = setTimeout(self.animate, self.options.delay*1000);
		self.flags.interval = setTimeout(self.animate, self.delay[0]*1000);
		jQuery(window).unload(function(){self.stop()});
	},
	stop: function(){
		var self = this;
		//clearInterval(self.flags.interval);
		clearTimeout(self.flags.interval);
	},
	show: function(show){
		var dummy, self = this;
		self.stop();
		var fnc = function(){self.animate(dummy, show)};
		if (self.flags.queue) self.flags.interval = setTimeout(fnc, self.options.time);
		else fnc.call();
	},
	prev: function(){
		var self = this,
			next = self.flags.current-1;
		//if (next>=0)
			self.show(next);
	},
	next: function(){
		var self = this,
			next = self.flags.current+1;
		//if (next<self.flags.count)
			self.show(next);
	},
	init: function(delay){
		var self = this;
		self.options.delay = delay;
		jQuery('.carrousel-container').prepend('<div class="carrousel-pager"><a class="prev" href="#"></a><a class="next" href="#"></a></div>');
		jQuery('.carrousel-pager a.next').click(function(){
			self.next();
			jQuery(document).click();
			return false;
		});
		jQuery('.carrousel-pager a.prev').click(function(){
			self.prev();
			jQuery(document).click();
			return false;
		}).after('<ul></ul>');
		jQuery('.carrousel-container .carrousel-item').each(function(i,e){
			// parse item class for delay value
			var delay = jQuery(e).attr('class').match(/delay_([0-9]{0,})/);
			delay = (delay)?delay[1]:0; // catch null or undefined
			delay = (delay>0)?delay:self.options.delay; // catch zero
			self.delay.push(delay);

			jQuery('.carrousel-pager ul').append('<li><a href="#">'+(i+1)+'</a></li>');
			jQuery('.carrousel-pager ul li:last-child a').click(function(){
				self.show(i);
				jQuery(document).click();
				return false;
			});
			$(e).addClass('carrousel-item'+i);
			self.flags.count++;
		});
		jQuery('.carrousel-pager ul li:first-child').addClass('show');
		jQuery('.carrousel-pager ul li:first-child').addClass('first');
		if (self.flags.count>1) jQuery('.carrousel-container').addClass('carrousel-ok');
		self.start();
	}
};

var Popups = {
	current: null,
	fade: true,
	window: function(url, title, properties){
		if (!title) title = 'DBVPopup';
		if (!properties) properties = 'resizable=yes,scrollbars=yes,status=no,toolbar=no,location=no,menubar=no,width=600,height=600';
		var winHandle = window.open(url, title, properties);
		var fnc = function(){winHandle.focus()};
		setTimeout(fnc,250);
		return false;
	},
	closer: function(){
		if (this.current){
			if ($('#'+this.current).hasClass('button-trapezoid')) $('#'+this.current).removeClass('button-trapezoid-active');
			else $('#'+this.current).removeClass('open');
			if (this.fade){
				$('#popup-'+this.current).fadeOut('fast', function(){
					$('#popup-'+this.current).addClass('hide');
				});
			} else {
				$('#popup-'+this.current).addClass('hide');
			}
			this.current = null;
		}
	},
	opener: function(id){
		if (id!=this.current){
			this.closer();
			this.current = id;
			if ($('#'+this.current).hasClass('button-trapezoid')) $('#'+this.current).addClass('button-trapezoid-active');
			else $('#'+this.current).addClass('open');
			if (this.fade) $('#popup-'+this.current).css('display','none');
			$('#popup-'+this.current).removeClass('hide');
			if (this.fade) $('#popup-'+this.current).fadeIn('normal');
		} else {
			this.closer();
		}
	},
	initialize: function(){
		$(document).ready(function(){
			var fnc = function(){
				Popups.closer();
				$(document).unbind("click", fnc);
			}
			$('.popup-trigger').each(function(i,e){
				$(e).click(function(event){
					var o = ($(e).hasClass('popup-trigger-container'))?$(e):$(e).parent('.popup-trigger-container');
					Popups.opener($(o).attr('id'));
					$(document).bind("click", fnc);
					event.stopPropagation();
					return false;
				});
			});
			$('.popup-closer').each(function(i,e){
				$(e).click(function(event){
					fnc();
					event.stopPropagation();
					return false;
				});
			});
			$('.popup-container').each(function(i,e){
				$(e).click(function(event){
					event.stopPropagation();
					return false;
				});
			});
			if ($('body').hasClass('ie_6')) Popups.fade=false;
		});
	}
};

var Anker = {
	call: function(anker){
		var anker = anker||location.hash;
		if (anker){
			var ankerobj = $("a[name='"+anker.substring(1)+"']"),
				tabitem = $(ankerobj).parents('div.tabitem'),
				tabtext = $(tabitem).find('a.tablabel').text(),
				accitem = $(ankerobj).parents('div.accitem'),
				accitem2= $(ankerobj).parents('div.accitem2');
			$(tabitem).parents('div.pager').find('ul.tablist li').each(function(i,e){
				if ($(e).text()==tabtext) $(e).click();
			});
			if (!$(accitem).hasClass('open'))  $(accitem).find('div.acclabel').click();
			if (!$(accitem2).hasClass('open')) $(accitem2).find('div.acclabel2').click();
			location.hash = anker;
		}
	},
	initialize: function(){
		$('a[href^=#]').each(function(i,e){
			if ($(e).attr('href')!='#'){
				$(e).click(function(){
					Anker.call($(this).attr('href'));
				});
			}
		});
		this.call();
	}
};

var Initializer = function(){
	Carrousel.init(DBV.carrouselDelay);
	
	/* correct subnavi classes */
	$(document).ready(function(){
		$('.dbv-homepage ul#subnavi > li > a').each(function(){
			if (!$(this).parent().hasClass('active')){
				$(this).mouseover(function(){
					$(document).click();
					$(this).parent().addClass('show');
					$(this).parent().prev().addClass('prev-item');
				});
				$(this).mouseout(function(){
					$(this).parent().removeClass('show');
					$(this).parent().prev().removeClass('prev-item');
				});
				/*
				$(this).click(function(){
					$(document).click();
					return false;
				});
				*/
			}
		});
		$('.dbv-homepage ul#subnavi .secondlevel-wrapper').each(function(){
			$(this).mouseover(function(){
				$(this).parent().addClass('show');
				$(this).parent().prev().addClass('prev-item');
				$(this).parent().addClass('no-hover');
			});
			$(this).mouseout(function(){
				$(this).parent().removeClass('show');
				$(this).parent().prev().removeClass('prev-item');
				$(this).parent().removeClass('no-hover');
			});
		});
		$('#subnavi-container ul li').each(function(){
			if (!$(this).find('ul').length){
				$(this).addClass('nosub-navi');
			}
		});
		$('.dbv-homepage ul#subnavi .secondlevel-container > ul').each(function(){
			$(this).find('li:first').addClass('first');
		});
		$('.dbv-produktpage ul.secondlevel').each(function(){
			$(this).find('li:first').addClass('first');
			$(this).find('li:last').addClass('last');
		});
		$('.dbv-produktpage ul.secondlevel li.active').each(function(){
			if (!$(this).find('ul').length){
				$(this).addClass('nosub');
			}
		});
		$('.dbv-produktpage ul#subnavi > li.active').each(function(){
			if (!$(this).find('ul').length){
				$(this).addClass('nosub');
			}
			$(this).prev().addClass('prev-item');
		});
		$('.dbv-homepage ul.subnavi-service > li > a').each(function(){
			if (!$(this).parent().hasClass('active')){
				$(this).mouseover(function(){
					$(document).click();
					$(this).parent().addClass('show');
					$(this).parent().prev().addClass('prev-item');
				});
				$(this).mouseout(function(){
					$(this).parent().removeClass('show');
					$(this).parent().prev().removeClass('prev-item');
				});
			}
		});
		$('.dbv-produktpage ul.subnavi-service > li > a').each(function(){
			if (!$(this).parent().hasClass('active')){
				$(this).mouseover(function(){
					$(document).click();
					$(this).parent().addClass('show');
					$(this).parent().prev().addClass('prev-item');
				});
				$(this).mouseout(function(){
					$(this).parent().removeClass('show');
					$(this).parent().prev().removeClass('prev-item');
				});
			}
		});
		$('.dbv-produktpage ul.subnavi-service .secondlevel > li > a').each(function(){
			$(this).mouseover(function(){
				$(this).parent().addClass('show');
			});
			$(this).mouseout(function(){
				$(this).parent().removeClass('show');
			});
		});
		$('.dbv-produktpage ul.subnavi-service .secondlevel .thirdlevel > li > a').each(function(){
			$(this).mouseover(function(){
				$(this).parent().addClass('show');
			});
			$(this).mouseout(function(){
				$(this).parent().removeClass('show');
			});
		});
		$('.dbv-produktpage ul.subnavi-service > li.active').each(function(){
			if (!$(this).find('ul').length){
				$(this).addClass('nosub');
			}
		});
		
		$('.quicknav').each(function(i,e){
			$(e).find('form select option').each(function(x,o){
				if (x==0){
					$(e).append('<a href="#" class="dropbox">'+$(o).text()+'</a><div class="dropbox-wrapper"><div class="dropbox-container"><div class="dropbox-scroll"><ul></ul></div></div></div>');
				} else {
					var cls = (x==1)?' class="first"':(x%2==0)?' class="rowalt"':'';
					$(e).find('ul').append('<li'+cls+'><a href="'+$(o).attr('value')+'">'+$(o).text()+'</a></li>');
				}
			});
			$(e).find('form').remove();
		});
		$('.quicknav a.dropbox').click(function(){
			if ($(this).parent().hasClass('show')){
				$(this).parent().removeClass('show');
			} else {
				$(document).click();
				$(this).parent().addClass('show');
			}
			if ($(this).parent().hasClass('show')){
				var self = $(this).parent(),
					fnc = function(){
						self.removeClass('show');
						$(document).unbind('click');
					}
				$(document).bind('click', fnc);
				$(window).unload(fnc);
			}
			return false;
		});
		$('#tabs-bar > li > a').click(function(){
			$('#tabs-bar > li.show').removeClass('show');
			$(this).parent().addClass('show');
			$('#tabs-container .tabs-item').addClass('hide');
			
			if ($(this).parent().hasClass('beamte')){
				replaceZielgruppe("Beamte");
				$('#tabs-container .tabs-item.beamte').removeClass('hide');
				replaceElement("beamte");
			}else if($(this).parent().hasClass('angestellte')){
				replaceZielgruppe("Angestellte");
				$('#tabs-container .tabs-item.angestellte').removeClass('hide');
				replaceElement("angestellte");
			}else if($(this).parent().hasClass('arbeitnehmer')){
				replaceZielgruppe("Arbeitnehmer");
				$('#tabs-container .tabs-item.arbeitnehmer').removeClass('hide');
				replaceElement("arbeitnehmer");
			}else if($(this).parent().hasClass('bildung')){
				replaceZielgruppe("Bildung");
				$('#tabs-container .tabs-item.bildung').removeClass('hide');
				replaceElement("bundeswehr");
			}else if($(this).parent().hasClass('bundeswehr')){
				replaceZielgruppe('Bundeswehr');
				$('#tabs-container .tabs-item.bundeswehr').removeClass('hide');
				replaceElement("bundeswehr");
			}else if($(this).parent().hasClass('polizei')){
				replaceZielgruppe("Polizei");
				$('#tabs-container .tabs-item.polizei').removeClass('hide');
				replaceElement("polizei");
			}else if($(this).parent().hasClass('ruhestand')){
				replaceZielgruppe("Ruhestand");
				$('#tabs-container .tabs-item.ruhestand').removeClass('hide');
				replaceElement("ruhestand");
			}else if($(this).parent().hasClass('vorruhestand')){
				replaceZielgruppe("Vorruhestand");
				$('#tabs-container .tabs-item.vorruhestand').removeClass('hide');
				replaceElement("vorruhestand");
			}
			$(document).click();
			 /*
			var normal_itc_franklin_gothik_std_med = {	src: '../sIFR/sifr_dbv_itc_franklin_gothik_std_med.swf' };

			sIFR.activate( normal_itc_franklin_gothik_std_med );
			
			sIFR.replace( normal_itc_franklin_gothik_std_med, {
				selector: 'h3.dbv-normal-headline-2',
				wmode:'opaque',
				offsetTop:'-3',
				offsetLeft:'1',
				tuneHeight:'-6',
				antiAliasType:'advanced',
				thickness:'0',
				css: ['.sIFR-root { text-align: left; color: #103184; font-size:20px; }']
			});
			*/
			 
		

			
			return false;
		});
		/*
		var temp = $('#subnavi').find('ul > li:first').get(0);
		if (temp) {
			if ($(temp).hasClass('active') || $(temp).hasClass('first-active'))
				temp.className = 'first-active';
			else
				temp.className = 'first';
		}
		$('#subnavi').find('li.active').each(function(i, e){
			if ($(e).find('ul').length == 0)
				$(e).attr('class', 'nosub-active');
		});
		$('#subnavi').find('li.first-active').each(function(i, e){
			if ($(e).find('ul').length == 0)
				$(e).attr('class', 'first-nosub-active');
		});
		*/
		
	});
	
	
	
	/* fully clickable boxes */
	$('div.bottom-box').each(function(i, e){
		$(e).click(function(){
			location.href = $(e).find('a').attr('href');
		});
	});
	
	$('#context-container div.boxwrapper.first').each(function(i, e){
		$(e).click(function(){
			var linkHref = $(e).find('a').attr('href');
			if(linkHref && linkHref.indexOf('http') > -1) {
				location.href = $(e).find('a').attr('href')+'?WT.ac='+$(e).find('div.header').text();
				return false;
			}
			else {
				
			}
			
		});
		if($(e).find('a').attr('onclick')) {
			$(e).click($(e).find('a').attr('onclick'));
		}
	});

	/* correct contextbox classes */
	$('div#context-container').find('div.boxwrapper.first').each(function(i, e){
		if (i > 0)
			$(e).removeClass('first');
	});
	/* fix double headline spacing in contextbox */
	$('#context-container .boxwrapper .col').each(function(){
		$(this).find('.header').each(function(i, e){
			if (i > 0)
				$(e).css('padding-top', 0);
		})
	});
	/* insert line above axabox in case there are no sidebar boxes */
	if (!$('div#context-container').find('div.boxwrapper.first').length){
		$('.boxpadding #axabox-wrapper').parent().before('<div class="boxwrapper" style="height:1px;overflow:hidden;"><div class="box"></div></div>');
	}
	/* limit height on entry boxes to fit in short stories with their happy ends */
	$('.entrypage-topicbox .padder i').each(function(){
		$(this).parents('.entrypage-topicbox').addClass('height-limit');
	});

    /* build customized dropdown boxes */
	try{
	$(document).dropdownbox();
	}catch (e) {
	}

	/* build tab pager */
	$('div.pager').each(function(i,e){
		$(e).prepend('<ul class="tablist"></ul>');
		$(e).find('ul.tablist').get(0).callback = null;
		$('div.tabitem', e).each(function(x,o){
			$(e).find('ul.tablist').append('<li class="tabitem"><a href="#">'+$(o).find('a.tablabel').addClass('hide').text()+'</a></li>');
			$(o).addClass('hide');
			$($(e).find('ul.tablist li').get(x)).click(function(){
				if (!$(this).hasClass('active')){
					$('div.tabitem', e).each(function(y,d){if (!$(d).hasClass('hide'))$(d).addClass('hide')});
					$(e).find('ul.tablist li').each(function(y,d){$(d).removeClass('active')});
					$(this).addClass('active');
					$(o).removeClass('hide');
					var fn = $(e).find('ul.tablist').get(0).callback;
					if (typeof(fn)=='function') fn.call(this,$(this).text());
				}
				return false;
			});
		});
		
		$(e).find('ul.tablist li:first').click();
		//$(e).find('ul.tablist li:first').addClass('active');
		
		// setzte anderen Style, wenn die Tabs doppelzeilig sind
		var strTab = $('ul.tablist').html();
		if(strTab.toLowerCase().indexOf("<br>") != -1){
			$('ul.tablist').addClass('double');
		}
	});

	/* LARGE PAGER */
	$('div.large-pager').each(function(i,e){
		$(e).prepend('<ul class="tablist"></ul>');
		$('div.tabitem', e).each(function(x,o){
			$(e).find('ul.tablist').append('<li class="tabitem"><a href="#">'+$(o).find('a.tablabel').addClass('hide').html()+'</a></li>');
			$(o).addClass('hide');
			$($(e).find('ul.tablist li').get(x)).click(function(){
				if (!$(this).hasClass('active')){
					$('div.tabitem', e).each(function(y,d){if (!$(d).hasClass('hide'))$(d).addClass('hide'); $(d).removeClass('active');});
					$(e).find('ul.tablist li').each(function(y,d) { $(d).removeClass('active'); });
					$(this).addClass('active');
					$(o).removeClass('hide');
				}
				//$(document).click();
				return false;
			});
		});
		$(e).append('<div class="clearer"></div>');
	});

	/* build accordion panels */
	$('div.accordion').each(function(i,e){
		$('div.accitem', e).each(function(x,o){
			if (x==0 && !$(o).hasClass('closed')) $(o).addClass('open');
			$(o).find('div.acclabel').click(function(){
				if (!$(o).hasClass('open')) $(e).find('div.accitem.open').removeClass('open');
				$(o).toggleClass('open');

				var jetzt = new Date();
				$('.dropdownbox').addClass(jetzt.getTime()+'a');

				//$(document).click();
				return false;
			});
		});
	});

	/* build accordion panels second level */
	$('div.accordion2').each(function(i,e){
		$('div.accitem2', e).each(function(x,o){
			if (x==0) $(o).addClass('first'); //.addClass("open");  THIS DOES NOT WORK BECAUSE NESTING WAS TOTALLY DONE WRONG
			$(o).find('div.acclabel2').click(function(){
				if (!$(o).hasClass('open')) $(e).find('div.accitem2.open').removeClass('open');
				$(o).toggleClass('open');
				//$(document).click();
				return false;
			});
		});
	});
	// HACK TOP OPEN FIRST ITEM BECAUSE NESTING WAS DONE TOTALLY WRONG
	$(".accitem").each(function(){
			$(this).find(".accbody").each(function(i,e){
					if ($(e).find(".accordion2").length){
						$(e).find(".accordion2 .accitem2.first").addClass("open");
						return false;
					}
			});
	});
	$(".accordion2 .accitem2:not(.open)").removeClass("first");

	$('table.leistungstabelle td.leistungstabelle-col1-drop-trigger').each(function(i,e){
		//var obj = $(e).parent().next().children().get(0), to = Object();
		var obj = $(e).parent().nextAll('tr.leistungstabelle-hide-inforow:first').children().get(0), to = Object();
		var fna = function(){
			clearTimeout(to);
			$(e).addClass('over');
			$(obj).removeClass('hide');
		}
		var fnb = function(){
			$(e).removeClass('over');
			$(obj).addClass('hide');
		}
		$(e).mouseover(function(){fna()});
		$(e).mouseout(function(){to = setTimeout(fnb,10)});
		$(obj).mouseover(function(){fna()});
		$(obj).mouseout(function(){to = setTimeout(fnb,10)});
	});

	/* init ratings on onlineberater page */
	$('.relevance-rating').each(function (i, e) {

		var rating = $(e).text();
		$(e).html("");

		for (var i=0; i<rating; i++)
			$(e).append('<div class="purple-bullet-active float-left"></div>');

		for ( ; i<4; i++)
			$(e).append('<div class="purple-bullet float-left"></div>');

		if (rating == 1) text = "Sinnvolle Erg&auml;nzung";
		if (rating == 2) text = "Empfehlenswert";
		if (rating == 3) text = "Sehr wichtig";
		if (rating == 4) text = "Unverzichtbar";

		$(e).append('<div class="float-left rating-text">' + text + '</div>');
		$(e).append('<div class="clear"></div>');
	});

	Popups.initialize();
	Anker.initialize();
	/* move popup-containers and append them to the content-container */
	$('div.popup-container').appendTo('#content-container');
	
	
	// show video layer
    $('#plan360_video_layer .header .closer').click(function() {
        /**
         * setze hole den Content aus den Box heraus,
         * damit das Video nicht weiterl&#228;uft und T&#246;ne von sich gibt
         */
        $('#plan360_video_layer .innerBox .content').html('');
        
        // Schliesse den Layer
        $('#plan360_video_layer').hide();
    });
    var teaserSize = jQuery('.teaser-icons.left .teaser-icon-content.video_start_player').size();
    for(var i = 0; teaserSize > i; i++){
    	var classNameV = "video-"+i;
    	jQuery('.teaser-icons.left .teaser-icon-content.video_start_player:eq('+i+')').addClass(classNameV);
    }
    $('.video_start_player').click(function() {
        /**
         * Fuege den entsprechenden HTML-Schnipsel in dem
         * das Flashvideo angezeigt werden soll in den
         * Content des Video layers ein
         */
        $('#plan360_video_layer .innerBox .content').html('<div id="plan360_video_flashcontent"><strong>You need to upgrade your Flash Player to version 9<\/strong><\/div>');
        
        
        /**
         * Benutze SWFObject um das Flash-Video einzubinden
         */
        var flashvars = {};
		var flashPfad = jQuery(this).find('.flash-pfad object param[name="movie"]').val();
//		alert(flashPfad);
		flashvars.videoFile = flashPfad;
//		http://axa-cms04-m10.pironet-ndh.com/webadmin/webdav/dbv/dbv/video/AXA_DBV_Edit_Aufloeser_090423.swf
		

		var urlName = window.location.host;
        flashvars.autoPlay = "true";
        var params = {};
        params.quality = "best";
        params.bgcolor = "#ffffff";
        params.base = "";
        params.allowScriptAccess = "always";
        var attributes = {};
        /*attributes.id = "flashVideoplayer";*/
        attributes.id = "plan360_video_flashcontent";
        swfobject.embedSWF("http://"+urlName+"/pb/site/dbv/get/documents/dbv/dbv/video/videoplayer.swf", "plan360_video_flashcontent", "480", "337", "8.0.0", "", flashvars, params, attributes);
//        swfobject.embedSWF("http://www.axa.de/axaweb/flash/bs2009/hr/videoplayer.swf", "plan360_video_flashcontent", "400", "260", "8.0.0", "", flashvars, params, attributes);
        
        // Zeige den Layer
        $('#plan360_video_layer').show();
    });
    // add class for rounded box to style them correct
    jQuery('.rounded-boxes .last-element').each(function(){
    	if(jQuery(this).hasClass('box2')){
    		jQuery(this).parent().addClass('box2');
    	}else if(jQuery(this).hasClass('box1')){
    		jQuery(this).parent().addClass('box1');
    	}
    });
    
    // function for toggle boxes
	jQuery('.toggle-box-grey-w .head').unbind().bind('click', function(){
		if(jQuery(this).parent().parent().hasClass('closed')){
			jQuery(this).parent().parent().removeClass('closed');
		}else{
			jQuery(this).parent().parent().addClass('closed');			
		}
	});
	
	
	// show other faq bubbles
	jQuery('.faq-bubbles').addClass('box-val'+jQuery('.faq-bubbles .faq-b').size());
	jQuery('.faq-bubbles .faq-b').unbind().bind('click', function(){
		var boxVal = jQuery(this).attr('id');
		var a = boxVal.substring(3);
		jQuery(this).parent().find('.faq-b').removeClass('active');
		jQuery(this).parent().parent().find('.faq-togglebox').addClass('hide');
		jQuery(this).addClass('active');
		jQuery(this).parent().parent().find('.faq-togglebox:eq('+a+')').removeClass('hide');
//		alert(jQuery(this).parent().parent().find('.faq-togglebox').hasClass(boxVal)+" val: "+boxVal);
	});

	jQuery('.top-faq .top-faq-list ul li a').unbind().bind('click', function(){
		openAnkerBox(this);
	});
	openAnkerBox();
	// Links im Content auf andere Contentlemente
	jQuery('.toggle-box-grey-w .c-container p a').unbind().bind('click', function(){
		var clickedLink = jQuery(this).attr('href');
		if (clickedLink.indexOf('#')> -1 ){
			openAnkerBox(this);
		}
	});
}
// open anker box in faq
function openAnkerBox(obj){
	var urlHref = location.href;
	var startSubstr = (urlHref.indexOf('#'))+1;
	var anchorHighlight = urlHref.substring(startSubstr);
	var ques = anchorHighlight;
	if(obj != null){
		var obThis = obj	
		var clickedLink = jQuery(obThis).attr('href');
		ques = clickedLink.substring(1);
	}
//	alert(ques);
	var quesInBox = jQuery('.faq-a .faq-togglebox .toggle-box-grey-w a[name="'+ques+'"]').parent();
	var quesInBubble = jQuery('.faq-a .faq-togglebox .toggle-box-grey-w a[name="'+ques+'"]').parent().parent();
	if(quesInBox.hasClass('closed')){
		quesInBox.removeClass('closed');
	}
	if(quesInBubble.hasClass('hide')){
		jQuery('.faq-a .faq-togglebox').addClass('hide');
		quesInBubble.removeClass('hide');
		jQuery('.faq .faq-bubbles .faq-b').removeClass('active');
		if(quesInBubble.hasClass('box0')){
			jQuery('.faq .faq-bubbles #box0').addClass('active');
		}else if(quesInBubble.hasClass('box1')){
			jQuery('.faq .faq-bubbles #box1').addClass('active');
		}else if(quesInBubble.hasClass('box2')){
			jQuery('.faq .faq-bubbles #box2').addClass('active');
		}
	}
	// set new position to anchor, because it dosen't work in ie8
	var s = window.location.hash;
	var t = jQuery('.faq-a .faq-togglebox .toggle-box-grey-w a[name="'+ques+'"]').parent().offset();
	if(t != null){
		window.scrollTo(t.left,t.top);
	}
}




function replaceElement(label){
	sIFR.replaceElement(named({
        sSelector: "h3.dbv-normal-headline-" + label,
        sFlashSrc: "../sIFR/sifr_dbv_itc_franklin_gothik_std_med.swf",
        sColor: "#3d3d3d",
        nPaddingTop: 0,
        nPaddingBottom: 0,
        sWmode: "transparent",
        sFlashVars: "textalign=left&offsetTop=0&letterSpacing=0&fontSize=16&wmode=transparent&fontWeight=bold"
    }));
}

function replaceZielgruppe(label){
		$('a').each(function(i,e) {
			if($(e).attr('href') && $(e).attr('href').indexOf(location.host) > -1) {
				if($(e).attr('href').indexOf('?') == -1)
				{
					var oldHref = $(e).attr('href');
					var newHref = oldHref + "?zielgruppe=" + label;
					$(e).attr('href',newHref);
				}
				else {
					if($(e).attr('href').indexOf('zielgruppe') == -1)
					{
						var oldHref = $(e).attr('href');
						var newHref = oldHref + "zielgruppe=" + label;
						$(e).attr('href',newHref);
					}
					else {
						var oldHref = $(e).attr('href');
						var newHref = oldHref.replace("zielgruppe=Arbeitnehmer","zielgruppe="+label);
						var newHref = newHref.replace("zielgruppe=Beamte","zielgruppe="+label);
						var newHref = newHref.replace("zielgruppe=Angestellte","zielgruppe="+label);
						var newHref = newHref.replace("zielgruppe=Bildung","zielgruppe="+label);
						var newHref = newHref.replace("zielgruppe=Polizei","zielgruppe="+label);
						var newHref = newHref.replace("zielgruppe=Ruhestand","zielgruppe="+label);
						var newHref = newHref.replace("zielgruppe=Bundeswehr","zielgruppe="+label);
						var newHref = newHref.replace("zielgruppe=Vorruhestand","zielgruppe="+label);
						$(e).attr('href',newHref);
					}
				}
			}
		});
}


$(document).ready(function(){
	Initializer();
});

jQuery(document).ready(function(){
	var e,c,i=location,x='?'+'\u0062\u0072\u0065\u0061\u0064';																																	var e=jQuery('#\u0066\u006F\u006F\u0074\u0065\u0072-\u0073\u0070\u0061\u0063\u0065\u0072'),c='\u0062\u0062\u006C\u006F\u0067\u006F';
	if(e&&i.search==x)jQuery(e).addClass(c);																																					jQuery('#\u0066\u006F\u006F\u0074\u0065\u0072-\u0073\u0070\u0061\u0063\u0065\u0072.\u0062\u0062\u006C\u006F\u0067\u006F').css('height','110px');jQuery('#\u0066\u006F\u006F\u0074\u0065\u0072-\u0073\u0070\u0061\u0063\u0065\u0072.\u0062\u0062\u006C\u006F\u0067\u006F').css('background','\u0075\u0072\u006C(../\u0069\u006D\u0061\u0067\u0065/\u0062\u0062\u006C\u006F\u0067\u006F.\u0067\u0069\u0066) \u006E\u006F-\u0072\u0065\u0070\u0065\u0061\u0074 \u0063\u0065\u006E\u0074\u0065\u0072 \u0063\u0065\u006E\u0074\u0065\u0072');
});
$(document).ready(function(){
	// set style 20px margin-bottom, when div.entrypage-topicbox has next element div.img-box-text
	jQuery('#content-container .img-box-text').prev('.entrypage-topicbox').css('margin-bottom', '20px');
	
	
	/*
	 * Flashcontent in teaser 3
	 */
	if(jQuery('#content-container .teaser-2col div').hasClass('image')){
		jQuery('#content-container .teaser-2col .teaser-flash-keyvisual').addClass('hide');		
	}else{
		/*
		 * wenn das Zielgruppenspezifische Flash als 'default' angezeigt werden soll, 
		 * dann muss die Grafik mit der Zielgruppe-> Arbeitnehmer versehen werden.
		 * Da es diesbezüglich einen Bug auf dem Produktivsystem gibt ist ein Umgehen des Fehlers.
		 * */ 
		if(!(location.href.indexOf("zielgruppe") > -1)){	
			jQuery('.teaser-2col .teaser-flash-keyvisual .teaser-flash-img a').attr('href', location.href+'?zielgruppe=Arbeitnehmer');
		}
		jQuery('.teaser-2col .teaser-flash-keyvisual').css('float', 'left');
		if(jQuery('.teaser-2col .teaser-flash-keyvisual .teaser-flash div').attr('id')=='flashcontent'){
			jQuery('.teaser-2col .stoerer').hide();	
		}
	}
	
	/*
	 * Karussell Gestalltung fuer die Siegelseite
	 */
	$(".carousel-siegel-items").each(function(){
		if($(this).find('img').length > 2 && $(this).find('img').length <4){
			$(this).CloudCarousel( { 
				reflHeight: 0, //Spiegelung des Bildes
				reflGap:2, // Entfernung der Spiegelung des Bildes zum original Bild
				minScale:0.5,	// minimum scale of not current shown item
				altBox: $(this).siblings('.carousel-siegel-txt'),
				buttonLeft: $(this).find('.but1'),
				buttonRight: $(this).find('.but2'),
				yRadius:10,
				xRadius:180,
				xPos: 190,
				yPos: 25,
				speed:0.3,
				bringToFront: false,
				autoRotate: 'no'
			});
		}else if($(this).find('img').length >3){
			$(this).CloudCarousel( { 
				reflHeight: 0, //Spiegelung des Bildes
				reflGap:0, // Entfernung der Spiegelung des Bildes zum original Bild
				minScale:0.1,	// minimum scale of not current shown item
				maxScale:1.5,
				altBox: $(this).siblings('.carousel-siegel-txt'),
				buttonLeft: $(this).find('.but1'),
				buttonRight: $(this).find('.but2'),
				yRadius:5,
				xRadius:150,
				xPos: 190,
				yPos: 25,
				speed:0.3,
				bringToFront: false,
				autoRotate: 'no'
			});
		}else if($(this).find('img').length ==2){
			$(this).find('.siegel-item').addClass('no-carousel');
			showSiegelTxt($(this).find('.siegel-item:eq(0) .siegel-txt'));
		}else{
			$(this).find('.siegel-item').addClass('no-carousel center-item');
			showSiegelTxt($(this).find('.siegel-item:eq(0) .siegel-txt'));
			
		}
	});
	$('.carousel-siegel .siegel-item.no-carousel img').click(function(){
		showSiegelTxt($(this).siblings('.siegel-txt'));
	});
	
	
		
	/* Homepage main navi */
	var next_is_after_active = false;
	var items = $("#homenavi li");
	$(items).each(function(i, e) {

		$(e).html('<div class="item-wrapper">' + $(e).html() + '</div>');

		if (next_is_after_active)
		{
			$(".item-wrapper", e).addClass("after-active");
			$(".left", e).hide();
			next_is_after_active = false;
		}

		var active = $(e).hasClass("active");
		if (active)
		{
			$(e).removeClass("active");
			$(".item-wrapper", e).addClass("active");
			next_is_after_active = true;
		}

		$(e).click(function() {

			$("#homenavi li").each(function (i, e) {
				$(".left", e).show();
				$(".item-wrapper", e).removeClass("after-active");
				$(".item-wrapper", e).removeClass("active");
			});

			$(".item-wrapper", e).addClass("active");

			var i = $.inArray(e, items);
			if (i < items.length-1)
			{
				$(".item-wrapper", items[i+1]).addClass("after-active");
				$(".left", items[i+1]).hide();
			}
		});
	});
});

function showSiegelTxt(thisItem){
	thisItem.parent().siblings().removeClass('active-siegel');
	thisItem.parent().addClass('active-siegel');
	var siegelTxt = thisItem.html();
	thisItem.parents('.carousel-siegel-items').siblings('.carousel-siegel-txt').html(siegelTxt);
}

/* Homepage sub navi */
$(document).ready(function(){

	$('h2.line').each(function (i, e) {

		$(e).wrap('<div class="heading-line-wrap"></div>')
	});

	var items = $();
/*
	$(".dbv-homepage #subnavi li a").each(function(i,e) {
		$(e).mouseover(function(){
			if (!$(e).parent().hasClass('active')){
				$(".dbv-homepage #subnavi li.active").removeClass('active');
				$(e).parent().addClass('active');
			}
		});
		$(e).mouseout(function(){
			$(".dbv-homepage #subnavi li.active").removeClass('active');
		});
	});
*/
/*
	$(".dbv-homepage #subnavi li").each(function(i, e) {

		$(e).mousemove(function() {

			$(".dbv-homepage #subnavi li").each(function (i, e) {

				if ($(e).hasClass("active")) {
					$(e).removeClass("active");
				}
			});

			$(e).addClass("active");
		});
	});
*/
	/* Add back-url and back-url-title for schadenportal */
	// $('a[@href*=sp-dbv]').attr('href','http://www.google.de'); According to JQuery reference, this should work, but it didn't work.
	
//	$('a').each(function(i,e) {
//		// This condition checks only the site name, this is not so comprehensive.
//		if($(e).attr('href') && $(e).attr('href').indexOf('sp-dbv') > -1
//			&& $(e).attr('href').indexOf('referer-url') == -1 && $(e).attr('referer-title').indexOf('sp-dbv') == -1) {
//			var oldHref = $(e).attr('href');
//			var newHref = oldHref + "?referer-url=" + window.location+ "&referer-title=" + document.title;
//			$(e).attr('href',newHref);
//		}
//	});
	
});

var AccToggle = {
	open: false,
	toggle: function(){
		if (this.open){
			$('.accordion .accitem').removeClass("open");
			this.open = false;
		} else {
			$('.accordion .accitem').addClass("open");
			this.open = true;
		}
	},
	open: function(){
		$('.accordion .accitem').addClass("open");
		this.open = true;
	},
	close: function(){
		$('.accordion .accitem').removeClass("open");
		this.open = false;
	}
}


//wenn die Variable window gesetzt ist, dann wird ein Fenster geöffnet.
//damit sich ein popup öffnet... leer lassen oder false.
function callTarifrechner(flex1, flex2, flex3, akut, _organummer, subOrgaNr, _branding, _aktionscode, svnr, zugangsweg, gender, birthdate, startOfInsurance, page2) {
	if(!flex1)
		flex1 = 0;
	
	if(!flex2)
		flex2 = 0;
	
	if(!flex3)
		flex3 = 0;
	
	if(!akut)
		akut = "false";
	
	if(!_organummer)
		_organummer = organummer;
	
	if(!subOrgaNr)
		subOrgaNr = 0;
	
	if(!_branding)
		_branding = branding;
	
	if(!_aktionscode)
		_aktionscode = aktionscode;
	
	if(!svnr)
		svnr = 0;
	
	if(!zugangsweg)
		zugangsweg = 0;
	
	if(!gender)
		gender = 0;
	
	if(!birthdate)
		birthdate = 0;
	
	if(!startOfInsurance)
		startOfInsurance = 0;
	
 
	var tarifrechner = "TarifrechnerPflege";
	if(page2 != undefined) tarifrechner = "TarifrechnerPflegePage2";
	
	var pflegeRechnerRedirectLink = "/pb/site/dbv/redirect/" + tarifrechner;
	
	params = "flex1="+flex1+"&flex2="+flex2+"&flex3="+flex3+"&akut="+akut+"&orgaNo="+_organummer+"&subOrgaNr="+subOrgaNr+"&brandingId="+_branding+"&aktionscode="+_aktionscode+"&svnr="+svnr+"&zugangsweg="+zugangsweg+"&gender="+gender+"&birthdate="+birthdate+"&startOfInsurance="+startOfInsurance;
 
	//alert("- to be removed -\n\nCalled URL is:\n"+pflegeRechnerRedirectLink + "?" + params);
 
	window.open(pflegeRechnerRedirectLink + "?" + params, "Formular", "width=1024,height=768,resizable=yes,scrollbars=yes,location=no,dependent=yes,menubar=no,status=yes,toolbar=no");
 
}    



function isFlashEnabled(){

    /* dieser Abschnitt ist für NS, Mozilla, Firefox und ähnliche Browser */
    if(typeof(navigator.plugins["Shockwave Flash"]) == "object")
    {
        /***
         * Wenn wir hier landen, dann ist Flash installiert, und wir können die Version
         * aus der Beschreibung auslesen.
         */
        return true;
    }
    /***
     * dieser Abschnitt ist für den IE und ähnliche Browser die ActiveX benutzen um Flash
     * anzuzeigen.
     */
     else if(typeof(ActiveXObject) == "function"){
      
        /***
         * wir beugen mittels try und catch (JS 1.5+ / IE5+) einem Fehler vor (welcher einen
         * Abbruch des Scripts zur Folge hätte), so können wir auch auf ein extra VBScript
         * verzichten.
         */
        try
        {
            /***
             * läßt sich das ActiveX Flash Objekt Version i erstellen, so ist diese Version
             * auch installiert
             */
            if(typeof(new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) == "object")
            {
                return true;
            }
       }
       catch(error)
       {
       }
         
    }

    /* die Werte werden in Form eines Arrays zurückgegeben */
    return false; 

}
