function defaults (init) {
	if (init == "Felix") {
		$("#felix").click();
		$("#bgimage").animate({'marginLeft' : '0px'}, 100, function () {	
			$("#navbar").delay(1500).fadeIn(1000);	
		});
	} else if (init == "Aktuell") {
		$("#aktuell").click();
		$("#bgimage").animate({'marginLeft' : '0px'}, 100, function () {	
			$("#navbar").delay(1500).fadeIn(1000);	
		});
	} else if (init == "Kontakt") {
		$("#kontakt").click();
		$("#bgimage").animate({'marginLeft' : '0px'}, 100, function () {	
			$("#navbar").delay(1500).fadeIn(1000);	
		});
	} else if (init == "Gästebuch") {
		$("#gaestebuch").click();
		$("#bgimage").animate({'marginLeft' : '0px'}, 100, function () {	
			$("#navbar").delay(1500).fadeIn(1000);	
		});
	} else if (init == "Impressum") {
		$("#impressum").click();
		$("#bgimage").animate({'marginLeft' : '0px'}, 100, function () {	
			$("#navbar").delay(1500).fadeIn(1000);	
		});
	} else if (init == "subnav_back") {
		$("#content > .variable").fadeOut(1000);
		$("#felix_subnavigation > .subnav").fadeOut(1000);
		$("#bgimage > .fade").fadeOut(1000, function () {
			$("#bgimage > .fade img").attr('src', 'assets/content/fotos' + '/' + 'hauptseite.jpg');
			$("#bgimage > .fade").css('opacity', '1');
				$("#bgimage > .fade").fadeIn(1000);
		});
		$.doTimeout(1500,function(){
			$("#content_main").fadeIn(1000);
		});
	} else {
		$("#bgimage > .fade").animate({'opacity' : 1});
		$("#bgimage > .fade").fadeIn(1000);
		$("#bgimage").delay(1500).animate({'marginLeft' : '0px'}, 2000, function () {
				$("#content_main").fadeIn(1000, function() {
					$("#navbar").fadeIn(1000);	
				});
			});
	}
}

/*
 * fancybox dynamic title and extra event html call
 */
function formatTitle(title, currentArray, currentIndex, currentOpts) {
	return '<span id="fancybox-title-over">Bild ' + (currentIndex + 1) + ' / ' + currentArray.length + (title==undefined ? '' : ' &nbsp; ' + title) + '</span>';
}

$(document).ready(function(){
	
	/*
	 * Link actions
	 */
	$("#felix").click(function () {
		$("#content > .variable").fadeOut(1000);
		$("#felix_subnavigation > .subnav").fadeOut(1000);
		$("#bgimage > .fade").fadeOut(1000, function () {						
			$("#bgimage > .fade img").attr('src', 'assets/content/fotos' + '/' + 'felix.jpg');
			$("#bgimage > .fade").css('opacity', '1');
			$("#bgimage > .fade").fadeIn(1000);
		});
		
		$.doTimeout(1500,function(){
			$("#felix_subnavigation").show();
			if ($("#felix_subnavigation > .subnav").css('fontSize') == '24px') {
				$("#felix_subnavigation").css({'fontSize' : '27px', 'position' : 'absolute', 'left' : '520px', 'top' : '220px', 'width' : '200px', 'height' : '150px'});
				$("#felix_subnavigation > .subnav").css({'width' : '130px', 'height' : '30px'});
				$("#subnav_film_ab").css({'left' : '69px'});
				$("#subnav_buehne_frei").css({'left' : '0px'});
				$("#subnav_galerie").css({'left' : '24px'});
				$("#subnav_vita").css({'left' : '32px'});
				$("#subnav_back").css({'left' : '32px'});
			} else { 
				$("#felix_subnavigation > .subnav_left").show("drop", { direction: "left" }, 800);
				$("#felix_subnavigation > .subnav_right").show("drop", { direction: "right" }, 800);
			}
			$("#felix_subnavigation > .subnav").fadeIn(1000);
		});
	});
	
	$("#aktuell").click(function () {
		$("#content > .variable").fadeOut(1000);
		if ($("#bgimage > .fade img").attr('src') != 'assets/content/fotos/hauptseite.jpg') {
			$("#bgimage > .fade").fadeOut(1000, function () {
				$("#bgimage > .fade img").attr('src', 'assets/content/fotos' + '/' + 'hauptseite.jpg');
				$("#bgimage > .fade").css('opacity', '0.33');
				$("#bgimage > .fade").fadeIn(1000);
			});
		} else {
			$("#bgimage > .fade").fadeTo(1000, 0.33);
		}
		$.doTimeout(1500,function(){ 
			$("#content_events").fadeIn(1000);
			$("a.thumb img, img.thumb").thumbsImg();
		});
		$(".event").click(function() {
			$.fancybox({
				'href'	: 	'#' + $(this).attr('id') + '_extraContainer'
			});
		});
	});
	
	$("#kontakt").click(function () {
		$("#content > .variable").fadeOut(1000);
		if ($("#bgimage > .fade img").attr('src') != 'assets/content/fotos/hauptseite.jpg') {
			$("#bgimage > .fade").fadeOut(1000, function () {
				$("#bgimage > .fade img").attr('src', 'assets/content/fotos' + '/' + 'hauptseite.jpg');
				$("#bgimage > .fade").css('opacity', '0.33');
				$("#bgimage > .fade").fadeIn(1000);
			});
		} else {
			$("#bgimage > .fade").fadeTo(1000, 0.33);
		}
		$.doTimeout(1500,function(){ 
			$("#content_kontakt > .inner").load("form.php");
			$("#content_kontakt").fadeIn(1000);
		});
	});
	
	$("#gaestebuch").click(function () { 
		$("#content > .variable").fadeOut(1000);
		if ($("#bgimage > .fade img").attr('src') != 'assets/content/fotos/hauptseite.jpg') {
			$("#bgimage > .fade").fadeOut(1000, function () {
				$("#bgimage > .fade img").attr('src', 'assets/content/fotos' + '/' + 'hauptseite.jpg');
				$("#bgimage > .fade").css('opacity', '0.33');
				$("#bgimage > .fade").fadeIn(1000);
			});
		} else {
			$("#bgimage > .fade").fadeTo(1000, 0.33);
		}
		$("#image_buehne").fadeTo(1000, 0.33);
		$.doTimeout(1500,function(){ 
			$("#content_gaestebuch > .inner").load("guestbook.php");
			$("#content_gaestebuch").fadeIn(1000);
		});
	});
	
	$("#impressum").click(function () {
		$("#content > .variable").fadeOut(1000);
		if ($("#bgimage > .fade img").attr('src') != 'assets/content/fotos/hauptseite.jpg') {
			$("#bgimage > .fade").fadeOut(1000, function () {
				$("#bgimage > .fade img").attr('src', 'assets/content/fotos' + '/' + 'hauptseite.jpg');
				$("#bgimage > .fade").css('opacity', '0.33');
				$("#bgimage > .fade").fadeIn(1000);
			});
		} else {
			$("#bgimage > .fade").fadeTo(1000, 0.33);
		}
		$.doTimeout(1500,function(){ 
			$("#content_impressum").fadeIn(1000);
		});
	});
	
	/*
	 * Subnavigation
	 */
	$("#felix_subnavigation > .subnav").click(function () {
		$("#felix_subnavigation").show();
		if ($(this).css('fontSize') != '24px') {
			$(this).hide("puff", {  }, 1000);
			$("#felix_subnavigation > .subnav_left").hide("drop", { direction: "left" }, 800);
			$("#felix_subnavigation > .subnav_right").hide("drop", { direction: "right" }, 800);
			$.doTimeout(1500,function(){
				$("#felix_subnavigation").css({'fontSize' : '24px', 'position' : 'absolute', 'left' : '630px', 'top' : '363px', 'width' : '170px', 'height' : '88px'});
				$("#felix_subnavigation > .subnav").css({'width' : '110px', 'height' : '22px'});
				$("#subnav_film_ab").css({'left' : '60px'});
				$("#subnav_buehne_frei").css({'left' : '0px'});
				$("#subnav_galerie").css({'left' : '24px'});
				$("#subnav_vita").css({'left' : '30px'});
				$("#subnav_back").css({'left' : '32px'});
				$("#felix_subnavigation > .subnav_left").show("drop", { direction: "left" }, 200);
				$("#felix_subnavigation > .subnav_right").show("drop", { direction: "right" }, 200);
			});
		} else {
			$(this).effect("pulsate", { times:1 }, 400);
		}
	});
	
	$("#subnav_film_ab").click(function () {
		$("#content > .subvariable").fadeOut(1000);
		$("#content > .subvariable object").hide();
		$("#bgimage > .fade").fadeOut(1000, function () {
			$("#bgimage > .fade img").attr('src', 'assets/content/fotos' + '/' + 'film_ab.jpg');
			$("#bgimage > .fade").fadeIn(1000);
		});
		$.doTimeout(1500,function(){ 
			$("#content_film_film").fadeIn(1000);
			$("#content_film_film object").show();
		});
	});
	
	$("#subnav_buehne_frei").click(function () {
		$("#content > .subvariable").fadeOut(1000);
		$("#content > .subvariable object").hide();
		$("#bgimage > .fade").fadeOut(1000, function () {
			$("#bgimage > .fade img").attr('src', 'assets/content/fotos' + '/' + 'buehne_frei.jpg');
			$("#bgimage > .fade").fadeIn(1000);
		});
		$.doTimeout(1500,function(){ 
			$("#content_film_buehne").fadeIn(1000);
			$("#content_film_buehne object").show();
		});
	});
	
	$("#subnav_galerie").click(function () {
		$("#content > .subvariable").fadeOut(1000);
		$("#bgimage > .fade").fadeOut(1000, function () {
			$("#bgimage > .fade img").attr('src', 'assets/content/fotos' + '/' + 'hauptseite.jpg');
			$("#bgimage > .fade").fadeIn(1000);
		});
		$.doTimeout(1500,function(){ 
			$("#content_galerie").fadeIn(1000);
		});
	    $('.galerie a[rel=galerie_img]').fancybox({
			'transitionIn'	:	'elastic',
			'transitionOut'	:	'elastic',
			'speedIn'		:	600, 
			'speedOut'		:	200, 
			'overlayShow'	:	true,
			'titlePosition' : 'over',
			'titleFormat'	: formatTitle
	    });
	});
	
	$("#subnav_vita").click(function () {
		$("#content > .subvariable").fadeOut(1000);
		$("#content > .subvariable object").hide();
		$("#bgimage > .fade").fadeOut(1000, function () {
			$("#content > .subvariable").fadeOut(1000);
			$("#bgimage > .fade img").attr('src', 'assets/content/fotos' + '/' + 'vita.jpg');
			$("#bgimage > .fade").fadeIn(1000);
		});
		$.doTimeout(1500,function(){ 
			$("#content_vita").fadeIn(1000);
			$("#content_vita object").show();
		});
	});
	
	$("#subnav_back").click(function () {
		$("#content > .variable").fadeOut(1000);
		defaults("subnav_back");
	});
				
	/*
	 * Add hover effects over specific images
	 */
	$('img.over').each(function(){
	    var t=$(this);
	    var src1= t.attr('src'); // initial src
	    var newSrc = src1.substring(src1.lastIndexOf('/'), src1.lastIndexOf('.')); // let's get file name without extension
	    t.hover(function(){
	        $(this).attr('src', 'img' + newSrc+ '_active.' + /[^.]+$/.exec(src1)); //last part is for extension       
	    }, function(){
	        $(this).attr('src', 'img' + newSrc + '.' + /[^.]+$/.exec(src1)); //removing '_active' from the name
	    });
	});
	
	/*
	 * Add hover effects to subnav
	 */
	$(".subnav").each(function(){
		$(this).hover(
			function(){
				$(".cross",this).css({'color' : '#d3b5b5'});
				$(".fex",this).css({'color' : '#993300'});
			},
			function(){
				$(".cross",this).css({'color' : '#993300'});
				$(".fex",this).css({'color' : '#d3b5b5'});
			}
		);
	});

	defaults(init);

});

/*
 * Preload images from css files
 */
$(window).bind('load', function() {
	$.preloadCssImages();
});
