function hideAll()
{
	$("#home-content").hide();
	$("#archiv-content").hide();
	$("#event-content").hide();
	$("#jesus-content").hide();
	$("#wir-content").hide();
	$("#galerie-content").hide();	
	$("#impressum-content").hide();	
}

function showPage( id )
{
	hideAll();
	$("#"+id+"-content").show();
}

function exists_id( id )
{
	if( id == 'home' ||
		id == 'archiv' ||
		id == 'event' ||
		id == 'jesus' ||
		id == 'wir' ||
		id == 'galerie' ||
		id == 'impressum' )
		return true;
	else
		return false;
}


function on_startup()
{
	// Parameter page auslesen und ggf. die entsprechende Seite anzeigen
	var page= '';
	var url = window.location.search;
	if( url )
	{
		var params = url.split('?')[1].split('&');
		for( i = 0; i < params.length; ++i )
		{
			var param = params[i].split('=');
			if( param[0] == 'page' )
				page = param[1];
		}
	}
	
	if( page && exists_id( page ) )
	{
		showPage( page );
		if( page == "home")
			$("#navigation").hide();
		else
			$("#navigation").show();
	}
	else
	{
		page = 'home';
		showPage( 'home' );
		$("#navigation").hide();
	}
}

$(document).ready(function(){

	hideAll();
	on_startup();
	
	var stdBgColor = $(".nav-green").css("background-color");
	var hoverBgColor = "#327d00";
	var hoverTextColor = "#fff";
	var stdTextColor = $(".nav-green").children(".nav-big").css("color");
	var fadeSpeed = 500;
	
	 $('.galery a').lightBox();

	
	$('.nav-green').hover( function() {
		// Set a pointer-cursor
		$(this).css("cursor", "pointer");
	
		// change the background-color
		$(".nav-green").stop().animate({"background-color": hoverBgColor }, 350);
		
		// change the link-text color
		$(this).children(".nav-big").children("a").animate({"color": hoverTextColor }, 350);
		
		// The current element is not supposed to change its background-color
		$(this).css("background-color", stdBgColor ).stop();
 	},
	function() {
		// change the background-color
		$(".nav-green").stop().animate({"background-color": stdBgColor }, 350);
		$(this).css("background-color", stdBgColor ).stop();
		
		// change the link-text color
		$(this).children(".nav-big").children("a").animate({"color": stdTextColor}, 350);
	});
	
	$('.nav-green').click( function() {
		var id = $(this).children(".nav-big").children("a").attr("id");
		if( id == "home" )
			$("#navigation").fadeOut(fadeSpeed);
		else
			$("#navigation").fadeIn(fadeSpeed);
		$("#content").fadeOut(fadeSpeed, function() {
			showPage( id );
			$("#content").fadeIn(fadeSpeed);
		});
		return false;
	});
	
	$('.navbar').children('a').click( function() {
		var id = $(this).attr("id");
		if( id == "home" )
			$("#navigation").fadeOut(fadeSpeed);
		else
			$("#navigation").fadeIn(fadeSpeed);
		$("#content").fadeOut(fadeSpeed, function() {
			showPage( id );
			$("#content").fadeIn(fadeSpeed);
		});
		return false;
	});
	
	$('.impressum').children('a').click( function() {
		var id = "impressum";
		$("#navigation").fadeIn(fadeSpeed);

		$("#content").fadeOut(fadeSpeed, function() {
			showPage( id );
			$("#content").fadeIn(fadeSpeed);
		});
		return false;
	});
	
	$('.galery-link').click( function() {
		var id = "galerie";
		$("#navigation").fadeIn(fadeSpeed);

		$("#content").fadeOut(fadeSpeed, function() {
			showPage( id );
			$("#content").fadeIn(fadeSpeed);
		});
		return false;
	});
	
	$('.gal-pic').hover( function() {
		$(this).attr( "rel", $(this).attr("src") );
		var pic = $(this).attr("src").replace(/(sw)/, "");
		$(this).attr("src", pic);
	}, function() {
		$(this).attr("src", $(this).attr( "rel" ));
	});

	$('.gal-pic').click( function() {
		var id = "galerie";
		$("#navigation").fadeIn(fadeSpeed);

		$("#content").fadeOut(fadeSpeed, function() {
			showPage( id );
			$("#content").fadeIn(fadeSpeed);
		});
		return false;
	});
})
