$(function() {
  $('.travail .photo, a.actualite_image').fancybox({
    overlayOpacity: 0.2,
    titlePosition: 'inside',
    padding: 10,
    titleFormat: function(title, currentArray, currentIndex, currentOpts) {
      var titlef = '<span class="fancybox-travail">' + title + '</span>';
      var img = $('img', currentArray[currentIndex]);
      if (img.attr('alt') && img.attr('alt') != title) {
        titlef += ' &nbsp; | &nbsp; <span class="fancybox-photo-title">' + img.attr('alt') + '</span>';
      }
      return titlef;
    }
  });
});

$(window).load(function() {

  $('.scroll').each(function() {
    var $this = $(this);
    var $pane = $this.parent();
    $this.data('scrollw', 0);
    $('.photo', $this).each(function() {

      $this.data('scrollw', $this.data('scrollw') + $(this).outerWidth());

      if ($this.data('scrollw') > $pane.width() + 10) {
        //          $this.css({'width': $this.data('scrollw') + 'px'});

        if (!$this.data('slided')) {
          $('<div/>', {'width': $pane.width() - 15}).insertAfter($pane).slider({
              slide: function(e, ui) {
                $this.css('margin-left', Math.round( ui.value / 100 * ( $pane.width() - $this.data('scrollw') + 10 )) + 'px');
              }
          });
          $this.data('slided', true);
        }
      }
    });
  });
});


