var currentBlockHeaderImage = 0;
var speed = 3500;
var maxloops = 50;
var loops = 0;
var countAll = 1;
var slideIntervalId;
 
$(document).ready(function() {
	var imagesBlocks = $("#header-images-slideshow .header-image");
	loops = 1;
	if (imagesBlocks.length > 0) {
	   /*$("#header-images-slideshow .header-image:first").fadeIn();
	   countAll = imagesBlocks.length;
	   setTimeout(changeContentHeader, speed);*/
		$(function() {
			slideIntervalId = setInterval( "slideSwitch()", speed );
		});
	}
	
	$(".logo h1").click(function() {
		window.location.href = "/";
	});
	$(".logo_en h1").click(function() {
		window.location.href = "/en/";
	});
	$(".logo_de h1").click(function() {
		window.location.href = "/de/";
	});
	
	$('#gallery a[rel=lbox]').lightBox({fixedNavigation:true,
		overlayBgColor: '#080b18',
		overlayOpacity: 0.6,
		containerResizeSpeed: 350,
		imageLoading: '/images/lightbox-ico-loading.gif',
		imageBtnClose: '/images/lightbox-btn-close.gif',
		imageBtnPrev: '/images/lightbox-btn-prev.gif',
		imageBtnNext: '/images/lightbox-btn-next.gif',
		txtImage: 'Zdjęcie',
		txtOf: 'z'
	});
});

/* function changeContentHeader() {
	if (loops < maxloops) {
		loops++;
	} else {
		return 0;
	}
	$("#header-images-slideshow .header-image").fadeOut();
	
	if (currentBlockHeaderImage == countAll - 1) {
	   currentBlockHeaderImage = 0;
	   $("#header-images-slideshow .header-image:eq("+currentBlockHeaderImage+")").fadeIn();
	   setTimeout(changeContentHeader, speed);
	} else {
	  currentBlockHeaderImage++;
	  $("#header-images-slideshow .header-image:eq("+currentBlockHeaderImage+")").fadeIn();
	  setTimeout(changeContentHeader, speed);
	} 
} */

function slideSwitch() {
	var $active = $('#header-images-slideshow div.active');
	if (loops >= maxloops) {
		clearInterval(slideIntervalId);
	}
	loops++;
    if ( $active.length == 0 ) $active = $('#header-images-slideshow div:last');
    var $next =  $active.next().length ? $active.next() : $('#header-images-slideshow div:first');
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

