// JavaScript Document

$(document).ready(function(){
	
	
	$('#REFERENZEN .ref .val').hide();
	$('#REFERENZEN .ref a').click(function(){
		$('#REFERENZEN .ref .val').slideUp();
		$(this).next().slideDown();
	});
	
	var c=0;
	$('.page').each(function(){
		c++;
		cont = $(this).find('.pageContent')
		d = -1 * (cont.height() + parseInt(cont.css('padding-top')) + parseInt(cont.css('padding-bottom')));
		$(this).css('margin-top', d ).css('z-index', 99-c ).attr('alt',d)
	})
	
	$('.page h2 a').click(function(){
		//noch ma eben die referenezn einklappen
		$('#REFERENZEN .ref .val').slideUp();
		
		$('.page').each(function(){
			$(this).stop().animate({'margin-top':parseInt($(this).attr('alt'))},'slow')
		})
		$(this).parents('.page').stop().animate({'margin-top':-10},'slow',function(){
//			$('html, body').animate({scrollTop:$(this).offset().top})
		})
	})
	
	$('#TeamMap area').hover(function(){
		$('#team_'+$(this).attr('alt')).fadeIn();
	},function(){
		$('#team_'+$(this).attr('alt')).fadeOut();
	})
	
	$('#METANAV a').click(function(){
		$('#OVERLAY').attr('href',$(this).attr('href'))
		if( $('#OVERLAY').is(':visible') ){
			$('#OVERLAY').stop().animate({'margin-top':0,'opacity':0},function(){
				$(this).hide()
				showCard()
			})
		}else{
			showCard()
		}
		return false;
	})
	
	function showCard(){
		url = $('#OVERLAY ').attr('href')
		$('#OVERLAY div').load( url,function(){
			$('#OVERLAY').css({'margin-top':0,'opacity':0}).show().stop().animate({'margin-top':50,'opacity':1});
			$('#OVERLAY a.close').click(function(){
				$('#OVERLAY').animate({'margin-top':0,'opacity':0},function(){$(this).hide()});
				return false;
			})
		});
	}
	
	function hideCard(url){
	}
	
	
	$('.page .next').click(function(){
		$(this).parents('.page').next('.page').find('h2 a').click()
	})
	
	if( window.location.hash ) {
		$('a[href$='+window.location.hash+']').click();
	}else{
		$('.page').first().find('h2 a').click();
	}
})
