$(document).ready(function() {
  
  if($('.headerSlideshow').length) initSlideShow();
  
  $('.thumbs a').fancybox({
  		prevEffect	: 'fade',
		nextEffect	: 'fade',
  		openEffect	: 'elastic',
  		closeEffect	: 'elastic'
  	});
  	
  	$('a.video').fancybox({
  			prevEffect	: 'fade',
  			nextEffect	: 'fade',
  			openEffect	: 'elastic',
  			closeEffect	: 'elastic',
  			width		: 800,
  			height		: 450,
  			scrolling	: 'no'
  		});
  	
  
  $('a.formular').fancybox({
  		prevEffect	: 'fade',
  		nextEffect	: 'fade',
  		openEffect	: 'elastic',
  		closeEffect	: 'elastic',
  		width		: 550,
  		height		: 730,
  		scrolling	: 'yes'
  	});
  
  
  
});



// SlideShow

function initSlideShow(){
	var images = $('.headerSlideshow img');
	var i = randomFromTo(0, images.length-1);
	
	
	$(images[i]).show();
	
	function change(){
		i = i<images.length-1 ? i+1 : 0;
		images.each(function( index ){
			if(index != i){
				$(images[index]).fadeOut(1400);
			} else {
				$(images[index]).fadeIn(1500);
			}
		});
	}
	
	setInterval(change, 5000);
		
}

function randomFromTo(from, to){
   return Math.floor(Math.random() * (to - from + 1) + from);
}
