

function autoplay_slider()
{
	if(currentSlide < totalSlides) {
		showNextSlide();
	} else
	{
		// set current slide as 1
		currentSlide=1;
		// scroll back
		var scrollAmount = 0;
		contentSlides.each(function(i){
		  scrollAmount += this.clientWidth;
		});
		$("#slideshow-scroller").animate({scrollLeft: -scrollAmount}, 1000);
		// update the nav controls
		updateButtons();
	}
}

function autoplay_slider2()
{
	if(currentSlide2 < totalSlides2) {
		showNextSlide2();
	} else
	{
		// set current slide as 1
		currentSlide2=1;
		// scroll back
		var scrollAmount = 0;
		contentSlides2.each(function(i){
		  scrollAmount += this.clientWidth;
		});
		$("#slideshow-scroller2").animate({scrollLeft: -scrollAmount}, 1000);
		// update the nav controls
		updateButtons2();
	}
}
// ===================
// copy the functions for each section of slider
// ===================
function showPreviousSlide()
{
  currentSlide--;
  updateContentHolder();
  updateButtons();
}

function showPreviousSlide2()
{
  currentSlide2--;
  updateContentHolder2();
  updateButtons2();
}

function showPreviousSlide3()
{
  currentSlide3--;
  updateContentHolder3();
  updateButtons3();
}

function showPreviousSlide4()
{
  currentSlide4--;
  updateContentHolder4();
  updateButtons4();
}

function showPreviousSlide5()
{
  currentSlide5--;
  updateContentHolder5();
  updateButtons5();
}

// ============

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

function showNextSlide2()
{
  currentSlide2++;
  updateContentHolder2();
  updateButtons2();
}

function showNextSlide3()
{
  currentSlide3++;
  updateContentHolder3();
  updateButtons3();
}

function showNextSlide4()
{
  currentSlide4++;
  updateContentHolder4();
  updateButtons4();
}

function showNextSlide5()
{
  currentSlide5++;
  updateContentHolder5();
  updateButtons5();
}

// ============

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

function updateContentHolder2()
{
  var scrollAmount = 0;
  contentSlides2.each(function(i){
    if(currentSlide2 - 1 > i) {
      scrollAmount += this.clientWidth;
    }
  });
  $("#slideshow-scroller2").animate({scrollLeft: scrollAmount}, 1000);
}

function updateContentHolder3()
{
  var scrollAmount = 0;
  contentSlides3.each(function(i){
    if(currentSlide3 - 1 > i) {
      scrollAmount += this.clientWidth;
    }
  });
  $("#slideshow-scroller3").animate({scrollLeft: scrollAmount}, 1000);
}

function updateContentHolder4()
{
  var scrollAmount = 0;
  contentSlides4.each(function(i){
    if(currentSlide4 - 1 > i) {
      scrollAmount += this.clientWidth;
    }
  });
  $("#slideshow-scroller4").animate({scrollLeft: scrollAmount}, 1000);
}

function updateContentHolder5()
{
  var scrollAmount = 0;
  contentSlides5.each(function(i){
    if(currentSlide5 - 1 > i) {
      scrollAmount += this.clientWidth;
    }
  });
  $("#slideshow-scroller5").animate({scrollLeft: scrollAmount}, 1000);
}

// ============

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


function updateButtons2()
{
  if(currentSlide2 < totalSlides2) {
    $("#slideshow-next2").show();
  } else {
    $("#slideshow-next2").hide();
  }
  if(currentSlide2 > 1) {
    $("#slideshow-previous2").show();
  } else {
    $("#slideshow-previous2").hide();
  }
}

function updateButtons3()
{
  if(currentSlide3 < totalSlides3) {
    $("#slideshow-next3").show();
  } else {
    $("#slideshow-next3").hide();
  }
  if(currentSlide3 > 1) {
    $("#slideshow-previous3").show();
  } else {
    $("#slideshow-previous3").hide();
  }
}

function updateButtons4()
{
  if(currentSlide4 < totalSlides4) {
    $("#slideshow-next4").show();
  } else {
    $("#slideshow-next4").hide();
  }
  if(currentSlide4 > 1) {
    $("#slideshow-previous4").show();
  } else {
    $("#slideshow-previous4").hide();
  }
}

function updateButtons5()
{
  if(currentSlide5 < totalSlides5) {
    $("#slideshow-next5").show();
  } else {
    $("#slideshow-next5").hide();
  }
  if(currentSlide5 > 1) {
    $("#slideshow-previous5").show();
  } else {
    $("#slideshow-previous5").hide();
  }
}
// ============

function setOpacity(elem,op_val)
{
	// transparency code commented
	/*$(elem).css({opacity:op_val})
	.bind('mouseover mouseout', function(e){
		$(this).css({opacity:(e.type=="mouseover")? 1 : op_val})
	});
	*/
}

var totalSlides = 0;
var currentSlide = 1;
var contentSlides = "";

function slider1(sessid){
  // add tracking on controls
  $("#slideshow-previous").click(function() {
    clearInterval(slideplay);
  	showPreviousSlide();
    logChange(sessid,'tophotel1_previous');
  });
  $("#slideshow-next").click(function() {
    clearInterval(slideplay);
  	showNextSlide();
    logChange(sessid,'tophotel1_next');
  });

  setOpacity("#slideshow-previous",0.8);
  setOpacity("#slideshow-next",0.8);

  var totalWidth = 0;
  contentSlides = $(".slideshow-content");
  contentSlides.each(function(i){
    totalWidth += this.clientWidth;
    totalSlides++;
  });
  $("#slideshow-holder").width(totalWidth);
  $("#slideshow-scroller").attr({scrollLeft: 0});
  updateButtons();
  // for auto play of special promotions
  slideplay = setInterval("autoplay_slider()", 5000);

  // more info button click function
  $("#moreinfo").click(function() {
  	contentSlides.each(function(i){
    if(currentSlide-1 == i) {
      var loc = $("#slide"+currentSlide).attr("href");
      if(loc != undefined) {
      	window.location=loc;
      }
    }
  	});
    logChange(sessid,'promo_moreinfo');
  });
}