/*********************************************************
* Variablen
*********************************************************/

// var xyz = 'xyz';


/*********************************************************
* 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);
	});
}


/*********************************************************
* Slideshow jqGalScroll
*********************************************************/

function slideShow( domReady )
{
	if( domReady )
	{
		if( $('ul.post-gallery li img').length > 1 )
		{
			$('ul.post-gallery li img').hide()
			$('ul.post-gallery li:first-child img').show()
		}
	}
	else
	{
		if( $('ul.post-gallery li img').length > 1 )
		{
			var galleryWidth = parseInt('0');
			var galleryHeight = parseInt('0');
			
			$('ul.post-gallery li img').each(function(i){
				if( $(this).width() > galleryWidth ) {
					galleryWidth = $(this).width();
				}
				if( $(this).height() > galleryHeight ) {
					galleryHeight = $(this).height();
				}
			});
			
			$('ul.post-gallery').jqGalScroll({
				ease: null,
				speed: 500,
				width: galleryWidth,
				height: galleryHeight,
				direction: 'horizontal'
			});
			
			$('div.jqGSPagination li a').each(function(){
				if( $(this).text().length == 1 )
				{
					$(this).text('0' + $(this).text());
				}
			});
			$('div.jqGSPagination li:last a').text('Info');
			if($('#content .pdf-link').length > 0) {
				$('div.jqGSPagination ul').append('<li>' + $('#content .pdf-link').html() + '</li>');
				$('#content .pdf-link').html('');
			}
		}
	}
}


/*********************************************************
* Tooltip
*********************************************************/

function tooltip()
{
	$("#content img").tooltip({
		track: true,
		showURL: false
	});
}


/*********************************************************
* Document-Ready
*********************************************************/

$(document).ready(function() { // Wenn DOM geladen, dann ...
	scrollinterna(); // Scrollinks
	maildecoding(); // eMail-Verschlüsselung
	slideShow(1) // Slideshow jqGalScroll - Bilder ausblenden
	tooltip(); // Tooltip
});

window.onload = function() {
	
	slideShow(); // Slideshow jqGalScroll
	
}