$(document).ready(function(){
	$('body').append('<div class="reiter"><div>&nbsp;</div></div>');
	

	var h1 = $('.wrapper1').height();
	var h2 = $('body').height();
	
	//$('.wrapper3').height(Math.max(h1,h2));
	if ($.browser.msie&&$.browser.version<7) {
		$('.logo a').ifixpng().css('cursor','pointer');
		$('.logo a, #nav a').click(function(){
			window.location = $(this).attr('href');
		});
		$('.header, .reiter, .logo2, .bg_themen img').ifixpng();
	} else {
		
	}
	
	$('.copy a').each(function(){
		if ($(this).attr('href').indexOf('endspiel2010.de')<0&&$(this).attr('href').indexOf('http://')==0) {
  			$(this).attr('target','_blank');
  		}
  		
 	});
	
	var tw = 0;
	var c = 0;
	$('.subnav2 a').each(function(){
		tw += $(this).width();
		c++;
	});
	
	var w = Math.floor(($('.subnav2').width()-tw)/c)-1;
	$('.subnav2 a').each(function(){
		var w0 = $(this).width();
		$(this).width(w0+w);
	});
	
	$('.subnav2').css('visibility','visible');
	
	$('.dokumentation .copy a, .dokumentation .events-item a, .dokumentation .events-item').attr('target','_blank');

	//$('.preview_box_body').corner("7px");
	$('.events-item').click(function(){
		//alert($(this).find('a').attr('href'));
		if (!$(this).parents('body').hasClass('dokumentation')) {
			window.location = $(this).find('a').attr('href');
		}
	});
	
	$('.documentation-item').click(function(){
		//alert($(this).find('a').attr('href'));
		//window.location = $(this).find('a').attr('href');
	});
	
	$('.docs-event-header').click(function(){
		//alert($(this).find('a').attr('href'));
		$(this).toggleClass('documentation-item-active');
		$(this).parents('.docs-event').find('.docs-event-body').slideToggle('normal');
	});
	
	$('.events-item').hover(function(){ 
		if (!$(this).parents('body').hasClass('dokumentation')) $(this).addClass('events-item-hovered')},
		function(){ $(this).removeClass('events-item-hovered')});
	$('.docs-event-header').hover(function(){$(this).addClass('documentation-item-hovered')},function(){$(this).removeClass('documentation-item-hovered')});
	//$('.documentation-item').hover(function(){$(this).addClass('documentation-item-hovered')},function(){$(this).removeClass('documentation-item-hovered')});
	
	$('.gaestebuch .write').click(function(){
		$('#entryForm').slideToggle();
	});
	
	$('#month_nav a').click(function(){
		var m = $(this).parents('li').attr('id').replace(/month/,'');
		$(this).parents('ul').find('li').removeClass('selected');
		$(this).parents('li').addClass('selected');
		$('.events .events-item, .events .docs-event').hide();
		$('.docs-event .events-item').show();
		$('.events .events-item, .events .docs-event').each(function(){
			if ($(this).hasClass('month'+m)) {
				$(this).show();
			}
		});
		$('h1 span.cur_month, h2 span.cur_month').text($(this).text());
	});
	
	$('#location_nav a').click(function(){
		var m = $(this).parents('li').attr('id').replace(/location/,'');
		$(this).parents('#location_nav').find('li').removeClass('selected');
		$(this).parents('li').addClass('selected');
		$('.events .events-item').hide();
		$('.events .events-item').each(function(){
			if ($(this).hasClass('location'+m)) {
				$(this).show();
			}
		});
		$('h2').text($(this).text());
	});
		
	if ($('body.home').length>0) {
  	var images = ['endspiel','schauspiel','denkspiel','musikspiel','kunstspiel'];
  	var captions = ['','','','',''];
  	gal_int = window.setInterval('changeImg()',7000);
  	window.cur_img = 0;
  	changeImg = function() {
  		$('#front_img').attr('id','back_img_tmp');
  		$('#back_img').attr('id','front_img');
  		$('#back_img_tmp').attr('id','back_img');
  		$('#front_img').hide();
  		//$('#front_img').html('<img src="assets/bilder/intro/'+images[window.cur_img]+'.jpg" /><div class="caption"><div class="caption_hg">&nbsp;</div><img src="assets/typo/'+images[window.cur_img]+'.gif" /></div>');
  		$('#front_img').html('<img src="_assets/img/home/'+images[window.cur_img]+'.jpg" title="'+captions[window.cur_img]+'" />');
  		$('#front_img>img').load(function(){
  			//$('#back_img .caption').hide();
  			//$(this).parent().css('left','1000px');
  			//$(this).parent().animate({left:0},2000);
  			$(this).parent().fadeIn(2000);
  			/*
  			var w = $(this).parent().find('.caption img').width();
  			$(this).parent().find('.caption').css('opacity',0);
  			$(this).parent().find('.caption_hg').width(w+10);
  			$(this).parent().find('.caption_hg').css('opacity',0.7);
  			var caption_t = setTimeout('showCaption()',2000); */
  		});
  		window.cur_img++;
  		if (window.cur_img>=images.length) { 
  			window.cur_img = 0;
  		}
  	}
  	showCaption = function() {
  		//$('#front_img .caption').animate({opacity:1},2000);
  	}
  	hideCaption = function() {
  		//$('#front_img .caption').hide();
  	}
  	changeImg();
  } 	
  
  
  
	
	/*
	$('.events-item-header').each(function() {
		$(this).click(function(){
			var id = $(this).parent().attr('id').replace(/item-/,'');
			if ($(this).parent().find('#detail-loaded-'+id).length>0) {
				$(this).parents('.events-item').find('.link-icon').show();
				$(this).parent().find('.close-button').remove();
				$(this).parent().removeClass('events-item-active');
				$('#detail-loaded-'+id).slideUp('slow',function(){
					$(this).remove();
				});
			} else {
				$(this).parents('.events-item').find('.link-icon').hide();
				$(this).parent().addClass('events-item-active');
				$(this).parent().append('<div id="detail-loaded-'+id+'" class="detail-loaded"></div>');
				$(this).parent().addClass('detail-preloading');
			//$('#detail-loaded-'+id).hide();
				$('#detail-loaded-'+id).load('/detail.php?id='+id, null, function() {
					$(this).parent().removeClass('detail-preloading');
					$(this).parent().append('<a class="close-button" title="schließen">&nbsp;</a>');
					$(this).find('.copy_long p:first>strong').addClass('organizer');
					$(this).parents('.events-item').find('a.close-button').click(function(){
						$(this).parents('.events-item').find('.link-icon').show();
						$(this).parent().removeClass('events-item-active');
						$('#detail-loaded-'+id).slideUp('slow',function(){
							$(this).remove();
						});
						$(this).parent().find('.close-button').remove();
					});
					
					$(this).slideDown('slow');
				});
			}
			
		});
		//$(this).colorbox({href:'detail.php?id='+$(this).attr('id').replace(/item-/,''),opacity:0.85,height:'500px',width:'760px'});
	});
	*/
});
