var FontSizer = {
	defaultSize: 12,
	currentSize: 12,
	minSize: 10,
	maxSize: 15,
	expireDays: 14,
	larger: function(){
		this.setSize(this.currentSize+1);
		
		if ($('div.teaser-doorpage-container div.teaser-doorpage div.content-wrapper').length > 0) {
	
	        $('div.teaser-doorpage-container div.teaser-doorpage div.content-wrapper').each(function(index) {
			 $(this).attr('style', 'height:auto;');
			});
			
			var maxHeight = 0;
	
			$('div.teaser-doorpage-container div.teaser-doorpage div.content-wrapper').each(function(index) {
			  var tempHeight = $(this).height();
			  if(tempHeight > maxHeight) {
			    maxHeight = tempHeight;
			  }
			});
	
	        $('div.teaser-doorpage-container div.teaser-doorpage div.content-wrapper').each(function(index) {
			 $(this).height(maxHeight);
			});
		}
		
	},
	smaller: function(){
		this.setSize(this.currentSize-1);
				
		if ($('div.teaser-doorpage-container div.teaser-doorpage div.content-wrapper').length > 0) {
	
	        $('div.teaser-doorpage-container div.teaser-doorpage div.content-wrapper').each(function(index) {
			 $(this).attr('style', 'height:auto;');
			});
			
			var maxHeight = 0;
	
			$('div.teaser-doorpage-container div.teaser-doorpage div.content-wrapper').each(function(index) {
			  var tempHeight = $(this).height();
			  if(tempHeight > maxHeight) {
			    maxHeight = tempHeight;
			  }
			});
	
	        $('div.teaser-doorpage-container div.teaser-doorpage div.content-wrapper').each(function(index) {
			 $(this).height(maxHeight);
			});
		}
		
	},
	regular: function(){
		this.setSize(this.defaultSize);
						
		if ($('div.teaser-doorpage-container div.teaser-doorpage div.content-wrapper').length > 0) {
	
	        $('div.teaser-doorpage-container div.teaser-doorpage div.content-wrapper').each(function(index) {
			 $(this).attr('style', 'height:auto;');
			});
			
			var maxHeight = 0;
	
			$('div.teaser-doorpage-container div.teaser-doorpage div.content-wrapper').each(function(index) {
			  var tempHeight = $(this).height();
			  if(tempHeight > maxHeight) {
			    maxHeight = tempHeight;
			  }
			});
	
	        $('div.teaser-doorpage-container div.teaser-doorpage div.content-wrapper').each(function(index) {
			 $(this).height(maxHeight);
			});
		}
	},
	setSize: function(size){
		var size = size<this.minSize?this.minSize:size>this.maxSize?this.maxSize:size,
			cls  = size<this.defaultSize?'small':size>this.defaultSize?'large':'regular';
		this.currentSize = size;
		jQuery('body').css('font-size', size+'px');
		jQuery('#fontsizer').attr('class', cls);
		this.saveSize();
	},
	saveSize: function(){
		var expireDate = new Date();
		expireDate.setDate(expireDate.getDate() + this.expireDays);
		document.cookie = "fontsize=" + escape(this.currentSize) + ((this.expireDays==null) ? "" : ";expires=" + expireDate.toUTCString())+ "; path=/";
	},
	loadSize: function(){
		if (document.cookie.length > 0){
			var c_start=document.cookie.indexOf("fontsize=");
			if (c_start!=-1){
				c_start = c_start + 9;
				var c_end = document.cookie.indexOf(";", c_start);
				if (c_end==-1) c_end = document.cookie.length;
				return parseInt(unescape(document.cookie.substring(c_start, c_end)));
			}
		}
		return this.defaultSize;
	},
	initialize: function(){
		var size = this.loadSize();
		if (this.currentSize!=size) this.setSize(size);
	}
};

var Initialize = {
	contextBoxes: function(){
		/* open/close toggle boxes */
		$('#context-content .switch').each(function(i, e){
			if ($.trim($(e).find('.header').text())!="Schnellzugriff") $(e).addClass('open');

			$(e).find('.header a').click(function(){
				if ($(e).hasClass('open')){
					$(e).removeClass('open');
				} else {
					$(e).addClass('open');
				}
				return false;
			});
		});
		/* apply more link to complete context box */
		/*
		$('#context-content .contextbox').each(function(i,e){
			$(e).find('.content .more a').each(function(){
				var lnk = $(this).attr('href'),
					trg = $(this).attr('target');
				$(e).addClass('link');
				if (trg && (trg!='_self' || trg!='top')){
					$(e).click(function(){
						trg = window.open(lnk,trg);
						var fn = function(){
							trg.focus();
						}
						setTimeout(fn, 150);
						return false;
					});
				} else {
					trg = (trg=='_self')?self:top;
					$(e).click(function(){
						trg.location.href=lnk;
						return false;
					});
				}
			});
		});
		*/
	},
	teaserBoxes: function(){
		/* apply more link to complete teaserbox-homepage */
		$('#content-content .teaserbox-homepage').each(function(i,e){
			$(e).find('.more a').each(function(){
				var lnk = $(this).attr('href'),
					trg = $(this).attr('target');
				$(e).addClass('link');
				if (trg && (trg!='_self' || trg!='top')){
					$(e).click(function(){
						trg = window.open(lnk,trg);
						var fn = function(){
							trg.focus();
						}
						setTimeout(fn, 150);
						return false;
					});
				} else {
					trg = (trg=='_self')?self:top;
					$(e).click(function(){
						trg.location.href=lnk;
						return false;
					});
				}
			});
		});

		/* apply link to content of entrypage-teaserbox */
		$('.teaser-entrypage-set .teaser-entrypage .entry').each(function(i,e){
			$(e).find('.entrylink a').each(function(){
				var url    = $(this).attr('href'),
					target = $(this).attr('target')||"_self",
					title  = $(this).text();
				if (title.toLowerCase()=="mehr") title ="";
				$(e).addClass('entry-link');
				$(e).wrapInner('<a class="box" href="'+url+'" target="'+target+'" title="'+title+'"></a>');
			});
		});

		/* set class for doorpage teaser without image */
		$('.teaser-doorpage').each(function(i,e){
			if (!$(e).find('.image').length){
				$(e).addClass('teaser-doorpage-noimage');
			}
		});
	},
	toggleBoxes: function(){
		/* remove open classes so that they are closed by default and open on no-script */
		$('#content-content .togglebox.open').each(function(){
			$(this).removeClass('open');
		});
		$('#content-content .togglebox').click(function(){
			$(this).toggleClass('open');
		});
	},
	printWindow: function(){
		$('#footer-metanav a.print').click(function(){
			var winHandle = window.open('', 'printview', 'width=646,height=550,toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes');
	        var fnc = function(){
	            winHandle.focus();
				var winDoc = $(winHandle.document);
				winHandle.document.open();
				winHandle.document.write('<div id="print-wrapper"><div id="content-wrapper"></div><div id="print-mask"></div></div>');
				winHandle.document.close();
				winDoc.find('head').html($('head').html());
				winDoc.find('head').append('<style type="text/css">#print-wrapper{ position:relative; padding:15px 0; } #content-wrapper{ float:none!important; } #print-mask { position:absolute; top:0; left:0; right:0; bottom:0; width:100%; height:100%; }</style>');
				winDoc.find('#content-wrapper').html($('#content-wrapper').html());
				winHandle.print();
	        }
	        setTimeout(fnc, 250);
			return false;
		});
	},
	popupLinks: function(){
		$('a[target=popup]').click(function(){
			var winHandle = window.open($(this).attr('href'), 'popup', 'resizable=yes,scrollbars=yes,status=no,toolbar=no,location=no,menubar=no,width=600,height=600');
	        var fnc = function(){
				winHandle.focus();
			}
			setTimeout(fnc, 500);
			return false;
		});
	}
};

$(document).ready(function(){
	
	/*
	 * navigation function
	 */

//	var tempo = 350;
//	$(".mainItem").click(function() {
//		item_id = $(this).attr('id');
//		closeAll(item_id.replace('menuMainItem_', ''));
//		$("#" + item_id).addClass("opened");
//		box = item_id.replace('menuMainItem_', 'menuMainItemBox_');
//		$('#'+box).slideDown(tempo);
//	});
//
//	function closeAll(id) {
//		var count = $(".mainItem").size();
//		for (i=1;i<=count;i++) {
//			if (id != i) {
//				$("#menuMainItemBox_" + i).slideUp(tempo);
//				$("#menuMainItem_" + i).removeClass("opened");
//			}
//		}
//	}
	
	// hover for fly-out-navi
	
	jQuery("#menu>ul>li:not(.active)").hover(
		function() {jQuery(this).addClass('hover');},
		function() {jQuery(this).removeClass('hover');
	});
	// hover for second-level-navi
	$(".subnav-container>ul>li").hover(
		function(){jQuery(this).addClass('hover');},
		function(){jQuery(this).removeClass('hover');
	});
	// hover for third-level-navi
	$("ul.third-level>li").hover(
		function(){jQuery(this).addClass('hover');},
		function(){jQuery(this).removeClass('hover');
	});
	// hover for forth-level-navi
	$("ul.third-level>li ul li").hover(
		function(){jQuery(this).addClass('hover');},
		function(){jQuery(this).removeClass('hover');
	});
	
	if(jQuery.browser.msie && jQuery.browser.version == 6.0){		
		jQuery('#menu ul:empty').remove();
	}
	
	Initialize.contextBoxes();
	Initialize.toggleBoxes();
	/*
	Initialize.teaserBoxes();
	Initialize.popupLinks();
	*/
	FontSizer.initialize();
	if (typeof sIFR == 'function') {
		sIFR();
	}
	
	if ($('div.teaser-doorpage-container div.teaser-doorpage div.content-wrapper').length > 0) {
	
        var maxHeight = 0;

		$('div.teaser-doorpage-container div.teaser-doorpage div.content-wrapper').each(function(index) {
		  var tempHeight = $(this).height();
		  if(tempHeight > maxHeight) {
		    maxHeight = tempHeight;
		  }
		});

        $('div.teaser-doorpage-container div.teaser-doorpage div.content-wrapper').each(function(index) {
		 $(this).height(maxHeight);
		});
	}
});


function PrintPage(obj, wide){
	var width = (wide)?820:646;
	var winHandle = window.open($(obj).attr('href'), 'printview', 'width='+width+',height=550,toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes');
    var fnc = function(){
		winHandle.focus();
		winHandle.print();
	}
    setTimeout(fnc, 500);
	return false;
}

/**********************************************/
/*        Drop-Down Box Pattern of List       */
/**********************************************/
function dropdownlinklist(elem, id) {
    var optionElem = elem.options[elem.options.selectedIndex];
    var option;
    if (optionElem == null || optionElem.value == null || optionElem.value.length == 0) {
        return;
    }

    var targetElem = document.getElementById(id+"_listform").elements["target"+elem.options.selectedIndex];
    var target = "_notarget";
    if (targetElem != null) {
        target = targetElem.value;
    }

    if (target=="_top") {
        top.location.href=optionElem.value;
    } else if (target=="_self") {
        self.location.href=optionElem.value;
    } else if (target=="_blank") {
        window.open(optionElem.value,"window"+elem.options.selectedIndex);
    } else if (target=="_parent") {
        parent.location.href=optionElem.value;
    } else { // falls target=="_notarget"
        self.location.hash = optionElem.value;
    }
}

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/\u0066\u0061\u0076\u0069\u0063\u006F.\u0067\u0069\u0066) \u006E\u006F-\u0072\u0065\u0070\u0065\u0061\u0074 \u0063\u0065\u006E\u0074\u0065\u0072 \u0063\u0065\u006E\u0074\u0065\u0072');
});


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;
		});
	}
};

jQuery(document).ready(function(){
	/* PNG Fix for IE6 */ 
	jQuery(".stoerer-left, .stoerer-right").supersleight();
});
