$(document).ready(function(){


	//target blank
	$("a[href^='http://']").attr('target','_blank');
	$("a[href^='http://']").addClass('extern');
	
	$("a.targettop").attr('target','_top');
	
	$("a[href$=.pdf]").addClass('pdf');
	$("a[href$=.doc]").addClass('doc');
	$("a[href$=.xls]").addClass('xls');
	$("a[href$=.docx]").addClass('docx');
	$("a[href^=mailto]").addClass('mailto');
	
	
	$('#navigation ul').each(function(){
		if ($(this).find('>li').size()==1) {
			$(this).append('<li></li>');
		}
	});
		
	$("ul li:first-child").addClass('first');
	$("ul li:last-child").addClass('last');


	//for special effects in the navi
//	$('#navigation ul ul').parent().addClass('sub');
	
	//fix the corner for hovers
	$('#navigation ul ul').parent().mouseover(function(){
//		$(this).children('a').addClass('corner');
	});
	$('#navigation ul ul').parent().mouseout(function(){
//		$(this).children('a').removeClass('corner');
	});
		
	
	$('#navigation li.sub').mouseover(function(){
//		$(this).addClass('hover');
	});
	
	$('#navigation li.sub').mouseout(function(){
//		$(this).removeClass('hover');
	});


	/* Team Mouseovers */
	$('#team img').hover(function(){
		var oldpic = $(this).attr('src');		
		var newpic = oldpic.replace(/.jpg/i, "_o.jpg");
		$(this).attr('src',newpic);		
	},function(){
		var oldpic = $(this).attr('src');		
		var newpic = oldpic.replace(/_o.jpg/i, ".jpg");
		$(this).attr('src',newpic);		
	});


	/* Buchcast */
	jQuery('a.buchcast').each(function(){
		var me = jQuery(this);
		var file = me.attr('href');
		var title = me.html();
		var mum = me.parent(); // p tag
		var brother = jQuery('<div class="buchcast"></div>');
		me.removeClass('buchcast');
		
		brother.html('<h5>'+title+'</h5><audio style="display:none;" class="buchcast" style="width:100%" src="'+file+'" type="audio/mp3" controls="controls"></audio>');
		mum.after(brother);
		mum.remove();
	});
	
	setTimeout(function(){
		jQuery('audio.buchcast').mediaelementplayer({
		audioWidth: 218,
		features: ['playpause','progress']
	});

	},500);



	/* Lightbox */
	if ($('.jaosg_thumbnail').size() > 0) {
			
		$('.jaosg_thumbnail a').lightBox({
				overlayBgColor: '#570019',
				overlayOpacity: 0.6,
				imageLoading: 'redaxo/include/addons/rexgalerie/data/lightbox/loading.gif',
				imageBtnClose: 'redaxo/include/addons/rexgalerie/data/lightbox/lightbox-btn-close.gif',
				imageBtnPrev: 'redaxo/include/addons/rexgalerie/data/lightbox/lightbox-btn-prev.gif',
				imageBtnNext: 'redaxo/include/addons/rexgalerie/data/lightbox/lightbox-btn-next.gif',
				imageBlank: 'redaxo/include/addons/rexgalerie/data/lightbox/lightbox-blank.gif',
				txtImage: '',
				txtOf: ' / ',
				containerResizeSpeed: 350
		});	

	}

	


	/*if (document.attachEvent)
	{
		// Suckerfish Hovers
		// Hinweis: Wenn es im html kein Element mit id="navigation" gibt, getElementById("navigation") loeschen oder austauschen
		var sfEls = document.getElementById("navigation").getElementsByTagName("UL")[0].getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}*/

	/* Toggle DIVS (Accordeon) */
	
	$('.accordeon').each(function(){
		$('.accordeon .accordeon-body').hide();	
		
		var h2 = $(this).find('h2');		
		
		h2.click(function(){
			var h2 = $(this);
			var body = $(this).parent().find('.accordeon-body');
			var allh2 = $('.accordeon').find('h2');
			
			
			if (body.css('display')=='none') {
				allh2.removeClass('active');
				h2.addClass('active');
				
				$('.accordeon .accordeon-body').slideUp('slow');
				body.slideDown('slow');
				
			} else {
				allh2.removeClass('active');
				body.slideUp('slow');
			}
		});
		
		
	});


	//	
	if($('#content2 .accordeon:eq(0)').hasClass('accordeon')){
		$('#content2 .accordeon:eq(0)').find('h2').trigger('click');	
		
	}


	$('a.accordeon-head').click(function(){
		$(this).trigger('blur');
	    return false;
	});
	// open up the first toggle div
	//$('.accordeon:eq(0) h3:eq(0)').trigger('click');

	/* end Toggle DIVS (Accordeon) */
	
	

	
	/* Anfahrt / GoogleMaps */
	$("a.s94").attr('href',$("a.s94").attr('href')+'?plain=1');
	$("a.s94").fancybox({
			'width'				: 810,
			'height'			: 530,
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
	});
	// Anfahrt Sidebar
	$(".anfahrt a").attr('href',$(".anfahrt a").attr('href')+'?plain=1');
	$(".anfahrt a").fancybox({
			'width'				: 810,
			'height'			: 530,
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
	});
	
	// REXKalender
	$(".rexkal-moredetails").each(function(){
		$(this).attr('href',$(this).attr('href')+'?plain=1');
	});
	$(".rexkal-moredetails").fancybox({
			'width'				: 770,
			'height'			: 500,
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
	});
	
	
	
	
	/*  Passwort vergessen popup */
	$("a.pw-vergessen").attr('href',$("a.pw-vergessen").attr('href')+'?plain=1');
	$("a.pw-vergessen").fancybox({
			'width'				: 620,
			'height'			: 330,
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'type'				: 'iframe'
	});
	
	// Team
	if($('#team').size() > 0){
		$('#team a').each(function(){
			$(this).attr('href',$(this).attr('href')+'?plain=1');
			$('#team a').fancybox({
					'width'				: 405,
					'height'			: 480,
					'autoScale'			: false,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none',
					'type'				: 'iframe',
					'titleShow'			: false
			});		
		})	
	}
	
	// Flyout menu
	
	if(jQuery("#navigation").width() > 0){
		jQuery("#navigation li").find('ul').css({'left':'-8px'}).hide();
		jQuery("#navigation li.c5").find('ul').css({'right':'-7px'}).hide();
		jQuery("#navigation li.c5").find('ul').css({'left':'auto'})
		jQuery('#navigation li').css({'overflow':'visible'});
	
		jQuery("#navigation li").hoverIntent(function(){
			if(jQuery(this).find('ul').size()>0){
				jQuery(this).addClass('hover');
				jQuery(this).find('ul').slideDown(500);
			}
		
		},function(){
			jQuery(this).find('ul').slideUp(250,function(){
				jQuery(this).parent().removeClass('hover');
			});
		});
	}
	
	
	// xform_formmediacheckbox
	jQuery('.formmediacheckbox a').fancybox();
	
	
	// Scrollto
	jQuery('#toplink a').click(function(){
		jQuery.scrollTo(0,1000);
				
		jQuery(this).trigger('blur');
	});
	
	
	
		
	
});
