
var totalSlides = 0;
var currentSlide = 1;
var contentSlides = "";
$j = jQuery.noConflict();
$j(document).ready(function(){

  $j("#slideshow-previous").click(showPreviousSlide);
  $j("#slideshow-next").click(showNextSlide);
  
  var totalWidth = 0;
  contentSlides = $j(".slideshow-content");
  
  contentSlides.each(function(i){
    totalWidth += this.clientWidth;
    totalSlides++;
  });
  $j("#slideshow-holder").width(totalWidth);
  $j("#slideshow-scroller").attr({scrollLeft: 0});
  
  if(playTime > 0) {
      updateButtons();
      autoPlay();
  }
});

function autoPlay() {
    
    if(currentSlide > totalSlides) {
        currentSlide = 2;
        showPreviousSlide();
        setTimeout("autoPlay()", playTime);
        return;
    }
    showNextSlide();
    setTimeout("autoPlay()", playTime);
}

function showPreviousSlide()
{
  currentSlide--;
  updateContentHolder();
  updateButtons();
}

function showNextSlide()
{
  currentSlide++;
  updateContentHolder();
  updateButtons();
}

function updateContentHolder()
{
  var scrollAmount = 0;
  contentSlides = $j(".slideshow-content");
  contentSlides.each(function(i){
   if(currentSlide - 1 > i) {
      scrollAmount += this.clientWidth;
    }
  });
  $j("#slideshow-scroller").animate({scrollLeft: scrollAmount}, 1000);
}

function updateButtons()
{
  if(currentSlide < totalSlides) {
    $j("#slideshow-next").show();
  } else {
    $j("#slideshow-next").hide();
  }
  if(currentSlide > 1) {
    $j("#slideshow-previous").show();
  } else {
    $j("#slideshow-previous").hide();
  }
}


