if($.cookie('exp__currency') === 'GB' ) { 
	var jsonfile = '/json/logg_rf_json_gb'
}
if($.cookie('exp__currency') === 'US' ) { 
	var jsonfile = '/json/logg_rf_json_us'
}
if($.cookie('exp__currency') === 'EU' ) { 
	var jsonfile = '/json/logg_rf_json_eu'
}

$.getJSON(jsonfile, (function(data) {
	console.log(data);
	var price1012a = data.priceData[2].price;
	var price1216a = data.priceData[3].price;
	var price1012b = data.priceData[4].price;
	var price1216b = data.priceData[5].price;
	
	var val1012a = data.priceData[2].price_val;
	var val1216a = data.priceData[3].price_val;
	var val1012b = data.priceData[4].price_val;
	var val1216b = data.priceData[5].price_val;

//INITIALISE WIDGET
    var loc = $(location).attr('href');
    var currency = $.cookie("exp__currenCook");

	var stock_level = $(".stklvl").data("stock");
	console.log("stock_level = "+stock_level);

    $("#total").html(price1012a);$("#model").text("1012");$("#cat").val("PP543");$("input[name='entry_id']").val("5688");$("#chan").text("12");

    $(".confCartBut").attr("onclick", "dataLayer.push({'event': 'add_to_cart', 'ecommerce':  {'currency': '"+currency+"', 'value': '"+val1012a+".00', 'items': [{'item_id': 'PP543', 'item_url': '"+loc+"', 'item_name': '1012a', 'price': '"+val1012a+".00', 'quantity': '1'}]}});");

	dataLayer.push({
		'event': 'view_cart',
		'ecommerce': {
			'currency': currency,
			'value': "0.00",
			'items': [
				{
				'item_id': "PP543",
				'item_url': loc,
				'item_name':"1012a",
				'price': val1012a+".00",
				'quantity': '1',
				'stock_av': stock_level,
				},
			]
		}
	}); 

    var resCheck = 0; var boaCheck = 0;

	$("label").removeAttr( "disabled" );$(".res").first().addClass("active");$(".board").first().addClass("active");

$(".res").click(function() { resCheck = $(this).find("input").val(); boaCheck = $(".board.active").find("input").val(); });
$(".board").click(function() { boaCheck = $(this).find("input").val(); resCheck = $(".res.active").find("input").val(); });
$(".configButs").click(function() {
	if (resCheck == "10" && boaCheck == "no"){
		$("#total").html(price1012a);$("#model").text("1012");$("#cat").val("PP543");$("input[name='entry_id']").val("5688");$("#chan").text("12");
        $(".confCartBut").attr("onclick", "dataLayer.push({'event': 'add_to_cart', 'ecommerce':  {'currency': '"+currency+"', 'value': '"+val1012a+".00', 'items': [{'item_id': 'PP543', 'item_url': '"+loc+"', 'item_name': '1012a', 'price': '"+val1012a+".00', 'quantity': '1'}]}});");

		console.log("stock_level = "+stock_level);
		setTimeout(function() {
			var stock_level = $(".stklvl").data("stock");
			dataLayer.push({
				'event': 'view_cart',
				'ecommerce': {
					'currency': currency,
					'value': "0.00",
					'items': [
						{
						'item_id': "PP543",
						'item_url': loc,
						'item_name':"1012a",
						'price': val1012a+".00",
						'quantity': '1',
						'stock_av': stock_level,
						},
					]
				}
			}); 
		}, 1000);
	} else if (resCheck == "12" && boaCheck == "no"){
		$("#total").html(price1216a);$("#model").text("1216");$("#cat").val("PP544");$("input[name='entry_id']").val("5692");$("#chan").text("16");
        $(".confCartBut").attr("onclick", "dataLayer.push({'event': 'add_to_cart', 'ecommerce':  {'currency': '"+currency+"', 'value': '"+val1216a+".00', 'items': [{'item_id': 'PP544', 'item_url': '"+loc+"', 'item_name': '1216a', 'price': '"+val1216a+".00', 'quantity': '1'}]}});");
		console.log("stock_level = "+stock_level);
		setTimeout(function() {
			var stock_level = $(".stklvl").data("stock");
			dataLayer.push({
				'event': 'view_cart',
				'ecommerce': {
					'currency': currency,
					'value': "0.00",
					'items': [
						{
						'item_id': "PP544",
						'item_url': loc,
						'item_name':"1216a",
						'price': val1216a+".00",
						'quantity': '1',
						'stock_av': stock_level,
						},
					]
				}
			}); 
		}, 1000);
	} else if (resCheck == "10" && boaCheck == "yes"){
		$("#total").html(price1012b);$("#model").text("1012");$("#cat").val("PP546");$("input[name='entry_id']").val("17661");$("#chan").text("12");
        $(".confCartBut").attr("onclick", "dataLayer.push({'event': 'add_to_cart', 'ecommerce':  {'currency': '"+currency+"', 'value': '"+val1012b+".00', 'items': [{'item_id': 'PP546', 'item_url': '"+loc+"', 'item_name': '1012b', 'price': '"+val1012b+".00', 'quantity': '1'}]}});");
		setTimeout(function() {
			dataLayer.push({
				'event': 'view_cart',
				'ecommerce': {
					'currency': currency,
					'value': "0.00",
					'items': [
						{
						'item_id': "PP546",
						'item_url': loc,
						'item_name':"1012b",
						'price': val1012b+".00",
						'quantity': '1',
						'stock_av': stock_level,
						},
					]
				}
			}); 
		}, 1000);
	} else if (resCheck == "12" && boaCheck == "yes"){
		$("#total").html(price1216b);$("#model").text("1216");$("#cat").val("PP547");$("input[name='entry_id']").val("17671");$("#chan").text("16");
		$(".confCartBut").attr("onclick", "dataLayer.push({'event': 'add_to_cart', 'ecommerce':  {'currency': '"+currency+"', 'value': '"+val1216b+".00', 'items': [{'item_id': 'PP547', 'item_url': '"+loc+"', 'item_name': '1216b', 'price': '"+val1216b+".00', 'quantity': '1'}]}});");
		setTimeout(function() {
			dataLayer.push({
				'event': 'view_cart',
				'ecommerce': {
					'currency': currency,
					'value': "0.00",
					'items': [
						{
						'item_id': "PP547",
						'item_url': loc,
						'item_name':"1216b",
						'price': val1216b+".00",
						'quantity': '1',
						'stock_av': stock_level,
						},
					]
				}
			}); 
		}, 1000);
	}
});

}));

$(document).ready(function() {
	$('.fancybox').fancybox({
		openEffect : 'fade',
		openSpeed  : 150,
		closeEffect : 'fade',
		closeSpeed  : 150,
		aspectRatio : true,
		scrolling   : 'no',
		helpers: {
			title : {
				type : 'inside'
			},
			overlay : {
				css : {
					'background' : 'rgba(87,120,165,0.55)'
				}
			}
		}
	});
});
$("a.zoom").append("<span></span>");

$(window).scroll(function() {
	if ($(this).scrollTop() > 100) {$('.scrollup').fadeIn();} else {$('.scrollup').fadeOut();}
});

$(function() {
	$('.scrollup').click(function() {
		$("html, body").animate({
			scrollTop: 0
		}, 600);
		return false;
	});
});
$(function () {

    $('.popover-link').popover({
        html: true,
        placement: 'right'
    })
        .click(function (e) {e.preventDefault();});

    $(':not(#anything)').on('click', function (e) {
        $('.popover-link').each(function () {
            //the 'is' for buttons that trigger popups
            //the 'has' for icons and other elements within a button that triggers a popup
            if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
                $(this).popover('hide');
                return;
            }
        });
    });
});
$(".accsTabs li:first").addClass("active");
$(".tab-pane:first").addClass("active");
//Reviews product selector
$('select#prod_id').on('change', function() {
  $(".hiddenFields input[name='entry_id']").val(this.value);
});