/**
 *---------------------------------------------------------------------------------------
 * @package      VP Conversion Tracking - Joomla! System Plugin
 * @subpackage   For VirtueMart 3+
 *---------------------------------------------------------------------------------------
 * @copyright    Copyright (C) 2012-2021 VirtuePlanet Services LLP. All rights reserved.
 * @license      GNU General Public License version 2 or later; see LICENSE.txt
 * @authors      Abhishek Das
 * @email        info@virtueplanet.com
 * @link         https://www.virtueplanet.com
 *---------------------------------------------------------------------------------------
*/

!(function($, win, doc) {
	$(doc).off('init.vpct').on('init.vpct', function() {
		$('.vpct-products').each(function() {
			var that = this,
				max_height = 0;

			$('.vpct-product-inner, .clearfix:visible', that).removeAttr('style').removeClass('vpct-resized').removeClass('vpct-checked').each(function() {
				if ($(this).hasClass('vpct-product-inner') && !$(this).hasClass('vpct-checked') && !$(this).hasClass('vpct-resized')) {
					if ($(this).outerHeight() > max_height) {
						max_height = $(this).outerHeight();
					}
					$(this).addClass('vpct-checked');
				}
				if ($(this).hasClass('clearfix')) {
					$('.vpct-product-inner.vpct-checked:not(.vpct-resized)', that).css('min-height', max_height).addClass('vpct-resized');
					max_height = 0;
				}
			});
		});
	});
	
	$(function() {
		$(doc).trigger('init.vpct');
	});

	$(win).load(function() {
		$(doc).trigger('init.vpct');
	});

	var vpct_resize_timeout = null;

	$(win).resize(function() {
		if (vpct_resize_timeout) clearTimeout(vpct_resize_timeout);

		vpct_resize_timeout = setTimeout(function() {
			$(doc).trigger('init.vpct');
		}, 200);
	});
})(jQuery, window, document);