function OCTgeturlparam(param) {
	var urlParams = new URLSearchParams(window.location.search);
	return urlParams.get(param) !== null ? param+'='+urlParams.get(param) : '';
}
var OCT4_GET_LANG = '';
var prdstkr_ur1201 = 'index.php?route=module/prdstkr/';
var prdstkr_url230 = 'index.php?route=extension/module/prdstkr/';
var prdstkr_url401 = 'index.php?route=extension/prdstkr/module/prdstkr|';
var prdstkr_url402 = 'index.php?route=extension/prdstkr/module/prdstkr.';

var prdstkr = {	
	'atgrid': function() {
  		var prd_product_ids = [];
 		$(".product-thumb a.product-img").each(function() {
			var target = $(this).closest('.product-thumb, .product-wrapper');
			var atag_str = $(this).attr('href').split('product_id');
			var product_id = parseInt(atag_str[1].match(/[0-9]+/));
			if(target.length && target.hasClass('prdstkr_atgrid') == false) {
				target.addClass('prdstkr_atgrid').addClass('prdstkr_atgrid'+product_id);
				prd_product_ids.push(product_id);
 			}
		});
		if(prd_product_ids.length) { 
 			$.ajax({
				url: prdstkr_url230 + 'getcache' + OCT4_GET_LANG,
				type: 'post',
				data: {product_ids:prd_product_ids},
				cache: true,
				complete: function() { 
				},
				success: function(json) {
					if(json) {
						//console.log(json);
						$(".product-thumb a.product-img").each(function() {
 							var target = $(this).closest('.product-thumb, .product-wrapper');
							var atag_str = $(this).attr('href').split('product_id');
							var product_id = atag_str[1].match(/[0-9]+/);
							if(json[product_id] && target.length) {
								$.each(json[product_id], function(prdstkr_id,val) {
									//console.log(json[product_id]);
									if(json[product_id][prdstkr_id] && target.find('.prdstkr_grd' + prdstkr_id).length == 0) {
										target.prepend(val['grid']);
									}
								});
 							}
						});
					}
				}
			});
		}		
  	},	
	'prodpage': function() {	
		var prd_product_ids = [];
		var product_id = false;
		
		if($(".button-group-page input[name='product_id']").length) {
			product_id = $(".button-group-page input[name='product_id']").val();
			prd_product_ids.push(product_id);
		} else if($('#input-product-id').length) {
			product_id = $('#input-product-id').val();
			prd_product_ids.push(product_id);
		} else if($(".product-info input[name='product_id']").length) {
			product_id = $(".product-info input[name='product_id']").val();
			prd_product_ids.push(product_id);
		} else if($("#product input[name='product_id']").length) {
			product_id = $("#product input[name='product_id']").val();
			prd_product_ids.push(product_id);
		} else if($("[property*='og:url']").length) {
			product_id = parseInt($("[property*='og:url']").attr('content').match(/[0-9]+/));
			prd_product_ids.push(product_id);
		} 
			
		if (prd_product_ids.length) {
			$.ajax({
				url: prdstkr_url230 + 'getcache' + OCT4_GET_LANG,
				type: 'post',
				data: {product_ids:prd_product_ids},
				cache: true,
				complete: function() { 
				},
				success: function(json) {
					if(json) {
						var target = $('#product').parent().parent().find('ul.thumbnails li:eq(0)');
						var target2 = $('.product-info .left .image');
						var target3 = $('.product-info .product-left .main-image');
						var targetoc4 = $('#product-info div.magnific-popup');
						
						if(json[product_id]) {
							$.each(json[product_id], function(prdstkr_id,val) {
								//console.log(json[product_id]);
								if(json[product_id][prdstkr_id] && target.length && target.find('.prdstkr_prdpg' + prdstkr_id).length == 0) {
									target.prepend(val['prgpg']);
								}
								
								if(json[product_id][prdstkr_id] && target2.length && target2.find('.prdstkr_prdpg' + prdstkr_id).length == 0) {
									target2.prepend(val['prgpg']);
								}
								
								if(json[product_id][prdstkr_id] && target3.length && target3.find('.prdstkr_prdpg' + prdstkr_id).length == 0) {
									target3.prepend(val['prgpg']);
								}
								
								if(json[product_id][prdstkr_id] && targetoc4.length && targetoc4.find('.prdstkr_prdpg' + prdstkr_id).length == 0) {
									targetoc4.prepend(val['prgpg']);
								}
							});
						}
					}
				}
			});
 		}
  	},
 	'initjson': function() {
		prdstkr.atgrid(); 
		$(document).ajaxStop(function() { 
			prdstkr.atgrid();
		});
		prdstkr.prodpage();
	}	
}
$(document).ready(function() {
prdstkr.initjson();
});