
$(document).ready(function() {
   var spacing = 165;

   function createControl(src) {
      return $('<img/>')
      .attr('src', src)
      .addClass('control')
      .css('opacity', 0.6)
      .css('display', 'none');
   }

  // wywaliłwm definiccje zmiennych

   var $enlargedCover = $('<img/>')
   .addClass('enlarged')
   .hide()
   .appendTo('body');
   var $closeButton = createControl('images/close.gif')
   .addClass('enlarged-control')
   .appendTo('body');
   var $priceBadge = $('<div/>')
   .addClass('enlarged-price')
   .css('opacity', 0.6)
   .css('display', 'none')
   .appendTo('body');


   $('#featured-books').css({
      'width': spacing * 3,
      'height': '120px',
      'overflow': 'hidden'
   }).find('.covers a').css({
      'float': 'none',
      'position': 'absolute',
      'left': 1000
   });

   var setUpCovers = function() {
      var $covers = $('#featured-books .covers a');

      $covers.unbind('click mouseenter mouseleave');

      // Lewy obrazek — przewinięcie w prawo (w celu zobaczenia obrazków z lewej strony).
      $covers.eq(0)
      .css('left', 0)
      .click(function(event) {
         $covers.eq(0).animate({'left': spacing}, 'fast');
         $covers.eq(1).animate({'left': spacing * 2}, 'fast');
         $covers.eq(2).animate({'left': spacing * 3}, 'fast');
         $covers.eq($covers.length - 1)
         .css('left', -spacing)
         .animate({'left': 0}, 'fast', function() {
            $(this).prependTo('#featured-books .covers');
            setUpCovers();
         });

         event.preventDefault();
      }).hover(function() {
         $leftRollover.appendTo(this).show();
      }, function() {
         $leftRollover.hide();
      });

      // Prawy obrazek — przewinięcie w lewo (w celu zobaczenia obrazków z prawej strony).
      $covers.eq(2)
      .css('left', spacing * 2)
      .click(function(event) {
         $covers.eq(0)
         .animate({'left': -spacing}, 'fast', function() {
            $(this).appendTo('#featured-books .covers');
            setUpCovers();
         });
         $covers.eq(1).animate({'left': 0}, 'fast');
         $covers.eq(2).animate({'left': spacing}, 'fast');
         $covers.eq(3)
         .css('left', spacing * 3)
         .animate({'left': spacing * 2}, 'fast');

         event.preventDefault();
      }).hover(function() {
         $rightRollover.appendTo(this).show();
      }, function() {
         $rightRollover.hide();
      });

 $covers.eq(1)
      .css('left', spacing)
    .hover(function() {
     $enlargeRollover.appendTo(this).show();
     }, function() {
        $enlargeRollover.hide();
      });
   };

   setUpCovers();
});


