$(document).ready(function(){
	eMail(); // eMail Links generieren
	Nivo(); // Slideshow starten wenn nötig
	extLink();
	animateSubmenu(true);
});

var eMail = function(){
	$('span.eMail').each(function(){
		var address = $(this).text().replace(/ \(at\) /, '@').replace(/ \(dot\) /, '.');
		$(this).replaceWith($( '<a href="mailto:'+address+'">'+address+'</a>' ));
	});
}

var extLink = function(){
	$('a._blank').each(function(){
		$(this).click(function(){
			window.open($(this).attr('href'));
			return false;
		});
	});
}

var animateSubmenu = function(init){
	if(init === true){
		SubNavElms = [];
		$('#SubNav li a').each(function(){
			SubNavElms[SubNavElms.length] = $(this);
		});
		SubNavElms = jQuery.merge(SubNavElms, jQuery.merge([], SubNavElms).reverse().slice(1, SubNavElms.length));
		for($i = 0; $i < 2; $i++){
			SubNavElms = jQuery.merge(SubNavElms, jQuery.merge([], SubNavElms).slice(1, SubNavElms.length));
		}
		animateSubmenu();
	}else{
		if(elm = SubNavElms.shift()){
			if(elm.hasClass('selected')){
				animateSubmenu();
			}else{
				elm.animate({'color':'#e5097f'}, {'duration':200, 'queue':true});
				elm.delay(400);
				elm.animate({'color':'#aaaaaa'}, {'duration':200, 'queue':true});
//				elm.delay(100);
				elm.animate({'color':'#333333'}, {'duration':200, 'queue':true, 'complete':animateSubmenu});
			}
		}
	}
}

var Nivo = function(){
/*
	Possible effects:
	sliceDown, sliceDownLeft, sliceUp, sliceUpLeft, sliceUpDown, sliceUpDownLeft, fold, fade, random, slideInRight,
	slideInLeft, boxRandom, boxRain, boxRainReverse, boxRainGrow, boxRainGrowReverse
*/
	if($('#SiteImage img').length > 1){
		$('#SiteImage').nivoSlider({
			effect:'random', // ..................... Specify sets like: 'fold,fade,sliceDown'
			slices:16, // ........................... For slice animations
			boxCols:11, // .......................... For box animations
			boxRows:6, // ........................... For box animations
			animSpeed:2000, // ...................... Slide transition speed
			pauseTime:5000, // ...................... How long each slide will show
			startSlide:0, // ........................ Set starting Slide (0 index)
			directionNav:true, // ................... Next & Prev navigation
			directionNavHide:true, // ............... Only show on hover
			controlNav:true, // ..................... 1,2,3... navigation
			controlNavThumbs:false, // .............. Use thumbnails for Control Nav
			controlNavThumbsFromRel:false, // ....... Use image rel for thumbs
			controlNavThumbsSearch:'.jpg', // ....... Replace this with...
			controlNavThumbsReplace:'_thumb.jpg', //  ...this in thumb Image src
			keyboardNav:false, // .................... Use left & right arrows
			pauseOnHover:true, // ................... Stop animation while hovering
			manualAdvance:false, // ................. Force manual transitions
			captionOpacity:0.8, // .................. Universal caption opacity
			prevText:'', // ......................... Prev directionNav text
			nextText:'', // ......................... Next directionNav text
			beforeChange:function(){}, // ........... Triggers before a slide transition
			afterChange:function(){}, // ............ Triggers after a slide transition
			slideshowEnd:function(){}, // ........... Triggers after all slides have been shown
			lastSlide:function(){}, // .............. Triggers when last slide is shown
			afterLoad:function(){} // ............... Triggers when slider has loaded
		});
		$('.nivo-control').text('');
		window.setTimeout("$('a.nivo-nextNav').click();", 3000);
	}
}

