$(document).ready(function() {
  var uri = window.location.pathname.substring(1).replace(/.html/,'').replace(/_neu/,'').toLowerCase().split('/');
  //alert (uri);
  if (uri=='') uri[0] = 'startseite';
  $('body').addClass(uri[0]);
  $('.nav #'+uri[0]).addClass('selected').css('visibility','hidden');
  var o = $('.nav .selected').offset();
  $('.wrapper_3').prepend('<div  id="nav_selected"><ul class="nav"></ul></div>');
  $('.nav .selected').clone().appendTo('#nav_selected ul').css('visibility','visible');
  $('#nav_selected .selected').css('top',o.top-100);
  $('.thumbnails a img').parent().click(function() {
    if ($.browser.msie === true && $.browser.version < 7) {
		window.scrollTo(0,0);
	}
	GB_open($(this).attr('href'),$(this).attr('title'));
	return false;
  });
  if ($('body.startseite').length>0) {
	$('.content-header').flash({ src: '/assets/flash/intro.swf', width: 616, height: 230, wmode: 'transparent' }); 
  }
  if ($('body.literaturmuseum').length>0) {
  	$('.copy hr').remove();
  	var c = 0;
  	$('.copy .author').each(function(){
  		if (c%2==0) { 
  			cur_row = (c/2)+1;
  			$(this).before('<div class="author-buttons" id="author-buttons-'+cur_row+'"></div>');
  		}
  		$('#author-buttons-'+(cur_row)).append('<div class="author-button" id="author-button-'+(c+1)+'">&nbsp;</div>');
  		$(this).attr('id','author-copy-'+(c+1));
  		$(this).hide();
  		c++;
  	});
  	$('.author-button').click(function(){
  		$('.author').hide();
  		$('.flashplayer').remove();
  		var id = $(this).attr('id').replace(/author-button-/,'');
  		if (!$(this).hasClass('selected')) { 
  			$('#author-copy-'+id).show();
  			$('#author-copy-'+id).find('p:last').before('<div class="flashplayer"></div>');
			$('#author-copy-'+id).find('.flashplayer').flash(
				{ 
			  		src: 'assets/flash/streaming_player.swf',
			  		width: 280,
			  		height: 30,
			  		wmode: 'transparent',
			  		flashvars: { fileName: 'author-'+id+'.mp3' },
			  		allowScriptAccess: 'always'
				},
				{ version: 6 }
    		);
  			$('.author-button').removeClass('selected');
  			$(this).addClass('selected');
  		} else {
  			$(this).removeClass('selected');
  		}
  		window.scrollTo(1000,1000);
  	});
  }
  if ($('body.literaturveranstaltungen').length>0) {
  	$('h2').each(function(){
  		if ($(this).text()=='Aktuelle Veranstaltungen') {
  			//var s = $(this).next().html();
  			//$(this).next().remove();
  			//s = s.split('<br>&nbsp;');
  			tmp = [];
  			$('.newsboxinhalt').each(function(){
  				t = $(this).html();
  				/*t = t.replace(/<br>/g,'');
  				t = t.replace(/<BR>/g,'');
  				t = t.replace(/<br\/>/g,'');
  				t = t.replace(/<BR\/>/g,'');*/
  				t = t.replace(/&nbsp;/g,'');
  				t = t.substring(0,t.length-4);
  				t = t.replace(/<a/,'<br /><a');
  				t = t.replace(/<A/,'<br /><a');
  				tmp.push(t);
  			});
  			$('.events').remove();
  			/*
  			for (i=0;i<s.length-1;i++) {
  				t = s[i];	
  			} */
  			$(this).after('<p class="event">'+tmp.join('</p><p class="event">')+'</p>');
  			$('p.event a').each(function(){
  				if ($(this).text()!='mehr...') {
  					$(this).replaceWith('<strong>'+$(this).text()+'</strong>');
  				} else {
  					var a = $(this).attr('href');
  					//$('body #ajaxloader').remove();
  					$(this).parents('p').after('<div class="ajaxloader"></div>');
  					$(this).parents('p').next('.ajaxloader').load(a+' .content table p',null,function(){
  						//alert($(this).find('.ajaxloader').html());
  						//$(this).find('.ajaxloader').remove();	
  					});
  					$(this).remove();
  					//$(this).before('|&nbsp;');
  				}
  			});
  			$('p.event').each(function(){
  				var c = 0;
  				$(this).find('br:not(:last)').each(function(){
  					if (c>1) {
  						$(this).replaceWith('&nbsp;|&nbsp;');
  					}
  					c++;
  				});
  				t = $(this).html();
  				t = t.replace(/<br><\/p>/,'</p>');
  				$(this).html(t);
  			});
  		}
  	});
  }
});
