$(document).ready(function(){
  var $fotos = $('#display img'),
    $container = $('.thumbWrapper');
    
  $('#thumbnails .thumbWrapper img').each(function(){
    $(this).wrap('<a href="#"></a>');
  });  

  $fotos.each(function(){
    $(this).attr({'height':'267','width':'370'}).css({'height':'267px','width':'370px'});
    var $text = $(this).next('.text');
    $(this).wrap('<div class="slide"></div>');
    $(this).parent('.slide').append($text);
    //$text.remove();
  });
  
  if($fotos.length == 0){
    $('#thumbnails').hide();
  }

  $container.css({'width':($fotos.length * 114)});
  $('#display').cycle({ 
    fx: 'fade', 
    speed: 1200,
    timeout: 0,
    next: '#display img',    
    pager:  $container,
    pagerAnchorBuilder: function(idx, slide) { 
      // return '<div class="thumbnail"><a onclick="thumbLinks();" href="#"><img src="' + slide.src + '" /></a></div>'; 
      return '.thumbWrapper a:eq(' + idx + ')';  
    } 
  });
    
  // calls the scroller function
  scroller();

  $('#gallery').cycle({ 
    random: 1,
    fx: 'fade', 
    speed: 2000, 
    timeout: 11000,  
    delay: -5500    
  });
  
});

function scroller(){
  $('.wrapper').serialScroll({
    items: $('.thumbWrapper a'),
    prev: 'a.previous',
    next: 'a.next',
    duration: 600,
    force: true,
    stop: true,
    lock: false,
    step: 1, 
    // easing:'easeOutQuart',
    cycle: false //don't pull back once you reach the end
  });
}



