var thishref = '';

jQuery(function($) {
	
	thishref = $('.activ:last', '#menu').attr('href');
	
	/* Schöner Effekt fürs Hauptmenü */
	$('#menu a').click(function() {
		//$('#menu a.activ').removeClass('activ');
		$(this).parents('li').siblings('li:has(.activ)').find('a').removeClass('activ').end().end().end().addClass('activ');
	});
	
	
	/* Drucken Link im Spielplan */
	if($('.spielplan .print').length == 1) {
		$('.spielplan .print').click(function() {
			window.print();
			return false;
		});
	}
	
	
	$("#wrap").localScroll({
     duration: 500,
     margin: true,
     lazy: true,
     onBefore: function(event, target) {
     		//if(!$(target).is('#submenuheader')) {
     		//	$('h3>.top').remove();
     		//	$(target).append('<a href="'+thishref+'#top" class="top">nach oben</a>');
     		//}
     }
   });
	
	
	/* Transparenzen im Header */
	$('#head h2 a span')
		//Standard
		.css('opacity', 0.8)
		.parent().hover(function() {
			//bei mouseover
			$('span', this).css('opacity', 1);		
		}, function() {
			$('span', this).css('opacity', 0.8);
		});
	
	$('#head .adress').css('opacity', 0.8).hover(function() {
		$(this).css({opacity: 1, background:'#9d0000'});
	}, function() {
		$(this).css({opacity: 0.8, background:'#373737'});
	});
	
	
	/* Mouseover für Schauspieler (Name einblenden) */
	$('#content .sitemap li').each(function() {
		h = -$(this).height();
		$('a.name', this).css({
			opacity: 0.8,
			bottom: h
		}).parent().hover(function() {
			$('a.name', this).stop().animate({bottom: 0}, 500);
		}, function() {
			$('a.name', this).stop().animate({bottom: h}, 500);
		});
		
		if($(':has(img)', this).length == 0) {
			$(this).remove();
		}
	});
	
	
	/* Erster Buchstabe in Zitaten */
	if(!$.browser.msie) {
		$('#content .zitat')
			.filter(':first').addClass('first').end()
			.each(function() {
				content = $.trim($('p:first', this).text());
				$('p:first', this).html('<span class="first">'+content[0]+'</span>'+content.substring(1, content.length));
			});
	}
	
	
	/* Seitenlinks für Stücke */
	if($('body.play').length == 1 && $('#content h3:not(:first)').length > 0) {
		$submenu = $('<div id="top" class="toc"><h3 id="submenuheader">&nbsp;</h3><ul></ul></div>');
		var counter = 0;
		$('#content h3:not(:first)').each(function() {
			if($(this).text()) {
				counter++;
				$(this).attr('id', 'intern-'+counter);
				$submenu.find('ul').append('<li><a href="'+thishref+'#intern-'+counter+'">'+$(this).text()+'</a></li>');
			}
		});
		$('.play .right').after($submenu);
	}
	
	
	/* Seite für die Pressemappen */
	if($('body').is('.pressemappen')) {
		$('.tx-damfrontend-pi1 .downloads').hide();
		$('.treeelem .titlewrap').click(function() {
			href = $(this).closest('tr').find('.control').find('a:eq(1)').attr('href').split('?');
			base = $('base').attr('href');
			url = base+'index.php?id=247&'+href[1]+'&type=2';
			$.nyroModalManual({
				url: url,
				width: 550,
				height: 400,
				title: 'Bitte warten... Downloads werden zusammengestellt.',
				type: 'iframe',
				css: {content: {background: 'white'}}
			});
			return false;
		});
	}
	
	/* Mouseover bei Personenlinks (Thumbnail mit Bild) */
	$('a.person').each(function() {
		link = 'index.php?id='+$(this).attr('rel')+'&type=60';
		$(this).qtip({
		   content: {
		   	 text: 'Lade Bild...',
		     url: link
		   },
		   
		   position: {
	       corner: {
	         target: 'middleRight'
	       }
	   	 },
		   show: 'mouseover',
		   hide: 'mouseout'
		});
	});
	
});
 