var totalSlides = 0;
var currentSlide = 1;
var contentSlides = "";

$(document).ready(function(){
  $("#previous").click(showPreviousSlide);
  $("#next").click(showNextSlide);
  
  var totalWidth = 0;
  contentSlides = $(".slideshow-content");
  contentSlides.each(function(i){
    totalWidth += this.clientWidth;
    totalSlides++;
  });
  $("#slideshow-holder").width(totalWidth);
  $("#slideshow-scroller").attr({scrollLeft: 0});
  $("#previous").hide();
  //$("#previous-dis").hide();
  
  
});

function showPreviousSlide()
{
  currentSlide--;
  
  if(currentSlide>=1){
		updateContentHolder();
		$("#next").fadeIn();
		//$("#next-dis").hide();
	}else{
		currentSlide=1;
		//currentSlide=totalSlides;
		//updateContentHolder();
	}
	
	if(currentSlide==1){
		$("#previous").fadeOut();
		//$("#previous-dis").hide();
	}
	
  
}

function showNextSlide()
{
	
	
  currentSlide++;
  if(currentSlide<=totalSlides){
		updateContentHolder();
		//$("#previous-dis").hide();
		$("#previous").fadeIn();
	}else{
		currentSlide=totalSlides;
	}
	if(currentSlide==totalSlides){
		$("#next").fadeOut();
		//$("#next-dis").hide();
	}
	
 
  
  
}

function updateContentHolder()
{
  var scrollAmount = 0;
  contentSlides.each(function(i){
    if(currentSlide - 1 > i) {
      scrollAmount += this.clientWidth;
    }
  });
  $("#slideshow-scroller").animate({scrollLeft: scrollAmount}, 1000);
}



