$(document).ready(function() {
var calosc = $(" .calosc");
var link = $("#ogloszenia .czyt_cal");
var ogloszenie = $("div .ogloszenie")
var c = 1;
$('<div id="kt"></div>').insertAfter("#nawigacja");

$("#slajder").css({
width: (ogloszenie.length * 670) + 'px'
});


$("#kt").html('<span>'+1+'</span>' + ' z ' + ogloszenie.length);

calosc.hide();

link.click(function() {
 slajd(300);
 });



function slajd(b) {
clearInterval(timer);
 calosc.eq(c-1).slideToggle(b);
 if (link.html() == 'Czytaj całość')
  {link.html('Ukryj'); }
  else
  {link.html("Czytaj całość");}
}


$("#rigth").click(function() {
clearInterval(timer);
if (c < ogloszenie.length)
 {
  if (link.html() == 'Ukryj')
  slajd(50);
  c=c+1;
  $("#slajder .ogloszenie").animate({'left': '-=570px'},
  {
  complete: function() {
  $("#kt").html('<span>'+c+'</span>' + ' z ' + ogloszenie.length);}
  });
 }
});

$("#left").click(function() {
clearInterval(timer);
 if (c > 1)
 {
  if(link.html()  == 'Ukryj')
  slajd(50);
  c=c-1;
  $("#slajder .ogloszenie").animate({'left': '+=570px'},
  {
  complete: function() {
  $("#kt").html('<span>'+c+'</span>' + ' z ' + ogloszenie.length);}
  });
 }
});

function slajdy() {

if (c < ogloszenie.length)
 {
  c=c+1;
  $("#slajder .ogloszenie").animate({'left': '-=570px'},
  {
  complete: function() {
  $("#kt").html('<span>'+c+'</span>' + ' z ' + ogloszenie.length); }
  });
 }
 else
 { 
 $("#slajder .ogloszenie").animate({'left': '+='+ 570 * (ogloszenie.length - 1) + 'px'},'fast');
//$("#slajder .ogloszenie").css({'left': '+='+ 670 * (ogloszenie.length) + 'px'});
 
c=1;
 $("#kt").html('<span>'+c+'</span>' + ' z ' + ogloszenie.length);
 }

};

var timer = setInterval(function() {
    slajdy();
    }, 5000);


});



