$(document).ready(function() {

		var hash = window.location.href;

		var href = $('#menu ul li a').each(function() {
			var href = $(this).attr('href');
			if(hash == href) {
        		var toLoad = hash+' #content > *';
        		$('#content').load(toLoad);
        	}
        });
	
		var clickedMenuItem;
		var currentMenuItem;
		
        $('#menu ul li a').click(function(e) {

       		var toLoad = $(this).attr('href')+' #content > *';

        	clickedMenuItem = $(this);
        	currentMenuItem = $(this);

        	$('#menu ul li a').each(function() {
        		if($(this).hasClass('active')){
        			currentMenuItem = $(this);
        			return false;
        		}
        		return true;
        	});

            e.preventDefault();
            
        	$('#content').fadeOut('slow',function(){
        		$('#load').css("display", "block");

        		$('#content').load(toLoad, function(){
        			$('#content').fadeIn('slow');
        			$('#load').css("display", "none");
        			
        			if( clickedMenuItem.attr('id') == "fotos" || clickedMenuItem.attr('id') == "aktuelles")
    				{
        				$.getScript("js/getFotos.js");
    				}
        			else if( clickedMenuItem.attr('id') == "kontakt")
    				{
        				$.getScript("js/getKontakt.js");
    				}
        			else if(clickedMenuItem.attr('id') == "gaestebuch")
    				{
        				$.getScript("js/getKontakt.js");
        				$.getScript("js/getGaestebuch.js");
    				}
        		});
			});

 
        	currentMenuItem.removeClass('active');
        	clickedMenuItem.stop().animate({
				paddingTop: '12px',
				color: '#868686'
				}, 150, function () {
					clickedMenuItem.addClass('active');
					clickedMenuItem.stop().stop().css({
						paddingTop: '12px',
						color: '#868686'
					});
				});
        	
        	
        	if(currentMenuItem.attr('href') != clickedMenuItem.attr('href'))
        	{
        		currentMenuItem.animate({
					paddingTop : '16px',
					color: '#b6b6b6'
        		}, 250);
        	}
        });

	$(function () {
		$("#menu ul > li a").hover(
		function () {
				$(this).stop().animate({
				paddingTop: '8px',
				color: '#868686'
				}, 150).animate({
						paddingTop: '12px'
				}, 100);
		},

		function () {
			if( !$(this).hasClass('active') )
			{
				$(this).animate({
					paddingTop : '18px',
					color: '#b6b6b6'
				}, 150).animate({
					paddingTop: '16px'
				}, 50);
			}
		});
	});

});
