// Funcions für FHP

// Image Slider Startseite	
var startNumber = 0;

$(document).ready(function() {	
	
	//Execute the slideShow
	if($('#gallery .sliderLinks a.headerSlide').length > 0) {
		// 1. Aufruf der Funktion, damit gleich beim Start 1. Slide ausgeführt wird
		galleryLoad();
		// Intervall, damit die anderen Slides auch durchgeführt werden
		var galleryLoop = window.setInterval('galleryLoad()',8600);
		// Intervall, damit die anderen Slides auch durchgeführt werden
		//setInterval('galleryUnload(' + linkItems + ')',8000);
		
		//slideShow();	
	}
	
	// E-Mail Verschlüsselung zum Spam-Schutz //

	$('a[href^="mailto:"]').click(function() {
		var mailString = $(this).attr('href').replace(/\(at\)/,'@');
		if(isEmail(mailString)){ // isEmail ist eine Mura Formcheck-Funktion
			$(this).attr('href', mailString);
			return true;
		}
		return false;		
	});
	
	$('a[name="back"]').click(function() {
		history.back();
		return false;
	});
	
	$('a.showBigImage').click(function() {
		var showHref = $(this).attr('href');
		
		$('#imgMed').attr('style', 'background-image:url(' + showHref + ')');
		
		return false;
	});
	
});

function galleryLoad() {
	var linkCont = $('div.link'); // Hier kommt der Link rein
	var textCont = $('div.caption'); // Hier kommt der Text rein
	var linkItems = $('#gallery .sliderLinks a.headerSlide'); // Alle Links
	var actItem = $('.sliderLinks a.headerSlide').get(startNumber);
	
	var actItemRel = $(actItem).attr('rel');
	
	/* INHALT */
	//Set the opacity to 0 and height to 1px	
	loadText(actItemRel);
	$(textCont).animate({height: '66px', opacity: 1.0}, 700).delay(7000).animate({height: '0', opacity: 0.0}, 700);//.animate({height: '66px'}, 500,loadText(actItemRel)).delay(2000);
	
	/* BILD */
	// weg dafür 
	loadImage($(actItem).clone());
	$(linkCont).animate({opacity: 1.0}, 700).delay(7000).animate({opacity: 0.0}, 700);
	
	// Wenn Startnummer gleich Anzahl - 1, dann wieder auf 0 setzen, ansonsten + 1
	if(startNumber == ($('#gallery .sliderLinks a.headerSlide').length -1)) {
		startNumber = 0;
	} else {
		startNumber += 1;		
	}
}

function clearContent() {
	$('div.caption .content').html();
}

function loadText(actItemRel) {
	$('div.caption .content').html(actItemRel);
}

function loadImage(actItem) {
	var linkCont = $('div.link'); // Hier kommt der Link rein
	$(linkCont).html(actItem);
}

/*
function slideShow() {

	//Set the opacity of all images to 0
	$('#gallery a').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('#gallery a:first').css({opacity: 1.0});
	
	//Get the caption of the first image from REL attribute and display it
	$('#gallery .content').html($('#gallery a:first').attr('rel'))
	.animate({opacity: 1.0}, 400);
	
	//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('gallery()',6000);
	
}

function gallery() {
	
	//if no IMGs have the show class, grab the first image
	var current = ($('#gallery a.show')?  $('#gallery a.show') : $('#gallery a:first'));
	
	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery a:first') :current.next()) : $('#gallery a:first'));	
	
	//Get next image caption
	var caption = next.attr('rel');
	
	//Get next image link
	var link = next.attr('name');
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
	//Set the opacity to 0 and height to 1px
	$('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:0 }).animate({height: '1px'}, { queue:true, duration:300 });
	
	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	$('#gallery .caption').animate({opacity: 1.0},100 ).animate({height: '65px'},500 );
	
	//Display the content
	$('#gallery .content').html(caption);
	$('#gallery .link').attr('href', link);
}
*/
