var lastCarouselImageIndex = 1;

function carouselIndicatorOnClick(id) {
  var carousel = jQuery("#home-carousel").data("jcarousel");
  carousel.scroll(jQuery.jcarousel.intval(id));
  carouselIndicatorToggle(lastCarouselImageIndex);
  carouselIndicatorToggle(id);
}

function carouselIndicatorCallback(carousel, item, idx, state) {
  if (state == 'init') return;
  carouselIndicatorToggle(lastCarouselImageIndex);
  carouselIndicatorToggle(idx);
  lastCarouselImageIndex = idx;
}

function carouselIndicatorToggle(id) {
  var imageObj = document.getElementById("carouselindicatorimage_" + id.toString());
  if (imageObj.className == "jcarousel-home-indicator-item") {
    imageObj.className = "jcarousel-home-indicator-item-active";
  } else {
    imageObj.className = "jcarousel-home-indicator-item";
  }
}

// Init the home carousel
jQuery(document).ready(function() {
  $("#home-carousel").jcarousel({scroll:1,visible:1,wrap:"both",itemVisibleInCallback:{onBeforeAnimation:carouselIndicatorCallback}});
});

