text: 
  function getURLVar(key) {
  	var value = [];
  
  	var query = String(document.location).split('?');
  
  	if (query[1]) {
  		var part = query[1].split('&');
  
  		for (i = 0; i < part.length; i++) {
  			var data = part[i].split('=');
  
  			if (data[0] && data[1]) {
  				value[data[0]] = data[1];
  			}
  		}
  
  		if (value[key]) {
  			return value[key];
  		} else {
  			return '';
  		}
  	}
  }
  
  $(document).ready(function() {
  	// Highlight any found errors
  	$('.text-danger').each(function() {
  		var element = $(this).parent().parent();
  
  		if (element.hasClass('form-group')) {
  			element.addClass('has-error');
  		}
  	});
  
  	// Currency
  	$('#form-currency .currency-select').on('click', function(e) {
  		e.preventDefault();
  
  		$('#form-currency input[name=\'code\']').val($(this).attr('name'));
  
  		$('#form-currency').submit();
  	});
  
  	// Language
  	$('#form-language .language-select').on('click', function(e) {
  		e.preventDefault();
  
  		$('#form-language input[name=\'code\']').val($(this).attr('name'));
  
  		$('#form-language').submit();
  	});
  
  	/* Search */
  	$('#search input[name=\'search\']').parent().find('button').on('click', function() {
  		var url = $('base').attr('href') + 'index.php?route=product/search';
  
  		var value = $('header #search input[name=\'search\']').val();
  
  		if (value) {
  			url += '&search=' + encodeURIComponent(value);
  		}
  
  		// category Search Start 
  		var category_id = $('#insp-search-category').val();
  		if (category_id > 0) {
  			url += '&category_id=' + encodeURIComponent(category_id);
  		}
  		// category Search END
  
  		location = url;
  	});
  
  	$('#search input[name=\'search\']').on('keydown', function(e) {
  		if (e.keyCode == 13) {
  			$('header #search input[name=\'search\']').parent().find('button').trigger('click');
  		}
  	});
  
  	// category Search Start 
  	$(".insp-search").keyup(function(){
  		if(($(this).val()).length >= 3) {
  			var category_id = $('#insp-search-category').val();
  			//console.log(category_id);
  			$.ajax({
  				url: 'index.php?route=common/insp_search/search',
  				type: 'post',
  				data : 'search_string=' + $(this).val() + '&category_id=' + category_id,
  				beforeSend  : function () {
  	                $('.insp-search-loader').show();
  	            },
  				success: function(result){
  	                $('.insp-search-result').html(result);
  	                $('.insp-search-loader').hide();
  	            }
  			});
  		}
  		else {
  			$('.insp-search-result').html('');
  		}
    	});
  	// category Search END
  
  	// Menu
  	$('#menu .dropdown-menu').each(function() {
  		var menu = $('#menu').offset();
  		var dropdown = $(this).parent().offset();
  
  		var i = (dropdown.left + $(this).outerWidth()) - (menu.left + $('#menu').outerWidth());
  
  		if (i > 0) {
  			$(this).css('margin-left', '-' + (i + 10) + 'px');
  		}
  	});
  
  	// Product List
  	$('#list-view').click(function() {
  		$('#content .product-grid > .clearfix').remove();
  
  		$('#content .row > .product-grid').attr('class', 'product-layout product-list col-xs-12');
  		$('#grid-view').removeClass('active');
  		$('#list-view').addClass('active');
  
  		localStorage.setItem('display', 'list');
  	});
  
  	// Product Grid
  	$('#grid-view').click(function() {
  		// What a shame bootstrap does not take into account dynamically loaded columns
  		var cols = $('#column-right, #column-left').length;
  
  		if (cols == 2) {
  			$('#content .product-list').attr('class', 'product-layout product-grid col-lg-3 col-md-4 col-sm-12 col-xs-12');
  		} else if (cols == 1) {
  			$('#content .product-list').attr('class', 'product-layout product-grid col-lg-3 col-md-4 col-sm-6 col-xs-12');
  		} else {
  			$('#content .product-list').attr('class', 'product-layout product-grid col-lg-3 col-md-3 col-sm-6 col-xs-12');
  		}
  
  		$('#list-view').removeClass('active');
  		$('#grid-view').addClass('active');
  
  		localStorage.setItem('display', 'grid');
  	});
  
  	if (localStorage.getItem('display') == 'list') {
  		$('#list-view').trigger('click');
  		$('#list-view').addClass('active');
  	} else {
  		$('#grid-view').trigger('click');
  		$('#grid-view').addClass('active');
  	}
  
  	// Checkout
  	$(document).on('keydown', '#collapse-checkout-option input[name=\'email\'], #collapse-checkout-option input[name=\'password\']', function(e) {
  		if (e.keyCode == 13) {
  			$('#collapse-checkout-option #button-login').trigger('click');
  		}
  	});
  
  	// tooltips on hover
  	$('[data-toggle=\'tooltip\']').tooltip({container: 'body'});
  
  	// Makes tooltips work on ajax generated content
  	$(document).ajaxStop(function() {
  		$('[data-toggle=\'tooltip\']').tooltip({container: 'body'});
  	});
  });
  
  // Cart add remove functions
  var cart = {
  	'add': function(product_id, quantity) {
  		$.ajax({
  			url: 'index.php?route=checkout/cart/add',
  			type: 'post',
  			data: 'product_id=' + product_id + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
  			dataType: 'json',
  			beforeSend: function() {
  				$('#cart > button').button('loading');
  			},
  			complete: function() {
  				$('#cart > button').button('reset');
  			},
  			success: function(json) {
  				$('.alert-dismissible, .text-danger').remove();
  
  				if (json['redirect']) {
  					location = json['redirect'];
  				}
  
  				if (json['success']) {
  					$('#content').parent().before('<div class="alert alert-success alert-dismissible"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
  
  					// Need to set timeout otherwise it wont update the total
  					setTimeout(function () {
  						$('#cart > button').html('<span class="cartr"><span class="cart-i d-inline-block"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -36 512.001 512" class="svg replaced-svg"><path d="m256 219.988281c5.519531 0 10-4.480469 10-10s-4.480469-10-10-10-10 4.480469-10 10 4.480469 10 10 10zm0 0"></path><path d="m472 139.988281h-59.136719l-90.96875-125.152343c-8.171875-14.003907-26.171875-18.988282-40.46875-11.070313-14.492187 8.050781-19.703125 26.304687-11.648437 40.800781.230468.410156.484375.804688.769531 1.179688l71.351563 94.242187h-171.796876l71.351563-94.242187c.28125-.375.539063-.769532.769531-1.179688 8.035156-14.460937 2.882813-32.730468-11.660156-40.808594-14.265625-7.902343-32.265625-2.921874-40.453125 11.070313l-90.972656 125.160156h-59.136719c-22.054688 0-40 17.945313-40 40 0 17.394531 11.289062 32.539063 27.191406 37.898438 1.695313 1.3125 3.8125 2.101562 6.117188 2.101562.460937 0 .894531.027344 1.347656.089844 4.304688.578125 7.714844 3.84375 8.496094 8.117187l34.019531 187.164063c2.597656 14.269531 15.011719 24.628906 29.519531 24.628906h298.617188c14.507812 0 26.921875-10.359375 29.519531-24.632812l34.019531-187.15625c.78125-4.277344 4.195313-7.542969 8.515625-8.121094.4375-.0625.871094-.089844 1.328125-.089844 2.320313 0 4.453125-.796875 6.148438-2.125 15.914062-5.394531 27.160156-20.511719 27.160156-37.875 0-22.054687-17.945312-40-40-40zm-185.011719-105.660156c-2.285156-4.730469-.511719-10.492187 4.136719-13.070313 4.839844-2.683593 10.941406-.953124 13.609375 3.855469.195313.359375.417969.703125.65625 1.03125l82.746094 113.84375h-21.15625zm-80.378906-8.179687c.238281-.328126.453125-.667969.652344-1.019532 2.675781-4.8125 8.78125-6.546875 13.601562-3.878906 4.65625 2.585938 6.4375 8.339844 4.148438 13.078125l-79.992188 105.660156h-21.15625zm265.390625 173.839843h-176c-5.523438 0-10 4.476563-10 10 0 5.523438 4.476562 9.898438 10 9.898438h154.398438c-.523438 1.492187-.9375 3.039062-1.226563 4.632812l-34.023437 187.257813c-.863282 4.757812-5.003907 8.210937-9.839844 8.210937h-298.617188c-4.839844 0-8.976562-3.453125-9.84375-8.207031l-34.019531-187.164062c-.289063-1.59375-.703125-3.140626-1.226563-4.628907h154.398438c5.523438 0 10-4.476562 10-10 0-5.523437-4.476562-10-10-10h-176c-11.121094 0-20-9.0625-20-20 0-11.027343 8.972656-20 20-20h432c11.027344 0 20 8.972657 20 20 0 11.105469-9.085938 20-20 20zm0 0"></path><path d="m256 249.988281c-16.542969 0-30 13.457031-30 30v80c0 16.542969 13.457031 30 30 30s30-13.457031 30-30v-80c0-16.574219-13.425781-30-30-30zm10 110c0 5.515625-4.484375 10-10 10s-10-4.484375-10-10v-80c0-5.515625 4.484375-10 10-10 5.519531 0 10 4.480469 10 10zm0 0"></path><path d="m356 389.988281c16.542969 0 30-13.457031 30-30v-80c0-16.574219-13.425781-30-30-30-16.542969 0-30 13.457031-30 30v80c0 16.542969 13.457031 30 30 30zm-10-110c0-5.515625 4.484375-10 10-10 5.519531 0 10 4.480469 10 10v80c0 5.515625-4.484375 10-10 10s-10-4.484375-10-10zm0 0"></path><path d="m156 249.988281c-16.542969 0-30 13.457031-30 30v80c0 16.542969 13.457031 30 30 30s30-13.457031 30-30v-80c0-16.574219-13.425781-30-30-30zm10 110c0 5.515625-4.484375 10-10 10s-10-4.484375-10-10v-80c0-5.515625 4.484375-10 10-10 5.519531 0 10 4.476563 10 10zm0 0"></path></svg></span><span id="cart-total" class="text-left">' + json['total'] + '</span></span>');
  					}, 100);
  
  					$('html, body').animate({ scrollTop: 0 }, 'slow');
  
  					$('#cart > ul').load('index.php?route=common/cart/info ul li');
  				}
  			},
  			error: function(xhr, ajaxOptions, thrownError) {
  				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
  			}
  		});
  	},
  	'update': function(key, quantity) {
  		$.ajax({
  			url: 'index.php?route=checkout/cart/edit',
  			type: 'post',
  			data: 'key=' + key + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
  			dataType: 'json',
  			beforeSend: function() {
  				$('#cart > button').button('loading');
  			},
  			complete: function() {
  				$('#cart > button').button('reset');
  			},
  			success: function(json) {
  				// Need to set timeout otherwise it wont update the total
  				setTimeout(function () {
  					$('#cart > button').html('<span class="cartr"><span class="cart-i d-inline-block"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -36 512.001 512" class="svg replaced-svg"><path d="m256 219.988281c5.519531 0 10-4.480469 10-10s-4.480469-10-10-10-10 4.480469-10 10 4.480469 10 10 10zm0 0"></path><path d="m472 139.988281h-59.136719l-90.96875-125.152343c-8.171875-14.003907-26.171875-18.988282-40.46875-11.070313-14.492187 8.050781-19.703125 26.304687-11.648437 40.800781.230468.410156.484375.804688.769531 1.179688l71.351563 94.242187h-171.796876l71.351563-94.242187c.28125-.375.539063-.769532.769531-1.179688 8.035156-14.460937 2.882813-32.730468-11.660156-40.808594-14.265625-7.902343-32.265625-2.921874-40.453125 11.070313l-90.972656 125.160156h-59.136719c-22.054688 0-40 17.945313-40 40 0 17.394531 11.289062 32.539063 27.191406 37.898438 1.695313 1.3125 3.8125 2.101562 6.117188 2.101562.460937 0 .894531.027344 1.347656.089844 4.304688.578125 7.714844 3.84375 8.496094 8.117187l34.019531 187.164063c2.597656 14.269531 15.011719 24.628906 29.519531 24.628906h298.617188c14.507812 0 26.921875-10.359375 29.519531-24.632812l34.019531-187.15625c.78125-4.277344 4.195313-7.542969 8.515625-8.121094.4375-.0625.871094-.089844 1.328125-.089844 2.320313 0 4.453125-.796875 6.148438-2.125 15.914062-5.394531 27.160156-20.511719 27.160156-37.875 0-22.054687-17.945312-40-40-40zm-185.011719-105.660156c-2.285156-4.730469-.511719-10.492187 4.136719-13.070313 4.839844-2.683593 10.941406-.953124 13.609375 3.855469.195313.359375.417969.703125.65625 1.03125l82.746094 113.84375h-21.15625zm-80.378906-8.179687c.238281-.328126.453125-.667969.652344-1.019532 2.675781-4.8125 8.78125-6.546875 13.601562-3.878906 4.65625 2.585938 6.4375 8.339844 4.148438 13.078125l-79.992188 105.660156h-21.15625zm265.390625 173.839843h-176c-5.523438 0-10 4.476563-10 10 0 5.523438 4.476562 9.898438 10 9.898438h154.398438c-.523438 1.492187-.9375 3.039062-1.226563 4.632812l-34.023437 187.257813c-.863282 4.757812-5.003907 8.210937-9.839844 8.210937h-298.617188c-4.839844 0-8.976562-3.453125-9.84375-8.207031l-34.019531-187.164062c-.289063-1.59375-.703125-3.140626-1.226563-4.628907h154.398438c5.523438 0 10-4.476562 10-10 0-5.523437-4.476562-10-10-10h-176c-11.121094 0-20-9.0625-20-20 0-11.027343 8.972656-20 20-20h432c11.027344 0 20 8.972657 20 20 0 11.105469-9.085938 20-20 20zm0 0"></path><path d="m256 249.988281c-16.542969 0-30 13.457031-30 30v80c0 16.542969 13.457031 30 30 30s30-13.457031 30-30v-80c0-16.574219-13.425781-30-30-30zm10 110c0 5.515625-4.484375 10-10 10s-10-4.484375-10-10v-80c0-5.515625 4.484375-10 10-10 5.519531 0 10 4.480469 10 10zm0 0"></path><path d="m356 389.988281c16.542969 0 30-13.457031 30-30v-80c0-16.574219-13.425781-30-30-30-16.542969 0-30 13.457031-30 30v80c0 16.542969 13.457031 30 30 30zm-10-110c0-5.515625 4.484375-10 10-10 5.519531 0 10 4.480469 10 10v80c0 5.515625-4.484375 10-10 10s-10-4.484375-10-10zm0 0"></path><path d="m156 249.988281c-16.542969 0-30 13.457031-30 30v80c0 16.542969 13.457031 30 30 30s30-13.457031 30-30v-80c0-16.574219-13.425781-30-30-30zm10 110c0 5.515625-4.484375 10-10 10s-10-4.484375-10-10v-80c0-5.515625 4.484375-10 10-10 5.519531 0 10 4.476563 10 10zm0 0"></path></svg></span><span id="cart-total" class="text-left">' + json['total'] + '</span></span>');
  				}, 100);
  
  				if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
  					location = 'index.php?route=checkout/cart';
  				} else {
  					$('#cart > ul').load('index.php?route=common/cart/info ul li');
  				}
  			},
  			error: function(xhr, ajaxOptions, thrownError) {
  				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
  			}
  		});
  	},
  	'remove': function(key) {
  		$.ajax({
  			url: 'index.php?route=checkout/cart/remove',
  			type: 'post',
  			data: 'key=' + key,
  			dataType: 'json',
  			beforeSend: function() {
  				$('#cart > button').button('loading');
  			},
  			complete: function() {
  				$('#cart > button').button('reset');
  			},
  			success: function(json) {
  				// Need to set timeout otherwise it wont update the total
  				setTimeout(function () {
  					$('#cart > button').html('<span class="cartr"><span class="cart-i d-inline-block"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -36 512.001 512" class="svg replaced-svg"><path d="m256 219.988281c5.519531 0 10-4.480469 10-10s-4.480469-10-10-10-10 4.480469-10 10 4.480469 10 10 10zm0 0"></path><path d="m472 139.988281h-59.136719l-90.96875-125.152343c-8.171875-14.003907-26.171875-18.988282-40.46875-11.070313-14.492187 8.050781-19.703125 26.304687-11.648437 40.800781.230468.410156.484375.804688.769531 1.179688l71.351563 94.242187h-171.796876l71.351563-94.242187c.28125-.375.539063-.769532.769531-1.179688 8.035156-14.460937 2.882813-32.730468-11.660156-40.808594-14.265625-7.902343-32.265625-2.921874-40.453125 11.070313l-90.972656 125.160156h-59.136719c-22.054688 0-40 17.945313-40 40 0 17.394531 11.289062 32.539063 27.191406 37.898438 1.695313 1.3125 3.8125 2.101562 6.117188 2.101562.460937 0 .894531.027344 1.347656.089844 4.304688.578125 7.714844 3.84375 8.496094 8.117187l34.019531 187.164063c2.597656 14.269531 15.011719 24.628906 29.519531 24.628906h298.617188c14.507812 0 26.921875-10.359375 29.519531-24.632812l34.019531-187.15625c.78125-4.277344 4.195313-7.542969 8.515625-8.121094.4375-.0625.871094-.089844 1.328125-.089844 2.320313 0 4.453125-.796875 6.148438-2.125 15.914062-5.394531 27.160156-20.511719 27.160156-37.875 0-22.054687-17.945312-40-40-40zm-185.011719-105.660156c-2.285156-4.730469-.511719-10.492187 4.136719-13.070313 4.839844-2.683593 10.941406-.953124 13.609375 3.855469.195313.359375.417969.703125.65625 1.03125l82.746094 113.84375h-21.15625zm-80.378906-8.179687c.238281-.328126.453125-.667969.652344-1.019532 2.675781-4.8125 8.78125-6.546875 13.601562-3.878906 4.65625 2.585938 6.4375 8.339844 4.148438 13.078125l-79.992188 105.660156h-21.15625zm265.390625 173.839843h-176c-5.523438 0-10 4.476563-10 10 0 5.523438 4.476562 9.898438 10 9.898438h154.398438c-.523438 1.492187-.9375 3.039062-1.226563 4.632812l-34.023437 187.257813c-.863282 4.757812-5.003907 8.210937-9.839844 8.210937h-298.617188c-4.839844 0-8.976562-3.453125-9.84375-8.207031l-34.019531-187.164062c-.289063-1.59375-.703125-3.140626-1.226563-4.628907h154.398438c5.523438 0 10-4.476562 10-10 0-5.523437-4.476562-10-10-10h-176c-11.121094 0-20-9.0625-20-20 0-11.027343 8.972656-20 20-20h432c11.027344 0 20 8.972657 20 20 0 11.105469-9.085938 20-20 20zm0 0"></path><path d="m256 249.988281c-16.542969 0-30 13.457031-30 30v80c0 16.542969 13.457031 30 30 30s30-13.457031 30-30v-80c0-16.574219-13.425781-30-30-30zm10 110c0 5.515625-4.484375 10-10 10s-10-4.484375-10-10v-80c0-5.515625 4.484375-10 10-10 5.519531 0 10 4.480469 10 10zm0 0"></path><path d="m356 389.988281c16.542969 0 30-13.457031 30-30v-80c0-16.574219-13.425781-30-30-30-16.542969 0-30 13.457031-30 30v80c0 16.542969 13.457031 30 30 30zm-10-110c0-5.515625 4.484375-10 10-10 5.519531 0 10 4.480469 10 10v80c0 5.515625-4.484375 10-10 10s-10-4.484375-10-10zm0 0"></path><path d="m156 249.988281c-16.542969 0-30 13.457031-30 30v80c0 16.542969 13.457031 30 30 30s30-13.457031 30-30v-80c0-16.574219-13.425781-30-30-30zm10 110c0 5.515625-4.484375 10-10 10s-10-4.484375-10-10v-80c0-5.515625 4.484375-10 10-10 5.519531 0 10 4.476563 10 10zm0 0"></path></svg></span><span id="cart-total" class="text-left">' + json['total'] + '</span></span>');
  				}, 100);
  
  				if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
  					location = 'index.php?route=checkout/cart';
  				} else {
  					$('#cart > ul').load('index.php?route=common/cart/info ul li');
  				}
  			},
  			error: function(xhr, ajaxOptions, thrownError) {
  				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
  			}
  		});
  	}
  }
  
  var voucher = {
  	'add': function() {
  
  	},
  	'remove': function(key) {
  		$.ajax({
  			url: 'index.php?route=checkout/cart/remove',
  			type: 'post',
  			data: 'key=' + key,
  			dataType: 'json',
  			beforeSend: function() {
  				$('#cart > button').button('loading');
  			},
  			complete: function() {
  				$('#cart > button').button('reset');
  			},
  			success: function(json) {
  				// Need to set timeout otherwise it wont update the total
  				setTimeout(function () {
  					$('#cart > button').html('<span class="cartr"><span class="cart-i d-inline-block"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -36 512.001 512" class="svg replaced-svg"><path d="m256 219.988281c5.519531 0 10-4.480469 10-10s-4.480469-10-10-10-10 4.480469-10 10 4.480469 10 10 10zm0 0"></path><path d="m472 139.988281h-59.136719l-90.96875-125.152343c-8.171875-14.003907-26.171875-18.988282-40.46875-11.070313-14.492187 8.050781-19.703125 26.304687-11.648437 40.800781.230468.410156.484375.804688.769531 1.179688l71.351563 94.242187h-171.796876l71.351563-94.242187c.28125-.375.539063-.769532.769531-1.179688 8.035156-14.460937 2.882813-32.730468-11.660156-40.808594-14.265625-7.902343-32.265625-2.921874-40.453125 11.070313l-90.972656 125.160156h-59.136719c-22.054688 0-40 17.945313-40 40 0 17.394531 11.289062 32.539063 27.191406 37.898438 1.695313 1.3125 3.8125 2.101562 6.117188 2.101562.460937 0 .894531.027344 1.347656.089844 4.304688.578125 7.714844 3.84375 8.496094 8.117187l34.019531 187.164063c2.597656 14.269531 15.011719 24.628906 29.519531 24.628906h298.617188c14.507812 0 26.921875-10.359375 29.519531-24.632812l34.019531-187.15625c.78125-4.277344 4.195313-7.542969 8.515625-8.121094.4375-.0625.871094-.089844 1.328125-.089844 2.320313 0 4.453125-.796875 6.148438-2.125 15.914062-5.394531 27.160156-20.511719 27.160156-37.875 0-22.054687-17.945312-40-40-40zm-185.011719-105.660156c-2.285156-4.730469-.511719-10.492187 4.136719-13.070313 4.839844-2.683593 10.941406-.953124 13.609375 3.855469.195313.359375.417969.703125.65625 1.03125l82.746094 113.84375h-21.15625zm-80.378906-8.179687c.238281-.328126.453125-.667969.652344-1.019532 2.675781-4.8125 8.78125-6.546875 13.601562-3.878906 4.65625 2.585938 6.4375 8.339844 4.148438 13.078125l-79.992188 105.660156h-21.15625zm265.390625 173.839843h-176c-5.523438 0-10 4.476563-10 10 0 5.523438 4.476562 9.898438 10 9.898438h154.398438c-.523438 1.492187-.9375 3.039062-1.226563 4.632812l-34.023437 187.257813c-.863282 4.757812-5.003907 8.210937-9.839844 8.210937h-298.617188c-4.839844 0-8.976562-3.453125-9.84375-8.207031l-34.019531-187.164062c-.289063-1.59375-.703125-3.140626-1.226563-4.628907h154.398438c5.523438 0 10-4.476562 10-10 0-5.523437-4.476562-10-10-10h-176c-11.121094 0-20-9.0625-20-20 0-11.027343 8.972656-20 20-20h432c11.027344 0 20 8.972657 20 20 0 11.105469-9.085938 20-20 20zm0 0"></path><path d="m256 249.988281c-16.542969 0-30 13.457031-30 30v80c0 16.542969 13.457031 30 30 30s30-13.457031 30-30v-80c0-16.574219-13.425781-30-30-30zm10 110c0 5.515625-4.484375 10-10 10s-10-4.484375-10-10v-80c0-5.515625 4.484375-10 10-10 5.519531 0 10 4.480469 10 10zm0 0"></path><path d="m356 389.988281c16.542969 0 30-13.457031 30-30v-80c0-16.574219-13.425781-30-30-30-16.542969 0-30 13.457031-30 30v80c0 16.542969 13.457031 30 30 30zm-10-110c0-5.515625 4.484375-10 10-10 5.519531 0 10 4.480469 10 10v80c0 5.515625-4.484375 10-10 10s-10-4.484375-10-10zm0 0"></path><path d="m156 249.988281c-16.542969 0-30 13.457031-30 30v80c0 16.542969 13.457031 30 30 30s30-13.457031 30-30v-80c0-16.574219-13.425781-30-30-30zm10 110c0 5.515625-4.484375 10-10 10s-10-4.484375-10-10v-80c0-5.515625 4.484375-10 10-10 5.519531 0 10 4.476563 10 10zm0 0"></path></svg></span><span id="cart-total" class="text-left">' + json['total'] + '</span></span>');
  				}, 100);
  
  				if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
  					location = 'index.php?route=checkout/cart';
  				} else {
  					$('#cart > ul').load('index.php?route=common/cart/info ul li');
  				}
  			},
  			error: function(xhr, ajaxOptions, thrownError) {
  				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
  			}
  		});
  	}
  }
  
  var wishlist = {
  	'add': function(product_id) {
  		$.ajax({
  			url: 'index.php?route=account/wishlist/add',
  			type: 'post',
  			data: 'product_id=' + product_id,
  			dataType: 'json',
  			success: function(json) {
  				$('.alert-dismissible').remove();
  
  				if (json['redirect']) {
  					location = json['redirect'];
  				}
  
  				if (json['success']) {
  					$('#content').parent().before('<div class="alert alert-success alert-dismissible"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
  				}
  
  				$('#wishlist-total span').html(json['total']);
  				$('#wishlist-total').attr('title', json['total']);
  
  				$('html, body').animate({ scrollTop: 0 }, 'slow');
  			},
  			error: function(xhr, ajaxOptions, thrownError) {
  				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
  			}
  		});
  	},
  	'remove': function() {
  
  	}
  }
  
  var compare = {
  	'add': function(product_id) {
  		$.ajax({
  			url: 'index.php?route=product/compare/add',
  			type: 'post',
  			data: 'product_id=' + product_id,
  			dataType: 'json',
  			success: function(json) {
  				$('.alert-dismissible').remove();
  
  				if (json['success']) {
  					$('#content').parent().before('<div class="alert alert-success alert-dismissible"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
  
  					$('#compare-total').html(json['total']);
  
  					$('html, body').animate({ scrollTop: 0 }, 'slow');
  				}
  			},
  			error: function(xhr, ajaxOptions, thrownError) {
  				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
  			}
  		});
  	},
  	'remove': function() {
  
  	}
  }
  
  /* Agree to Terms */
  $(document).delegate('.agree', 'click', function(e) {
  	e.preventDefault();
  
  	$('#modal-agree').remove();
  
  	var element = this;
  
  	$.ajax({
  		url: $(element).attr('href'),
  		type: 'get',
  		dataType: 'html',
  		success: function(data) {
  			html  = '<div id="modal-agree" class="modal">';
  			html += '  <div class="modal-dialog">';
  			html += '    <div class="modal-content">';
  			html += '      <div class="modal-header">';
  			html += '        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>';
  			html += '        <h4 class="modal-title">' + $(element).text() + '</h4>';
  			html += '      </div>';
  			html += '      <div class="modal-body">' + data + '</div>';
  			html += '    </div>';
  			html += '  </div>';
  			html += '</div>';
  
  			$('body').append(html);
  
  			$('#modal-agree').modal('show');
  		}
  	});
  });
  
  // Autocomplete */
  (function($) {
  	$.fn.autocomplete = function(option) {
  		return this.each(function() {
  			this.timer = null;
  			this.items = new Array();
  
  			$.extend(this, option);
  
  			$(this).attr('autocomplete', 'off');
  
  			// Focus
  			$(this).on('focus', function() {
  				this.request();
  			});
  
  			// Blur
  			$(this).on('blur', function() {
  				setTimeout(function(object) {
  					object.hide();
  				}, 200, this);
  			});
  
  			// Keydown
  			$(this).on('keydown', function(event) {
  				switch(event.keyCode) {
  					case 27: // escape
  						this.hide();
  						break;
  					default:
  						this.request();
  						break;
  				}
  			});
  
  			// Click
  			this.click = function(event) {
  				event.preventDefault();
  
  				value = $(event.target).parent().attr('data-value');
  
  				if (value && this.items[value]) {
  					this.select(this.items[value]);
  				}
  			}
  
  			// Show
  			this.show = function() {
  				var pos = $(this).position();
  
  				$(this).siblings('ul.dropdown-menu').css({
  					top: pos.top + $(this).outerHeight(),
  					left: pos.left
  				});
  
  				$(this).siblings('ul.dropdown-menu').show();
  			}
  
  			// Hide
  			this.hide = function() {
  				$(this).siblings('ul.dropdown-menu').hide();
  			}
  
  			// Request
  			this.request = function() {
  				clearTimeout(this.timer);
  
  				this.timer = setTimeout(function(object) {
  					object.source($(object).val(), $.proxy(object.response, object));
  				}, 200, this);
  			}
  
  			// Response
  			this.response = function(json) {
  				html = '';
  
  				if (json.length) {
  					for (i = 0; i < json.length; i++) {
  						this.items[json[i]['value']] = json[i];
  					}
  
  					for (i = 0; i < json.length; i++) {
  						if (!json[i]['category']) {
  							html += '<li data-value="' + json[i]['value'] + '"><a href="#">' + json[i]['label'] + '</a></li>';
  						}
  					}
  
  					// Get all the ones with a categories
  					var category = new Array();
  
  					for (i = 0; i < json.length; i++) {
  						if (json[i]['category']) {
  							if (!category[json[i]['category']]) {
  								category[json[i]['category']] = new Array();
  								category[json[i]['category']]['name'] = json[i]['category'];
  								category[json[i]['category']]['item'] = new Array();
  							}
  
  							category[json[i]['category']]['item'].push(json[i]);
  						}
  					}
  
  					for (i in category) {
  						html += '<li class="dropdown-header">' + category[i]['name'] + '</li>';
  
  						for (j = 0; j < category[i]['item'].length; j++) {
  							html += '<li data-value="' + category[i]['item'][j]['value'] + '"><a href="#">&nbsp;&nbsp;&nbsp;' + category[i]['item'][j]['label'] + '</a></li>';
  						}
  					}
  				}
  
  				if (html) {
  					this.show();
  				} else {
  					this.hide();
  				}
  
  				$(this).siblings('ul.dropdown-menu').html(html);
  			}
  
  			$(this).after('<ul class="dropdown-menu"></ul>');
  			$(this).siblings('ul.dropdown-menu').delegate('a', 'click', $.proxy(this.click, this));
  
  		});
  	}
  })(window.jQuery);
  
  
  