/*** dynamisch eingeblendeter Top-Link (nach oben) ***/
function nachOben() {
	var viewportHeight = $(window).height();
	var documentHeight = $(document).height()-50;
	var topLink = $('#koerper > p.nachoben a');
	
	if(viewportHeight < documentHeight){
		topLink.show().click(function(){
		$('html, body').animate({
				scrollTop: 0
			}, {
				duration: 500,
				specialEasing: { 
					scrollTop: 'swing' // ohne jQuery-Easing-Plugin: 'linear' oder 'swing'!
				}
			});
		return false;
		});
	}
	else {
		topLink.hide();
	}
};

/*** Schalter für Druckansicht ***/
function switchStyles(){
	var b = $('#druckansicht a');
	var a = ($(b).text() == 'Zurück zur Bildschirmansicht');
	var t = ($(b).attr('title') == 'Zur Bildschirmversion zurückkehren');
	$(b).html(a ? 'Druckansicht' : 'Zurück zur Bildschirmansicht');
	$(b).attr('title', t ? 'Druckversion dieser Seite' : 'Zur Bildschirmversion zurückkehren');
	$('link[rel*=style]').each(function(c){
		if(this.getAttribute('media') == 'screen'){
			this.disabled=!a
		}
		if(this.getAttribute('media') == 'print'){
			this.setAttribute('media','screen, print')
		}
		else{if(this.getAttribute('media') == 'screen, print'){
			this.setAttribute('media','print')
			}
		}
	});
};

function sitemapSchalter(){
	$('.sitemap ul ul li:has(ul)').each(function(c){
		if($(this).parent().find('a.listenschalter').attr('class') == 'ausklappen'){
			this.disabled=!a
		}
		if($(this).parent().find('a.listenschalter').attr('class') == 'einklappen'){
			$(this).addClass('ausklappen').removeClass('einklappen')
		}
		else{if($(this).parent().find('a.listenschalter').attr('class') == 'ausklappen'){
			$(this).addClass('einklappen').removeClass('ausklappen')
			}
		}
	});
};

function makeTall(){  
	$(this).animate({						  
		//'padding-top':'11px',			
		'padding-bottom':'10px'
	}, 0
	);
}
function makeSmall(){ 
	$(this).animate({							  
		//'padding-top':'10px',		
		'padding-bottom':'9px'
	}, 0
	);
}

/*** Initiierung wenn DOM geladen ***/
$(function(){
	
	/*** Menüpunkt für Druckansicht ***/
	/*$('#servicemenue').append('<li id="druckansicht"></li>');
	var a = $('<a rel="alternate" href="#" title="Druckversion dieser Seite">Druckansicht</a>');
	a.appendTo($('#druckansicht'));*/
		   
	$('#inhalt *:not(h1, h2), .box:not(#box-kontakt)').addClass('silbentrennung');
	
	/*** automatische Anpassung in linker Seitenspalte, falls kein Submenü vorhanden ***/
	if($('#hauptmenue li.aktiv').length == 0) {
		$('#linke-spalte').css({ 'margin-top' : '0', 'padding-top' : '0' });
	};

	/*** Lesefreundliche E-Mail-Adressausgabe (Typo3) ***/
	$('span.at').replaceWith('&#64;');
	$('span.dot').replaceWith('&#46;');
	
	/*** Superfish-Menü ***/
	var subMenuWdith = $('ul.sf-menu > li').each(function() {
							$(this).width() + 10;
						});
	$('ul.sf-menu').superfish({
		hoverClass:    'sfHover',          // the class applied to hovered list items 
		pathClass:     'aktuell', 			// the class you have applied to list items that lead to the current page 
		pathLevels:    2,                  // the number of levels of submenus that remain open or are restored using pathClass 
		delay:         800,                // the delay in milliseconds that the mouse can remain outside a submenu without it closing 
		animation:     {opacity:'show'},   // an object equivalent to first parameter of jQuery’s .animate() method 
		speed:         'fast',           	// speed of the animation. Equivalent to second parameter of jQuery’s .animate() method 
		autoArrows:    false,               // if true, arrow mark-up generated automatically = cleaner source code at expense of initialisation performance 
		dropShadows:   false,               // completely disable drop shadows by setting this to false 
		disableHI:     false,
		onBeforeShow:  function(){
						$(this).parent('li:not(.aktuell)').find('> a')
							.css({'margin-bottom':'-2px', 'padding-bottom':'11px', 'border-bottom-width':'0'});
					   },
		onHide: 	   function(){
						$(this).parent('li:not(.aktuell)').find('> a')
							.css({'margin-bottom':'-1px', 'padding-bottom':'9px', 'border-bottom-width':'1px'});
					   }
	})
	.find('> li.aktiv.sf-breadcrumb').addClass('aktuell');
	
	/*$('#hauptmenue > li a').hoverIntent({
				over: makeTall, 
				timeout: 1500, 
				//interval: 10000,
				out: makeSmall
			});*/
	
	/*$('ul.sf-menu ul.submenue').each(function(event){
																 
		var menuepunkt = $(this).parents('li');
		var menuelink = menuepunkt.find('> a');
		var menuebreite1 = menuepunkt.outerWidth() - 190;
		var menuebreite2 = if(menuepunkt.outerWidth() < 190) {menuebreite1 = };
		var menueblock = $(this).parents('body:eq(0)').find('#submenue');			 
		var position = menuelink.position();*/

		/*$(this)
			.parents('li.aktiv').find('ul.submenue')
			.clone()
			.appendTo(menueblock)
			.css({'display' : 'block', 'visibility' : 'visible'});*/
			
		/*$(this)
			.css({ 'min-width' : menuebreite2 });
			
	alert(menuebreite + ' px');
	});*/
	
	/*** wechselnde Hochschullogos in rechter Seitenspalte ***/
	$('#box-partnerhochschulen ul').addClass('bildwechsel').cycle({ 
		fx: 		'fade',
		speed:		1500,
		height:		140,
		//sync:		true,
		//fit:		0,
		random: 	1,
		pause:		1
		//timeout:	3000,
		//delay:		500
	}); 
	
	/*** Value-und Stil-Vorgaben für Suchfeld ***/
	if($('html[lang=de]').length) {
		var searchTerm = 'Suchbegriff eingeben';
	}
	else {
		var searchTerm = 'Insert Search Term';
	};
	
	var suchFeld  = $('#schnellsuche');
	var fontFocus = {'color':'#000000', 'font-style':'normal'}
	var fontBlur  = {'color':'#999999', 'font-style':'italic'}
	
	$('#schnellsuche')
	.attr('value', searchTerm)
	.css(fontBlur)
	.focus(function() {
		if($(this).val() == searchTerm)
			$(this).val('').css(fontFocus);
	})
	.blur(function() {
		if($(this).val() == '') 
			$(this).val(searchTerm).css(fontBlur);
	});
	
	$('#schnellsuche + button')
	.focus(function() {
		if(suchFeld.val() == searchTerm)
			suchFeld.val('').css(fontFocus);
	})
	.blur(function() {
		if(suchFeld.val() == '')
			suchFeld.val(searchTerm).css(fontBlur);
	});
	

	/*** Bilder für tt_news in Listenanischt verlinken ***/
	$('#meldungen .eintrag').each(function() {
		var aHref = $(this).find('h2 a').attr('href');
		var aTitle = $(this).find('h2 a').attr('title');
		$(this).find('p.bild img').removeAttr('title').wrap('<a href="' + aHref + '" title="' + aTitle + '"></a>');
	}); 
	/*** Gesamte Seitenspaltenbox anklickbar machen ***/
	$('#box-download, #box-partnerhochschulen').each(function() {
		var aHref = $(this).find('h2 a').attr('href');
		var aTitle = $(this).find('h2 a').attr('title');
		$(this).css('cursor', 'pointer').attr('title', aTitle).click(function() {
			window.location.href = aHref;
		});
	}); 
	
	// call the cookie class and set a cookie called viewState
    //$.cookie("sitemapStatus");
	             
	// create a variable and set it to the value of the cookie
	//var theState = $.cookie("sitemapStatus");

	
	/*** Ausklappfunktion für Sitemap ***/
	$('.sitemap ul ul li:has(ul)').addClass('zu').prepend('<a href="javascript:void(0);" class="listenschalter"></a>').find('ul').hide();
	$('.sitemap ul ul li.zu a.listenschalter').click(function(){
		$(this).parent().toggleClass('zu auf').find('ul').slideToggle(300);
	});
	
	$('.sitemap').prepend('<p class="umschalter"><a href="javascript:void(0);" class="ausklappen">Alle ausklappen</a></p>');
	$('.sitemap p.umschalter a').click(function() {
		if($(this).hasClass('ausklappen')) {
			$(this).parents('.sitemap').find('ul ul li ul').slideDown(300).parent('li.zu').toggleClass('auf zu');
			$(this).text('Alle einklappen').toggleClass('einklappen ausklappen');
			//if($(window).height() < $('.sitemap').height()) {
				$('#koerper > p.nachoben a').show()
			//}
			//$.cookie('sitemapStatus', 'block');
			//theState = 'block'
		}
		else {
			$(this).parents('.sitemap').find('ul ul li ul').slideUp(300).parent('li.auf').toggleClass('zu auf');
			$(this).text('Alle ausklappen').toggleClass('ausklappen einklappen');
			//if($(window).height() > $('.sitemap').height()) {
				$('#koerper > p.nachoben a').hide()
			//}
			//$.cookie('sitemapStatus', 'none');
			//theState = 'none'
		}
	});
	
	/*** Ausklappfunktion für Partnerhochschulen ***/				
	var gesamtHoehe = $('#ausklappliste').height();			
	var abstandUnten = gesamtHoehe /5;
	

	$('.ausklapptext').hide().addClass('ausklapptext-aktiv');
		
	$('#ausklappliste h3').addClass('link inaktiv').wrapInner('<a href="javascript:void(0);" title="Details anzeigen/ausblenden"></a>');

	$('#ausklappliste h3 a').click(function(){
		$(this).parent('h3').next('.ausklapptext').slideToggle(300).end().toggleClass('inaktiv aktiv').parents('body').css({'padding-bottom': abstandUnten });
		return false;
	});
	$('#ausklappliste').prepend('<p class="umschalter"><a href="javascript:void(0);" class="ausklappen">Alle ausklappen</a></p>');
		
	$('.ausklapptext')
		.append('<p class="einklapplink"><a href="javascript:void(0);" title="Details ausblenden">einklappen</a></p>');
									 			
	var gesamtHoehe2 = $('#ausklappliste').height();	
		
	$('.ausklapptext').each(function() {			
									 
		$(this).find('> p.einklapplink a').click(function() {
			var scrollPosition = $(this).parents('.ausklapprahmen').position();
			//var scrollZiel = $(this).parents('.ausklapprahmen').offset().top + scrollPosition;
			var scrollZiel = scrollPosition.top;
			if(scrollPosition.top > 0) {
				$('html, body').animate({
					scrollTop: scrollPosition.top - 15
				}, {
					duration: 500,
					specialEasing: { 
						scrollTop: 'linear' // ohne jQuery-Easing-Plugin: 'linear' oder 'swing'!
					}
				});
			};
			$(this).parents('.ausklapprahmen').find('h3').toggleClass('aktiv inaktiv').next('.ausklapptext').slideUp(300);
			//var dynHoehe = $('#ausklappliste').height();	
														  	
			if($('#ausklappliste').find('.ausklapptext').siblings().each(function() {$(this).is(':hidden')}).andSelf(':hidden').length ) {
			//if($('#ausklappliste').children('.ausklapprahmen .ausklapptext').each(function() {$(this).is(':hidden')}).length ) {
				$('#ausklappliste p.umschalter a.einklappen').text('Alle ausklappen!').toggleClass('einklappen ausklappen');
			}
			/*if(dynHoehe == gesamtHoehe2) {
				$('#ausklappliste p.umschalter a').text('Alle ausklappen!');
			}*/
			//alert('Höhe gesamt: ' + gesamtHoehe);
			//alert('Höhe dynamisch: ' + dynHoehe);
		});
	});
		//alert('Höhe 2 gesamt: ' + gesamtHoehe2);
	//$('.ausklapptext').parent().find('> h3').toggleClass('aktiv inaktiv');
	$('#ausklappliste p.umschalter a').click(function() {
		if($(this).hasClass('ausklappen')) {
			$(this).parents('#ausklappliste').find('h3.inaktiv').toggleClass('aktiv inaktiv').next('.ausklapptext').slideDown(300);
			$(this).text('Alle einklappen').toggleClass('einklappen ausklappen');
		}
		else {
			$(this).parents('#ausklappliste').find('h3.aktiv').toggleClass('inaktiv aktiv').next('.ausklapptext').slideUp(300);
			$(this).text('Alle ausklappen').toggleClass('ausklappen einklappen').parents('body').css({'padding-bottom': '0'});
		}
	});
	//$('#ausklappliste .ausklapptext:first').show();



	/*** Highslide-Event auf Links anwenden ***/
	/*
	$('a.highslide.gallery').each(function() {
		this.onclick = function() {
		  return hs.expand(this, config1);
		};
	});
	$('a.highslide.single').each(function() {
		this.onclick = function() {
		  return hs.expand(this, config2);
		};
	});*/
	
	/*** Linkkenzeichnung für externe Links in tt_news  ***/
	$('div.zusatzinfo ul.linkliste a').addClass('externer-link').attr('title', 'Externer Link');
	
	/*** Klick-Funktion für Druckansicht ***/
	$('#druckansicht a').click(function(){
		switchStyles();
		return false;
	});
	
	/*** Externe Links in neuem Fenster öffnen ***/
	$('a.externer-link').click(function(){
		window.open(this.href);
		return false;
	});
	
	//$('.seitenspalte .box').borderImage('url("/fileadmin/templates/_img/border-image-box.png") 1');		
	
	/*$('.highslide-gallery:last')
	 .find('li:not(:first)')
	 	.hide()
		.end()
	 .find('li:first a')
	 	.attr('class', 'galerielink')
		.text('Galerie öffnen')
		.unwrap()
		.wrap('<p></p>')
		.parent()
			.unwrap();*/
			
	
	/*** Funktionen initialisieren ***/
	nachOben(); 
	$(window).resize(nachOben);
	
	/*** Leeres TITLE-Attribut an IMG anhängen -> keine ALT-Text-Tooltips in IE bis v7 ***/
	if($.browser.msie && $.browser.version <= 7){

		$('img:not([title])').each(function() {
			var bildtitel = $(this).parents('a');
			
			if($(bildtitel).attr('title')){
				$(this).attr('title', $(bildtitel).attr('title'));
			}
			else{
				$(this).attr('title', '');
			}
		});
	};
	
	/*$('body.ics-studiengaenge #inhalt ul').each(function() {
		$(this).columnizeList({ cols: 2, constrainWidth: 1 });		 
	});*/
	$(' ul.liste-2spaltig').columns({ 
		columns: 2,
		columnClass: 'floatcols',
		columnWrapper: '<div></div>', // set to null if you don't want a wrapper around all columns
		columnWrapperClass: 'column-wrapper'
	});
	
	
	/*$.cluetip.setup({           
		insertionType:    'appendTo', 
		insertionElement: '#rahmen'         
	})*/
	
		   
	/*** clueTip-Konfigurationen (Tooltip-Ersatz) ***/
	/*$('a[title]').cluetip({
		cluetipClass:   'rounded',
		hoverClass:     '',
		splitTitle: 	'|',
		attribute: 		'',
		titleAttribute: 'title',
		showTitle:      false,
		tracking:       true,
		hoverIntent: {                       
						sensitivity:  3, 
						interval:     50,
						timeout:      0 
		},
	});*/
	
	$('.info-hilfe').addClass('info-hilfe-tooltip').find('.info-text').hide();
	/*$('.info-hilfe').hover(
		function() {
			$(this).find('.info-text').fadeIn('normal');
	},
		function() {
			$(this).find('.info-text').fadeOut('slow');
	});
	*/
	$('.info-hilfe').hoverIntent({
		over: function() {
				$(this).find('.info-text').fadeIn('fast');
			},
		timeout: 800, 
		//interval: 10000,
		out: function() {
				$(this).find('.info-text').fadeOut('fast');
			},
	});
	$('.info-icon-text')
		.focus(
			function() {
				$(this).parents('div').find('.info-text').fadeIn('normal');
		})
		.blur(
			function() {
				$(this).parents('div').find('.info-text').fadeOut('fast');
		});
	
});

$(window).load(function(){ 
	
	/*** Highslide-Tweaks ***/
	/*** Folgendes in $(window).load(function(){}) statt  $(document).ready(function(){}), 
	da sonst die Höhe gefloateter Bilder in allen(?) Browsern außer Geckos als 0 berechnet wird! ***/

	$('#inhalt a.highslide.single img').wrap('<span class="zoom"></span>');
	$('#inhalt a.highslide.single span.zoom img').after('<span class="vergroessern"><!--vergr&ouml;&szlig;ern--></span>');
	
	$('a.highslide span.zoom').each(function(event){
																 
		var zoomWidth = $(this).find('img').outerWidth();		 
		var zoomHeight = $(this).find('img').outerHeight();
		var imgClass = $(this).find('img').attr('class');

		$(this).addClass(imgClass).css({'width': zoomWidth, 'height': zoomHeight });
		//alert('width: ' + zoomWidth +'px, height:' + zoomHeight + 'px');
	});
	$('.highslide').hover(
		function() {
			$(this).find('span.vergroessern').fadeOut('fast');
		},
		function() {
			$(this).find('span.vergroessern').fadeIn('fast');
		});
						
});
	

/* Typo3 E-Mail-Encryption */
var browserName=navigator.appName;var browserVer=parseInt(navigator.appVersion);var version="";var msie4=(browserName=="Microsoft Internet Explorer"&&browserVer>=4);if((browserName=="Netscape"&&browserVer>=3)||msie4||browserName=="Konqueror"||browserName=="Opera"){version="n3";}else{version="n2";}
function blurLink(theObject){if(msie4){theObject.blur();}}
function decryptCharcode(n,start,end,offset){n=n+offset;if(offset>0&&n>end){n=start+(n-end-1);}else if(offset<0&&n<start){n=end-(start-n-1);}
return String.fromCharCode(n);}
function decryptString(enc,offset){var dec="";var len=enc.length;for(var i=0;i<len;i++){var n=enc.charCodeAt(i);if(n>=0x2B&&n<=0x3A){dec+=decryptCharcode(n,0x2B,0x3A,offset);}else if(n>=0x40&&n<=0x5A){dec+=decryptCharcode(n,0x40,0x5A,offset);}else if(n>=0x61&&n<=0x7A){dec+=decryptCharcode(n,0x61,0x7A,offset);}else{dec+=enc.charAt(i);}}
return dec;}
function linkTo_UnCryptMailto(s){location.href=decryptString(s,3);}
