var curHeader = 'header-blank';

$(document).ready(function () {
	$('#nav-film').mouseover(function() {
		$(this).attr('src','img/film-o.png');
		if(curHeader != 'header-film') {
			$('#'+curHeader).fadeOut('slow');
			curHeader = 'header-film';
			$('#header-film').fadeIn('slow');
		}
	});
	$('#nav-film').mouseleave(function() {
		$(this).attr('src','img/film.png');
	});
	$('#nav-web').mouseover(function() {
		$(this).attr('src','img/web-o.png');
		if(curHeader != 'header-web') {
			$('#'+curHeader).fadeOut('slow');
			curHeader = 'header-web';
			$('#header-web').fadeIn('slow');
		}
	});
	$('#nav-web').mouseleave(function() {
		$(this).attr('src','img/web.png');
	});
	$('#nav-games').mouseover(function() {
		$(this).attr('src','img/games-o.png');
		if(curHeader != 'header-games') {
			$('#'+curHeader).fadeOut('slow');
			curHeader = 'header-games';
			$('#header-games').fadeIn('slow');
		}
	});
	$('#nav-games').mouseleave(function() {
		$(this).attr('src','img/games.png');
	});
	$('#nav-dgdp').mouseover(function() {
		$(this).attr('src','img/film-dgdp-o.png');
		if(curHeader != 'header-dgdp') {
			$('#'+curHeader).fadeOut('slow');
			curHeader = 'header-dgdp';
			$('#header-dgdp').fadeIn('slow');
		}
	});
	$('#nav-dgdp').mouseleave(function() {
		$(this).attr('src','img/film-dgdp.png');
	});
	$('#nav-projektatlantis').mouseover(function() {
		$(this).attr('src','img/film-projektatlantis-o.png');
		if(curHeader != 'header-projektatlantis') {
			$('#'+curHeader).fadeOut('slow');
			curHeader = 'header-projektatlantis';
			$('#header-projektatlantis').fadeIn('slow');
		}
	});
	$('#nav-projektatlantis').mouseleave(function() {
		$(this).attr('src','img/film-projektatlantis.png');
	});
	$('#nav-sturmwelten').mouseover(function() {
		$(this).attr('src','img/film-sturmwelten-o.png');
		if(curHeader != 'header-sturmwelten') {
			$('#'+curHeader).fadeOut('slow');
			curHeader = 'header-sturmwelten';
			$('#header-sturmwelten').fadeIn('slow');
		}
	});
	$('#nav-sturmwelten').mouseleave(function() {
		$(this).attr('src','img/film-sturmwelten.png');
	});
	$('#nav-wasser').mouseover(function() {
		$(this).attr('src','img/film-wasser-o.png');
		if(curHeader != 'header-wasser') {
			$('#'+curHeader).fadeOut('slow');
			curHeader = 'header-wasser';
			$('#header-wasser').fadeIn('slow');
		}
	});
	$('#nav-wasser').mouseleave(function() {
		$(this).attr('src','img/film-wasser.png');
	});
	//window.setTimeout("flickerText(0)",2000);
	var text;
	$('.header-text').each(function() {
		text = $(this).html();
		text = replaceUmlauts(text);
		$(this).html(text.replace(/\b([A-Za-z0-9])/g,'<span class="caps">$1</span>'));
		$('.caps').css('font-size',38);
	});
});

function replaceUmlauts(text) {
	text = text.replace(/&amp;/,"&");
	text = text.replace(/&auml;/,"ä");
	text = text.replace(/&Auml;/,"Ä");
	text = text.replace(/&uuml;/,"ü");
	text = text.replace(/&Uuml;/,"Ü");
	text = text.replace(/&Ouml;/,"Ö");
	text = text.replace(/&ouml;/,"ö");
	text = text.replace(/&szlig;/,"ß");
	return text;
}

function flickerText(off) {
	if(off) {
		$("#header-img div").css("text-shadow","none");
		$("#header-img div").css("color","#777788");
		window.setTimeout("flickerText(0)",100);
	} else {
		$("#header-img div").css("text-shadow","0px 0px 10px #aae, 4px 0px 4px #55a, -4px 0px 4px #55a");
		$("#header-img div").css("color","#eeeeff");
		var rand = parseInt( Math.random() * 2 );
		if(rand == 1) {
			window.setTimeout("flickerText(1)",100);
		} else {
			window.setTimeout("flickerText(1)",2500);
		}
	}
}
