$(document).ready(function () {
	$.getJSON('/json/ipgeo', (function (data) {
		console.log(data);
		var ipcode = data.ipgeocode;
		console.log('The ipcode is ' + ipcode);

		if (ipcode == 'GB') { //UK Pound		
			$('#local-telephone').html('<i class="fas fa-phone"></i> 01480 396 395');
			if ($.cookie('exp__currency') === null || $.cookie('exp__currency') === "" || $.cookie('exp__currency') === "null" || $.cookie('exp__currency') === undefined) {
				var CookieSet = $.cookie('exp__currency', 'GB', {
					path: '/'
				});
			}
			if ($.cookie('exp__country') === null || $.cookie('exp__country') === "" || $.cookie('exp__country') === "null" || $.cookie('exp__country') === undefined) {
				var CookieSet = $.cookie('exp__country', 'GBR', {
					path: '/'
				});
			}
			//$('.currencyBut i').addClass("fa-pound-sign");
		} else if (ipcode == 'US') { //US Dollar			
			$("#local-telephone").html("Tel: +1 800 591 2796 (Toll Free)");
			if ($.cookie('exp__currency') === null || $.cookie('exp__currency') === "" || $.cookie('exp__currency') === "null" || $.cookie('exp__currency') === undefined) {
				var CookieSet = $.cookie('exp__currency', 'US', {
					path: '/'
				});
			}
			if ($.cookie('exp__country') === null || $.cookie('exp__country') === "" || $.cookie('exp__country') === "null" || $.cookie('exp__country') === undefined) {
				var CookieSet = $.cookie('exp__country', 'USA', {
					path: '/'
				});
			}
			//$('.currencyBut i').addClass("fa-dollar-sign");
		} else if (ipcode == 'AD' || ipcode == 'AT' || ipcode == 'BE' || ipcode == 'CY' || ipcode == 'EE' || ipcode == 'FI' || ipcode == 'FR' || ipcode == 'DE' || ipcode == 'GR' || ipcode == 'IE' || ipcode == 'IT' || ipcode == 'XK' || ipcode == 'LV' || ipcode == 'LU' || ipcode == 'MT' || ipcode == 'MC' || ipcode == 'ME' || ipcode == 'NL' || ipcode == 'PT' || ipcode == 'SM' || ipcode == 'SK' || ipcode == 'SI' || ipcode == 'ES' || ipcode == 'VA') {
			$("#local-telephone").html("");
			if ($.cookie('exp_currency') === null || $.cookie('exp__currency') === "" || $.cookie('exp__currency') === "null" || $.cookie('exp__currency') === undefined) {
				var CookieSet = $.cookie('exp__currency', 'EU', {
					path: '/'
				});
			}
			if ($.cookie('exp__country') === null || $.cookie('exp__country') === "" || $.cookie('exp__country') === "null" || $.cookie('exp__country') === undefined) {
				var CookieSet = $.cookie('exp__country', 'EUR', {
					path: '/'
				});
			}
			//$('.currencyBut i').addClass("fa-euro-sign");
		} else { //USDollar - catch all 			
			$("#local-telephone").html("");
			if ($.cookie('exp__currency') === null || $.cookie('exp__currency') === "" || $.cookie('exp__currency') === "null" || $.cookie('exp__currency') === undefined) {
				var CookieSet = $.cookie('exp__currency', 'US', {
					path: '/'
				});
			}
			if ($.cookie('exp__country') === null || $.cookie('exp__country') === "" || $.cookie('exp__country') === "null" || $.cookie('exp__country') === undefined) {
				var CookieSet = $.cookie('exp__country', 'ROW', {
					path: '/'
				});
			}
			//$('.currencyBut i').addClass("fa-dollar-sign");
		}
	}));

	$("a.currgb").click(function () {
		CookieSet = $.cookie('exp__currency', 'GB', {
			path: '/'
		});
	});
	$("a.currus").click(function () {
		CookieSet = $.cookie('exp__currency', 'US', {
			path: '/'
		});
	});
	$("a.curreu").click(function () {
		CookieSet = $.cookie('exp__currency', 'EU', {
			path: '/'
		});
	});

	if ($.cookie('exp__currency') === 'GB') {
		$('.currencyBut i').removeClass("fa-dollar-sign fa-euro-sign").addClass("fa-pound-sign");
		var currenCookieSet = $.cookie('exp__currenCook', 'GBP', {
			path: '/'
		});
	}
	if ($.cookie('exp__currency') === 'US') {
		$('.currencyBut i').removeClass("fa-pound-sign fa-euro-sign").addClass("fa-dollar-sign");
		var currenCookieSet = $.cookie('exp__currenCook', 'USD', {
			path: '/'
		});
	}
	if ($.cookie('exp__currency') === 'EU') {
		$('.currencyBut i').removeClass("fa-dollar-sign fa-pound-sign").addClass("fa-euro-sign");
		var currenCookieSet = $.cookie('exp__currenCook', 'EUR', {
			path: '/'
		});
	}

	//Cart JSON call and cookie cuttr

	$.getJSON('/json/global_cart', (function (data) {
		console.log(data);
		if (data.order_qty == 0) {
			$(".cartupdate").text(" 0 ");
		} else if (data.order_qty == 1) {
			$(".cartupdate").text(" 1 ");
			$(".cartSubTot").text("(" + data.order_subtotal + ")");
		} else if (data.order_qty >= 2) {
			$(".cartupdate").text(" " + data.order_qty + " ");
			$(".cartSubTot").text("(" + data.order_subtotal + ")");
		}
	}));

	var str = $(".cartSubTot").text();
	str = str.slice(0);
	$(".cartSubTot").text(str);

	//tooltip for lang and curr

	$('[data-toggle=modal-popover]').each(function () {
		$(this).popover({
			content: $(this).attr("popover-content"),
			title: $(this).attr("popover-title")
		})
		$(this).tooltip({
			placement: 'right',
			title: $(this).attr("tooltip-title")
		})
	})

});
