var index;

$(document).ready(function () {
	$('.arrow').on('click', newNextSlide);
	$('.go').on('click', goSlide);
	$('.btn-feedback').on('click', showFeedback);
	$('.close').on('click', closeFeedback);
	$('#eje1-p2').hide();
});

function newNextSlide() {
	indexSection = $(this).attr('data-section');
	direction = $(this).attr('data-direction');
	section = document.querySelector('#'+indexSection+' div[data-content="1"]');
	content = section.querySelectorAll('#'+indexSection+' div[data-content="1"] > .slide');
	limit = $('#'+indexSection+' div[data-content="1"]').attr('data-limit');
	console.log(content);
	for (var i = 0; i < content.length; i++) {
		if ($(content[i]).is(':visible')) {
			if (direction == 'next') {
				index = parseInt($(content[i+1]).attr('data-position'));
				console.log(index);
				$('#'+indexSection+' div[data-content="1"] .arrow').show();
				if (index == content.length || index == limit) {
					$(this).hide();
				}
			} else if (direction == 'previous') {
				index = parseInt($(content[i-1]).attr('data-position'));
				console.log(index);
				$('#'+indexSection+' div[data-content="1"] .arrow').show();
				if (index == 1) {
					$(this).hide();
				}
			}
		}
	}
	for (var i = 1; i < 3; i++) {
		v =	$('#'+indexSection+' .content'+i).attr('data-content');
		if (v != 0) {
			for (var i2 = 1; i2 <= content.length; i2++) {
				$('#'+indexSection+' .slide'+i2).hide();
			}
			$('#'+indexSection+' .slide'+index).fadeIn();
			break
		}
	}
}

function goSlide() {
	n = $(this).attr('data-index');
	indexSection = $(this).attr('data-section');
	section = document.querySelector('#'+indexSection+' div[data-content="1"]');
	content = section.querySelectorAll('#'+indexSection+' div[data-content="1"] > .slide');
	g = $(this).attr('data-go');
	// on = $('#'+indexSection+' div[data-content="1"] .slide').is(':visible');
	console.log(content);
	if (g == 0) {
		$('#'+indexSection+' div[data-content="1"] .arrow').css({'pointer-events': 'none', 'z-index': '-1'}); 
	} else if (g == 1) {
		$('#'+indexSection+' div[data-content="1"] .arrow').css({'pointer-events': 'auto', 'z-index': 0});
	}
	for (var i = 1; i < 3; i++) {
		v =	$('#'+indexSection+' .content'+i).attr('data-content');
		if (v != 0) {
			for (var i2 = 1; i2 <= content.length; i2++) {
				$('#'+indexSection+' .slide'+i2).hide();
			}
			$('#'+indexSection+' .slide'+n).fadeIn();
			break
		}
	}
}

function showFeedback() {	$('.box-feedback').hide();	$('.flecha_adelante').show();	
	indexSection = $(this).attr('data-section');
	// $('#'+indexSection+' div[data-content="1"] .arrow').show();
	$('#' + indexSection + ' div[data-content="1"] .arrow').css('pointer-events', 'none');
	indexFeedback = $(this).attr('data-feedback');
	$('#' + indexSection + ' div[data-content="1"] #feedback' + indexFeedback).show();
}

function closeFeedback() {
	indexSection = $(this).attr('data-section');
	$('#' + indexSection + ' div[data-content="1"] .arrow').css('pointer-events', 'auto');
	indexFeedback = $(this).attr('data-feedback');
	$('#' + indexSection + ' div[data-content="1"] #feedback' + indexFeedback).hide();
	btn = $(this).attr('data-btn');
	if (btn) {
		contentBtn = document.querySelectorAll('input[data-btn="' + btn + '"]'); // colocar este data en la img de x que estas en la retro. data-btn = ipt1, ipt2, ipt3...
		for (var i = 0; i < contentBtn.length; i++) {
			$(contentBtn[i]).attr('disabled', 'disabled');
		}
	}
}