(function($) {
  Slider = function(photos) {
    var newBackground = '';
    var photoIndex = 0;
    var timer = '';
    var interval = 10000;
    var previousImage = $('#photo img:nth-child(1)');

    var next = function() {
      photoIndex += 1;

      if (photoIndex == photos.length) {
        photoIndex = 0;
      }

      var photo = photos[photoIndex];

      $('#ribbon a').css('background-position', '0 -' + photo.position + 'px').attr('href', photo.url);
      $('#photo img:nth-child(' + (photoIndex + 1) + ')').css({'z-index': '10'});
      previousImage.css({'z-index': '0'});
      $('#photo img:nth-child(' + (photoIndex + 1) + ')').fadeTo(1000, 1, function () {
        previousImage.css({opacity: '0'});
	previousImage = $(this);
      });
    }

    var startTimer = function() {
      timer = setInterval(function() { next(); }, interval); 
    };
    
    // Link und Ribbon-Text nach dem Laden anpassen
    $('#ribbon a').css('background-position', '0 -' + photos[0].position + 'px').attr('href',  photos[0].url);

    // Beim Hover über #photo die Navigation und den Eigentümer des Photos
    // anzeigen und den Timer pausieren 
    $('#photo').hover(function() {
      clearInterval(timer);
      timer = '';
    }, startTimer);

   startTimer(); 

  };
})(jQuery);

