$(document).ready(function(){
	// mouseover for main navi
	$('#nav li a img').hover(function(){
		$(this).attr('src', $(this).attr('src').split('.').join('-active.'));
		$('#' + $(this).parents('li').attr('id') + '_tooltip').show();
	}, function() {
		$(this).attr("src", $(this).attr('src').split('-active.').join('.'));
		$('#' + $(this).parents('li').attr('id') + '_tooltip').hide();
	});
	
	// img management
	$('#bioHover1').hover(function(){
		$('.bioTitle').stop(true,true).addClass('grey');
		$('#bioTitle1').removeClass('grey');
		$('#bio1').slideDown(250);
	}, function(){
		$('.bio').stop(true,true).css('display', 'none');
		$('.bioTitle').stop(true,true).removeClass('grey');
	});
	$('#bioTitle1').hover(function(){
		$('.bioTitle').stop(true,true).addClass('grey');
		$('#bioTitle1').removeClass('grey');
		$('#bio1').slideDown(250);
	}, function(){
		$('.bio').stop(true,true).css('display', 'none');
		$('.bioTitle').removeClass('grey');
	});
	
	$('#bioHover2').hover(function(){
		$('.bioTitle').stop(true,true).addClass('grey');
		$('#bioTitle2').removeClass('grey');
		$('#bio2').slideDown(250);
	}, function(){
		$('.bio').stop(true,true).css('display', 'none');
		$('.bioTitle').stop(true,true).removeClass('grey');
	});
	$('#bioTitle2').hover(function(){
		$('.bioTitle').stop(true,true).addClass('grey');
		$('#bioTitle2').removeClass('grey');
		$('#bio2').slideDown(250);
	}, function(){
		$('.bio').stop(true,true).css('display', 'none');
		$('.bioTitle').removeClass('grey');
	});
	
	$('#bioHover3').mouseenter(function(){
		$('.bioTitle').stop(true,true).addClass('grey');
		$('#bioTitle3').removeClass('grey');
		$('#bio3').slideDown(250);
	}).mouseleave(function(){
		$('.bio').stop(true,true).css('display', 'none');
		$('.bioTitle').stop(true,true).removeClass('grey');
	});
	$('#bioTitle3').mouseenter(function(){
		$('.bioTitle').stop(true,true).addClass('grey');
		$('#bioTitle3').removeClass('grey');
		$('#bio3').slideDown(250);
	}).mouseleave(function(){
		$('.bio').stop(true,true).css('display', 'none');
		$('.bioTitle').removeClass('grey');
	});
	
	$('#bioHover4').mouseenter(function(){
		$('.bioTitle').stop(true,true).addClass('grey');
		$('#bioTitle4').removeClass('grey');
		$('#bio4').slideDown(250);
	}).mouseleave(function(){
		$('.bio').stop(true,true).css('display', 'none');
		$('.bioTitle').stop(true,true).removeClass('grey');
	});
	$('#bioTitle4').mouseenter(function(){
		$('.bioTitle').stop(true,true).addClass('grey');
		$('#bioTitle4').removeClass('grey');
		$('#bio4').slideDown(250);
	}).mouseleave(function(){
		$('.bio').stop(true,true).css('display', 'none');
		$('.bioTitle').removeClass('grey');
	});
	
	$('#imgMgmt').mouseout(function(){
		$('.bio').stop(true,true).css('display', 'none');
		$('.bioTitle').removeClass('grey');
	});
	
	// add css class last
	$("#nav_content li:last-child").addClass('last');
	
	// load lightbox, TODO i18n
//	$('#gallery a').lightBox({
//		overlayOpacity: 0.5,
//		imageLoading: '/img/de/lightbox/loading.gif',
//		imageBlank: '/img/de/lightbox/blank.gif',
//		imageBtnClose: '/img/de/lightbox/btn-close.gif',
//		imageBtnPrev: '/img/de/lightbox/btn-back.gif',
//		imageBtnNext: '/img/de/lightbox/btn-next.gif',
//		txtImage: 'Abbildung',
//		txtOf: 'von',
//		containerResizeSpeed: 300
//	   });
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animation_speed: 'fast', /* fast/slow/normal */
		opacity: 0.50, /* Value between 0 and 1 */
		show_title: false, /* true/false */
		theme: 'light_square'
	});
	
	$('.homepage h2').next('p').hide();
	$('.homepage h2').click(function(){
		if (!$(this).next('p').hasClass('expanded'))
		{
			$(this).next('p').addClass('expanded');
			$(this).next('p').slideDown('fast');
			$('span.more').hide();
		}
		else
		{
			$(this).next('p').removeClass('expanded');
			$(this).next('p').slideUp('fast');
			$('span.more').show();
		}
	});
	
    $('#content-right h2').next('ul').hide();
	$('#content-right h2').next('p').hide();
	
    $('#content-right h2').click(function(){
		if ($(this).next('ul'))
		{
			if (!$(this).next('ul').hasClass('expanded'))
	    		$(this).next('ul').addClass('expanded').slideDown('fast');
			else
				$(this).next('ul').removeClass('expanded').slideUp('fast');
		}
		if ($(this).next('p'))
		{
			if (!$(this).next('p').hasClass('expanded'))
	    		$(this).next('p').addClass('expanded').slideDown('fast');
			else
				$(this).next('p').removeClass('expanded').slideUp('fast');
		}

    });

	$('.news_teaser .news_fulltext').hide();
	$('a.news_show').click(function(){
		$('.news_fulltext').each(function(){
			if ($(this).css('display') == 'block')
			{
				$(this).css('visibility', 'hidden');
				$(this).prev('div').children('a.news_show').css('display', 'block');
			}
		})

		$(this).parent('div').next('.news_fulltext').css('visibility', 'visible').css('display', 'none').slideDown('fast');
		$(this).hide();
		return false;
	});

});
