/*********************************************************
* Variablen
*********************************************************/

var ntTrans = parseInt('5000'); // Anzeige einer News des Newsticker in ms


/*********************************************************
* Scrolllinks
*********************************************************/

function scrollinterna()
{
	$('a[href*=#]').click(function() {
		if( location.pathname.replace( /^\//,'' ) == this.pathname.replace( /^\//,'' ) && location.hostname == this.hostname && $(this).attr('href').replace( /#/,'' ) != '' )
		{
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length)
			{
				var targetOffset = $target.offset().top;
				$('html,body').animate({scrollTop: targetOffset}, 800, 'swing');
				return false;
			}
		}
	});
};

/*********************************************************
* eMail-Verschlüsselung
*********************************************************/

function maildecoding()
{
	$('.email').each(function(){
		var mailArr = $(this).html();
		mailArr = mailArr.split(' ');
		var mailTxt = mailArr[0] + "@" + mailArr[2] + "." + mailArr[4];
		var mailOut = "<a href=\"mailto:" + mailTxt + "\" title=\"" + mailTxt + "\">" + mailTxt + "</a>";
		$(this).html(mailOut);
	});
}


/*********************************************************
* News-Ticker
*********************************************************/
var ntFirstEl;
var ntActEl;


function newsticker()
{
	$('#content .news-teaser h4').hide();
	$('#content .news-teaser h4:first').fadeIn('fast', function(){
		ntFirstEl = $(this);
		ntActEl = $(this);
		window.setTimeout('fadeMe()', ntTrans);
	});
}

function fadeMe()
{
	var nextEl = ( !$(ntActEl).next().length ) ? ntFirstEl : $(ntActEl).next();
	$(ntActEl).fadeOut('slow', function(){
		$(nextEl).fadeIn('slow', function(){
			ntActEl = nextEl;
			window.setTimeout('fadeMe()', ntTrans);
		});
	});
}


/*********************************************************
* Menü-Boxen
*********************************************************/

function menuBox()
{
	$('#menu li a').click(function(){
		hideMenuBox();
		if( $(this).parent('li').children('ul').is(':hidden') )
			$(this).parent('li').children('ul').fadeIn('slow');
		return false;
	});
	$('html, body').click(function(){
		hideMenuBox();
	});
}

function hideMenuBox()
{
	$('#menu li ul').each(function(){
		if( !$(this).is(':hidden') )
			$(this).fadeOut('fast');
	});
}


/*********************************************************
* Fancy-Box-Zoom
*********************************************************/

function fancyBoxZoom()
{
	$("a[href*=.jpg], a[href*=.gif], a[href*=.png], a.lightboxlink").fancybox({
		
		overlayOpacity: .4
	});
}


/*********************************************************
* Document-Ready
*********************************************************/

$(document).ready(function() { // Wenn DOM geladen, dann ...
	scrollinterna(); // Scrollinks
	maildecoding(); // eMail-Verschlüsselung
	newsticker(); // News-Ticker
	//menuBox(); // Menü-Boxen
	fancyBoxZoom(); // Fancy-Box-Zoom
});
