jQuery(document).ready(function ($) {

	var steps = 1;
	var maxSteps = parseInt($(".pixelio-cart-abandon-recovery-more-progress-bar-container").attr("max_step"));
	$(".pixelio-cart-abandon-recovery-more-step-next").hide();
	$(".pixelio-cart-abandon-recovery-more-step-" + steps).show();
	$(".pixelio-cart-abandon-recovery-more-step-back").hide();
	for (var i = 2; i <= maxSteps; i++) {
		$(".pixelio-cart-abandon-recovery-more-step-" + i).hide();
	}

	function setProgress(percent) {
		$('.pixelio-cart-abandon-recovery-more-progress-fill').css('width', percent + '%');
		$('.pixelio-cart-abandon-recovery-more-progress-text').text(percent + '%');
	}

	function nextStep() {
		$(".pixelio-cart-abandon-recovery-more-step-" + steps).hide();
		steps++;

		if (steps > 1) {
			$(".pixelio-cart-abandon-recovery-more-step-back").show();
		}

		if ($(".step-" + steps).data('step-state') == 1) {
			$(".pixelio-cart-abandon-recovery-more-step-next").show();
		} else {
			$(".pixelio-cart-abandon-recovery-more-step-next").hide();
		}

		setProgress(parseInt(steps * (100 / (maxSteps + 1))));
		$(".pixelio-cart-abandon-recovery-more-step-" + steps).show();
	}

	function backStep() {
		$(".pixelio-cart-abandon-recovery-more-step-" + steps).hide();
		steps--;

		if (steps === 1) {
			$(".pixelio-cart-abandon-recovery-more-step-back").hide();
		}

		if ($(".pixelio-cart-abandon-recovery-more-step-" + steps).data('step-state') == 1) {
			$(".pixelio-cart-abandon-recovery-more-step-next").show();
		} else {
			$(".pixelio-cart-abandon-recovery-more-step-next").hide();
		}

		setProgress(parseInt(steps * (100 / (maxSteps + 1))));
		$(".pixelio-cart-abandon-recovery-more-step-" + steps).show();
	}

	window.nextStep = nextStep;
	window.backStep = backStep;

	setProgress(parseInt(100 / (maxSteps + 1)));

	$(".pixelio-cart-abandon-recovery-more-step-back").on('click', function (e) {
		e.preventDefault();
		backStep();
	});
	$(".pixelio-cart-abandon-recovery-more-step-next").on('click', function (e) {
		e.preventDefault();

		nextStep();
	});
});
