$('.select-model, .select-product, .select-variation, .select-artist, .select-theme').on('change', function()
{
	window.location = $(this).val();
});

// for local
$('a').each(function(i,l)
{
	/*
	var url = $(l).attr('href');

	if(url.indexOf("casecompany.") != -1)
	{
		var new_url = url.replace('casecompany.', 'casecompany-cart.');
		new_url = new_url.replace('shop/', '');
		$(l).attr('href', new_url);
	}
	*/

});

$('.filter-smartphone').on('click', function(){
	if($(this).attr('oc') === 'closed')
	{
		$('.filters').show();
		$(this).attr('oc', 'open');
	}
	else
	{
		$('.filters').hide();
		$(this).attr('oc', 'closed');
	}
});

$('.filter-at').on('click', function(){
	if($(this).attr('oc') === 'closed')
	{
		$('.filters-at').show();
		$(this).attr('oc', 'open');
	}
	else
	{
		$('.filters-at').hide();
		$(this).attr('oc', 'closed');
	}
});

$('.rmore').on('click', function()
{
	let txt = $('.at-description .mobile p').attr('attr-txt');
	let old = $('.at-description .mobile p').html();

	$('.at-description p').text(txt);
});


setInterval(function(){ switchExtraThumbs() }, 3000);

function switchExtraThumbs()
{
	$('.products-item img').each(function(i,l)
	{
		var thumbs = $(l).attr('extra-thumbs');

		if (thumbs !== 'null') {
            var index = $(l).attr('index');
            var original = $(l).attr('original');
            var extrathumbs = JSON.parse(thumbs);

            $(l).css('transition', 'opacity 0.2s ease-in-out');
            $(l).css('opacity', 0.7);

            setTimeout(function() {
                if (index === 'original') {
                    $(l).attr('src', extrathumbs[0]);
                    $(l).attr('index', 0);
                } else {
                    index = parseInt(index);
                    var length = parseInt(extrathumbs.length);

                    if ((index + 1) < length) {
                        index++;
                        $(l).attr('src', extrathumbs[index]);
                        $(l).attr('index', index);
                    } else {
                        $(l).attr('src', original);
                        $(l).attr('index', 'original');
                    }
                }
				$(l).on('load', function() {
                    $(l).css('opacity', 1);
                });
            }, 200); // Delay for the initial opacity reset to take effect
        }
	});
}
