$(document).ready(function() {
	var i = 0;
	$('.aktualnosciBox').each(function() { 
		$(this).attr('id', 'aktualnosciBox-'+i);
		i++;
	});
	var activeBox = 0;
	var countBox = $('.aktualnosciBox').size() - 1;
	var boxTimer = 0;
	boxTimer = setInterval(function() {
		var oldBox = activeBox;
		if(oldBox>=countBox) {
            var newBox = 0;
        }
		else {
			newBox = parseInt(oldBox) + 1;
		}
		activeBox = newBox;
		$('#aktualnosciBox-'+oldBox).fadeOut('slow', function(){
            $('#kwadracik-'+activeBox).addClass('zamalowany').siblings().removeClass('zamalowany');
            $('#aktualnosciBox-'+activeBox).fadeIn('slow');
        });                            
    },5000);
	$('#kwadraciki a').click(function(){ 
        var sId = $(this).attr('id');
        var aId = sId.split('-');
		var oldBox = activeBox;
		activeBox = aId[1];
		$('#aktualnosciBox-'+oldBox).fadeOut('fast', function(){
            $('#kwadracik-'+activeBox).addClass('zamalowany').siblings().removeClass('zamalowany');
            $('#aktualnosciBox-'+activeBox).fadeIn('fast');
			clearTimeout(boxTimer);
        });
    });
});
$(document).ready(function() {
	var i = 0;
	$('.aktualnosciBox2').each(function() { 
		$(this).attr('id', 'aktualnosciBox2-'+i);
		i++;
	});
	var activeBox = 0;
	var countBox = $('.aktualnosciBox2').size() - 1;
	var boxTimer = 0;
	boxTimer = setInterval(function() {
		var oldBox = activeBox;
		if(oldBox>=countBox) {
            var newBox = 0;
        }
		else {
			newBox = parseInt(oldBox) + 1;
		}
		activeBox = newBox;
		$('#aktualnosciBox2-'+oldBox).fadeOut('slow', function(){
            $('#kwadracik2-'+activeBox).addClass('zamalowany2').siblings().removeClass('zamalowany2');
            $('#aktualnosciBox2-'+activeBox).fadeIn('slow');
        });                            
    },4000);
	$('#kwadraciki2 a').click(function(){ 
        var sId = $(this).attr('id');
        var aId = sId.split('-');		
		var oldBox = activeBox;
		activeBox = aId[1];
		$('#aktualnosciBox2-'+oldBox).fadeOut('fast', function(){
            $('#kwadracik2-'+activeBox).addClass('zamalowany2').siblings().removeClass('zamalowany2');
            $('#aktualnosciBox2-'+activeBox).fadeIn('fast');
			clearTimeout(boxTimer);
        });
    });
});
