var sayings = [
  "If you're buying a car, buy with confidence with a pre-purchase inspection.", 
  "When do you need an appraisal? Before you need one!",
  "An appraisal is an insurance policy against total loss.", 
  "Don't waste money on an appraisal that won't hold up to scrutiny by insurance companies and in court!",
  "You get an appraisal not to prove to <em>you</em> what it's worth, but to prove to somebody else what it's worth.",
  "The bitter taste of poor quality remains long after the sweet smell of a low price.",
  "Ensure you'll be compensated fairly in the event of theft, accident, bankruptcy, divorce, or a fraudulent sale."
];

function sayings_initCallback(carousel) {
  // Pause autoscrolling if the user moves with the cursor over the clip.
  carousel.clip.hover(function() {
    carousel.stopAuto();
  }, function() {
    carousel.startAuto();
  });
}

function sayings_itemVisibleInCallback(carousel, item, i, state, evt) {
  // The index() method calculates the index from a 
  // given index who is out of the actual item range.
  var idx = carousel.index(i, sayings.length);
  carousel.add(i, sayings_getItemHTML(sayings[idx - 1]));
};

function sayings_getItemHTML(saying) {
  return saying;
}

function sayings_itemVisibleOutCallback(carousel, item, i, state, evt) {
  carousel.remove(i);
}

$(document).ready(function(){

  //$('#saying').text(sayings[1]);  
  //$('#saying').text(sayings.length);

  $('#saying').jcarousel({
      wrap: 'circular',
      auto: 8,
      scroll: 1,
      itemVisibleInCallback: {onBeforeAnimation: sayings_itemVisibleInCallback},
      itemVisibleOutCallback: {onAfterAnimation: sayings_itemVisibleOutCallback},
      initCallback: sayings_initCallback
    });

});

