$(document).ready(function(){
  var currentPosition = 0;
  var slideWidth = 301;
  var liczba_slajdow = 12;
  var slides = $('.slide');
  var numberOfSlides = slides.length;

  // Remove scrollbar in JS
  $('#slidesContainer').css('overflow', 'hidden');

  // Wrap all .slides with #slideInner div
  slides
  .wrapAll('<div id="slideInner"></div>')
    // Float left to display horizontally, readjust .slides width
	.css({
      'float' : 'left',
      'width' : slideWidth
    });

  // Set #slideInner width equal to total width of all slides
  $('#slideInner').css('width', slideWidth * numberOfSlides);

  // Insert controls in the DOM
//  $('#slideshow')
//    .prepend('<span class="control foto_left" id="leftControl"></span>')
//    .append('<span class="control foto_right" id="rightControl"></span>'); //foto_right

  // Hide left arrow control on first load
  manageControls(currentPosition);

  // Create event listeners for .controls clicks
  $('.control')
    .bind('click', function(){
    // Determine new position
	currentPosition = ($(this).attr('id')=='rightControl') ? currentPosition+1 : currentPosition-1;

	// Hide / show controls
    manageControls(currentPosition);
    // Move slideInner using margin-left
    $('#slideInner').animate({
      'marginLeft' : slideWidth*(-currentPosition)
    });
    $('#aktualny_slajd').html(currentPosition+1 + '/12');
  });

  // manageControls: Hides and Shows controls depending on currentPosition
  function manageControls(position){
    // Hide left arrow if position is first slide
	if(position==0){$('#leftControl').hide()} else{$('#leftControl').show()}
	// Hide right arrow if position is last slide
    if(position==numberOfSlides-1){$('#rightControl').hide()} else{$('#rightControl').show()}
  }
  
  
        var czas = 5000; //1000 = 1s
        var intervalID = window.setInterval(przewin, czas);


  function przewin(){
      liczba_slajdow=liczba_slajdow-2;
    if(currentPosition>10){
        currentPosition = 0;
    }
    else{
        currentPosition =  currentPosition+1;
    }
    manageControls(currentPosition);
    // Move slideInner using margin-left
    $('#slideInner').animate({
      'marginLeft' : slideWidth*(-currentPosition)
    });
    $('#aktualny_slajd').html(currentPosition+1 + '/12');
  }

  $("#slideshow").hover(
    function(){
        clearInterval(intervalID);
    },
    function(){
        intervalID = window.setInterval(przewin, czas);
    });
      

});


jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
    return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

//jQuery(function($){
//    $('#slideshow2').serialScroll({
//        items:'li',
//        prev:'#screen2 a.prev',
//        next:'#screen2 a.next',
//        offset:-230, //when scrolling to photo, stop 230 before reaching it (from the left)
//        start:1, //as we are centering it, start at the 2nd
//        duration:1200,
//        force:true,
//        stop:true,
//        lock:false,
//        cycle:false, //don't pull back once you reach the end
//        easing:'easeOutQuart', //use this easing equation for a funny effect
//        jump: true //click on the images to scroll to them
//    });
//
//});
//
//



