/* top vineyards rotation */

var duration = 6000;
var countItems = 1; 
var newTimer;
var totalItems = 10;
var rotationState = "Play";

function setTotalItems(totalItems) {
	this.totalItems = totalItems;
}

function hideShowElements(elemToHideId){
	var elementToHide = document.getElementById("vineyard_" + elemToHideId);
	if(elementToHide) {
		elementToHide.style.display = "none";
		var elementToDisplay = document.getElementById("vineyard_" + countItems);
		elementToDisplay.style.display = "block";
		document.getElementById("vineyard_select").innerHTML = countItems;
 	}
}
function restartTimer(){
	clearTimeout(_topVineyards);
	_topVineyards = setTimeout("moveForward()", duration);
}
function moveBack(){
	if(totalItems == 0){
		return;
	}
	var elementToHideId= countItems;
	countItems--;
	if(countItems == 0){
		countItems=totalItems;
		elementToHideId=1;
	}
	hideShowElements(elementToHideId);
	restartTimer();
}
function moveForward(){

	if(totalItems == 0){
		return;
	}
	var elementToHideId=countItems;
	countItems++;
	var valueToCompare = totalItems;
	valueToCompare++;
	if(valueToCompare == countItems){
		countItems=1;
		elementToHideId=totalItems;
	}
	hideShowElements(elementToHideId);
	restartTimer();
}
function moveCurrent(){
	if(totalItems == 0){
		return;
	}
	var elementToHideId=countItems;
	countItems = 1;
	
	hideShowElements(elementToHideId);
	restartTimer();
}
_topVineyards = setTimeout("moveForward()", duration);
		
