var curPic = 1;
var nextPic = 1;
var maxPics = 10;
var arrowBtnClicked = false;
var direction = "left";

var curEndPos;
var nextBeginPos;
var nextEndPos;
var sni;

$(function() {

	// ROOMS & AMENITIES SLIDESHOW
	bindButtons();
	sni=setInterval("showNextImage()", 4000);
	
});

function showNextImage(){
	
	unBindButtons();
	
	clearInterval(sni);
	
	if (arrowBtnClicked == true){
		arrowBtnClicked = false;
	}
	else
	{
		if (direction == "left"){
			nextPic++;
		} else {
			nextPic--;
		}	
	}
	
	if (nextPic > maxPics){
		nextPic=1;

	} else if (nextPic < 1){
		nextPic=maxPics;
	}
	
	if (direction == "left"){
		curEndPos = -823;
		nextBeginPos = 823;

	} else {
		curEndPos = 823;
		nextBeginPos = -823;
	}

	$("#gallery-image-"+curPic).animate({ marginLeft: curEndPos }, 750, "easeInQuad");
	
	$("#gallery-image-"+nextPic).css("margin-left", nextBeginPos).animate({ marginLeft: 0 }, 750, "easeInQuad", function() {
		curPic=nextPic;
		bindButtons();
		sni=setInterval("showNextImage()", 4000);
	});
	
}

function bindButtons(){
	$(".gallery-arrow-right").click(function() {
  		nextPic++;
		direction = "left";
		arrowBtnClicked = true;
		showNextImage();
	});
	
	$(".gallery-arrow-left").click(function() {
  		nextPic--;
		direction = "right";
		arrowBtnClicked = true;
		showNextImage();
	});
}

function unBindButtons(){
	$(".gallery-arrow-right").unbind('click');
	$(".gallery-arrow-left").unbind('click');
}


