$(document).ready(function()
{
	// cycle home
	$('.pics').cycle({ 
	    fx:    'fade', 
	    speed:  800,
	    timeout: 6000
	 });
	
	// maphilight karte
	$(function()
	{
		$.fn.maphilight.defaults = {
				fill: true,
				fillColor: 'd0362c',
				fillOpacity: 0.666,
				stroke: false,
				strokeColor: 'ff0000',
				strokeOpacity: 1,
				strokeWidth: 1,
				fade: true,
				alwaysOn: false
			}
		
		$('.map').maphilight();
	});
	
	// maphilight liste
	$('ul.csc-menu li').each(function(i)
	{
		$(this).mouseenter(function() {
			  var name = $(this).text().toLowerCase().replace(/ /g,'-').replace(/--/g, '-').replace(/ü/g, 'ue'); // do some (yes, ugly!) magic ;)
			  var area = $('area[href$='+name+'/]');

			  area.simulate('mouseover');
		});
		
		$(this).mouseleave(function() {
			  var name = $(this).text().toLowerCase().replace(/ /g,'-').replace(/--/g, '-').replace(/ü/g, 'ue'); // do some (yes, ugly!) magic ;)
			  var area = $('area[href$='+name+'/]');

			  area.simulate('mouseout');
		});		
	});

	// links auf pdf-dokumente auszeichnen
	$('a[href$=.pdf]').addClass('link-pdf');
	
	// pdf-dokumente in neuem fenster öffnen
	$('a[href$=.pdf]').each(function(){
		$(this).attr('target', '_blank');
	});
	
	// http:// bei referenzen abschneiden
	$('.tx-narkose-pi1 .subcolumns a').each(function()
	{
		var text = $(this).text().substring(7);
		$(this).text(text);
	});
	
	// formular patientvideos
	if ($('input[name=user]'))
	{
		$('input[name=user]').attr('value', 'video');
	}
	
	// suchresultate: slash entfernen bei title
	$('.tx-indexedsearch-title a').each(function(){
	    var title = $(this).text().substring(1);
	    $(this).text(title);
	});
	
	// suchresultate: hr einbinden
	$('.tx-indexedsearch').before('<hr class="hr_search" />');
	// $('.tx-indexedsearch-browsebox').after('<hr class="hr_divider" />');
	$('.tx-indexedsearch-res .wrapper').after('<hr class="hr_divider" />');

	// news auf- und zuklappen
	$('.news-list-container .wrapper').each(function(i)
	{
		if ($(this).children().length > 1)
		{
			if (window.location.pathname.substring(1,3) == 'it')
			{
				$(this).append('<p class="tt_news_more"><a href="javascript:;"><img alt="plus" src="fileadmin/templates/images/plus.gif"> mostra tutto</a></p>'); // füge neues a element in den DOM
			}
			else if (window.location.pathname.substring(1,3) == 'fr')
			{
				$(this).append('<p class="tt_news_more"><a href="javascript:;"><img alt="plus" src="fileadmin/templates/images/plus.gif"> afficher les détails</a></p>'); // füge neues a element in den DOM
			}
			else if (window.location.pathname.substring(1,3) == 'en')
			{
				$(this).append('<p class="tt_news_more"><a href="javascript:;"><img alt="plus" src="fileadmin/templates/images/plus.gif"> read more</a></p>'); // füge neues a element in den DOM
			}
			else
			{
				$(this).append('<p class="tt_news_more"><a href="javascript:;"><img alt="plus" src="fileadmin/templates/images/plus.gif"> mehr</a></p>'); // füge neues a element in den DOM

			}
			$(this).children(":first").addClass('show'); // datum soll sichtbar bleiben
			$(this).children(":first").next().addClass('show'); // <h2> soll sichtbar bleiben
			$(this).children(":first").next().next().remove(); // leeres <p> tag entfernen
			$(this).children(":first").next().next().addClass('show'); // der erste absatz wird weiter angezeigt
			$(this).children('.tt_news_more').addClass('show'); // ebenso der link zum aufklappen
			$(this).children().not(".show").hide(); // alle anderen werden versteckt. 
		}
	});


	if (window.location.pathname.substring(1,3) == 'it')
	{
		$('.news-list-container .wrapper .tt_news_more a').click(function() {
			if ($(this).parent().is('.show')) {
				$(this).parent().siblings().show('fast');
				$(this).html('<img alt="minus" src="fileadmin/templates/images/minus.gif"> nascondi</a>');
			} else {
				$(this).parent().siblings().not('.show').hide('fast');
				$(this).html('<img alt="plus" src="fileadmin/templates/images/plus.gif"> mostra tutto</a>');
			}
			$(this).parent().toggleClass('show');
		});
	}
	else if (window.location.pathname.substring(1,3) == 'fr')
	{
		$('.news-list-container .wrapper .tt_news_more a').click(function() {
			if ($(this).parent().is('.show')) {
				$(this).parent().siblings().show('fast');
				$(this).html('<img alt="minus" src="fileadmin/templates/images/minus.gif"> masquer les détails</a>');
			} else {
				$(this).parent().siblings().not('.show').hide('fast');
				$(this).html('<img alt="plus" src="fileadmin/templates/images/plus.gif"> afficher les détails</a>');
			}
			$(this).parent().toggleClass('show');
		});		
	}
	else if (window.location.pathname.substring(1,3) == 'en')
	{
		$('.news-list-container .wrapper .tt_news_more a').click(function() {
			if ($(this).parent().is('.show')) {
				$(this).parent().siblings().show('fast');
				$(this).html('<img alt="minus" src="fileadmin/templates/images/minus.gif"> hide</a>');
			} else {
				$(this).parent().siblings().not('.show').hide('fast');
				$(this).html('<img alt="plus" src="fileadmin/templates/images/plus.gif"> more</a>');
			}
			$(this).parent().toggleClass('show');
		});		
	}
	else
	{
		$('.news-list-container .wrapper .tt_news_more a').click(function() {
			if ($(this).parent().is('.show')) {
				$(this).parent().siblings().show('fast');
				$(this).html('<img alt="minus" src="fileadmin/templates/images/minus.gif"> weniger</a>');
			} else {
				$(this).parent().siblings().not('.show').hide('fast');
				$(this).html('<img alt="plus" src="fileadmin/templates/images/plus.gif"> mehr</a>');
			}
			$(this).parent().toggleClass('show');
		});	
	}

	$('div.c33r div.subcr ul li').each(function(i)
	{
		$(this).click(function() {
			var group = $(this).attr("class");
			if(group == 'fachgebiete') {
				$(this).showAll();
			} else {
				$(this).hideAll(group);
			}
		});

	});

	$('.tx-ttaddress-pi1 span').each(function() {
		var link = $(this).html();
		if(link) {
			$(this).html('<a href="'+link+'" target="_blank">'+link+'</a>');
		}
	});



});

$.fn.hideAll = function(v) {
	$('div.tx-ttaddress-pi1 ul#list li').each(function(i) {
		$(this).hide('slow');
		$('div.c33r div.subcr ul li').removeClass("highlightfa");
	});
	$('div.c33r div.subcr ul li.'+v).addClass("highlightfa");
	$('div.tx-ttaddress-pi1 ul#list li.'+v).show('slow');
}
$.fn.showAll = function() {
	$('div.tx-ttaddress-pi1 ul#list li').each(function(i) {
		$(this).show('slow');
		$('div.c33r div.subcr ul li').removeClass("highlightfa");
		$('div.c33r div.subcr ul li.fachgebiete').addClass("highlightfa");
	});
}
