var w1;
var w2;
var w3;
var desc1;
var desc2;
var price;
var autoDestacadoInterval;

var currProduct = 1;
var totalProducts;;
var enabled = true;


function toRight(auto){
	if(!enabled) return;
	
	if(currProduct == totalProducts){
		if(auto){
			updateProduct(-(totalProducts-1));
			slidePhotos('+='+(242*(totalProducts-1)), 0, 300);
		}else{
			return;
		}
	}else{
		updateProduct(1);
		slidePhotos('-=242', currProduct-1);
	}
}

function toLeft(){
	if(!enabled) return;
	if(currProduct == 1) return;
	updateProduct(-1);
	slidePhotos('+=242', currProduct-1);
}


function showTitle(index){
	$("#LGT_destacadoProductosPhoto_Headers2").children().eq(index).show();
}

function hideTitle(index){
	$("#LGT_destacadoProductosPhoto_Headers2").children().eq(index).hide();
}

function updateProduct(inc){
	hideTitle(currProduct-1);
	currProduct += inc;
	showTitle(currProduct-1);
	setPaginadorText();
}

function setPaginadorText(){
	$('#LGT_destacadoProductosBox_Footer_paginador').html(currProduct + copies.paginadorText + totalProducts);
}

function slidePhotos(leftVal, index, timer){
	enabled = false;
	//initTextElements(index);
	var slideTime = (timer == null) ? 250 : timer;
	stopShowNextDestacado();
	$('#LGT_destacadoProductosPhotosContainer').animate({ left: leftVal}, slideTime, function() {
		enabled = true;
		showNextDestacado();
		//animateTextElements(index);
	});
}

/*function initTextElements(index){
	desc1 = $('#LGT_destacadoProductosPhotosContainer').children().eq(index).children().eq(1).children().eq(0);
	desc2 = $('#LGT_destacadoProductosPhotosContainer').children().eq(index).children().eq(2).children().eq(0);
	price = $('#LGT_destacadoProductosPhotosContainer').children().eq(index).children().eq(3).children().eq(0);
	w1 = desc1.css('left');
	w2 = desc2.css('left');
	w3 = price.css('left');
	
	var offset = 30;
	desc1.css('display', 'none');
	desc2.css('display', 'none');
	price.css('display', 'none');
	
	desc1.css('left', desc1.width() + offset);
	desc2.css('left', desc2.width() + offset);
	price.css('left', price.width() - offset);
}

function animateTextElements(index){
	var time1 = 200;
	var time2 = 70;
	
	setTimeout(function(){ desc1.css('display', 'inline'); desc1.animate({ left: w1 }, time1, function() { }); }, 100);
	setTimeout(function(){ desc2.css('display', 'inline'); desc2.animate({ left: w2 }, time1, function() { enabled = true; showNextDestacado(); }); }, 200);
	setTimeout(function(){ price.css('display', 'inline'); price.animate({ left: w3 }, time2, function() { }); }, 300);
}*/
	
	
	
function doShowNextDestacado(){
	toRight(true);
}


function showNextDestacado(){
	stopShowNextDestacado();
	autoDestacadoInterval = setInterval("doShowNextDestacado()", 10000);
}

function stopShowNextDestacado(){
	clearInterval(autoDestacadoInterval);
}


	
$(document).ready(function(){
	$('#rightArrow').click(function(e){
		e.preventDefault();
		toRight();
	});
	
	$('#leftArrow').click(function(e){
		e.preventDefault();
		toLeft();
	});
	
	totalProducts = $("#LGT_destacadoProductosPhoto_Headers2 div").length;
	for(var i = currProduct; i<totalProducts; i++){
		hideTitle(i);
	}
	$('#LGT_destacadoProductosPhoto_Headers2').show();
	
	setPaginadorText();
	//initTextElements(0);
	//animateTextElements();
	showNextDestacado();
});





