/*
	
	HEADER
	>
	SLAJDY
	>
	KOLECZKA I INNE MASJTERSZTYKI
	>
	PJONA
	
*/

function slideSwitch() {
    var $active = $('#photo IMG.active');

    if ( $active.length == 0 ) $active = $('#photo IMG:last');

    var $next =  $active.next().length ? $active.next() : $('#photo IMG:first');

    $active.addClass('last-active');
	
	var index = $("#photo IMG").index( $('.last-active')[0] );
	index = index + 1;
	if (index == 5) {index = 0;}
	var koleczko = '#header span:eq(' + index + ')';	
	$(koleczko).addClass('active').siblings().removeClass('active');
	
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });

}

$(function() {
    setInterval( "slideSwitch()", 9000 );
	
	$('#header span').click(function(){
		$(this).addClass('active').siblings().removeClass('active');
		
		var klasa = $(this).attr('class');
		klasa = klasa.substr(0,6); // jakie zdjecie mamy wybrac
		
		if (klasa == 'photo1') {$('#photo IMG:eq(0)').addClass('active').css("opacity", "1.0").siblings().removeClass('active last-active');}
		if (klasa == 'photo2') {$('#photo IMG:eq(1)').addClass('active').css("opacity", "1.0").siblings().removeClass('active last-active');}
		if (klasa == 'photo3') {$('#photo IMG:eq(2)').addClass('active').css("opacity", "1.0").siblings().removeClass('active last-active');}
		if (klasa == 'photo4') {$('#photo IMG:eq(3)').addClass('active').css("opacity", "1.0").siblings().removeClass('active last-active');}
		if (klasa == 'photo5') {$('#photo IMG:eq(4)').addClass('active').css("opacity", "1.0").siblings().removeClass('active last-active');}
		
   });
})

