text: var products = null;
  var categories = null;
  var title = null;
  
  // Called once the page has loaded
  document.addEventListener('DOMContentLoaded', function(event) {
  	loadProducts();
  	loadCategories();
  });
  
  // Replace this with your Sheety URL
  // Make sure NOT to include the sheet name in the URL (just the project name!)
  var projectUrl = 'https://api.sheety.co/868a53474b5dfd812cbccdcd9f3a5736/productQuest';
  
  function loadProducts() {
  	fetch(projectUrl + '/products')
  	.then((response) => response.json())
  	.then(json => {
  		this.products = json.products
  		showAllProducts();
  	});
  }
  
  function loadCategories() {
  	fetch(projectUrl + '/categories')
  	.then((response) => response.json())
  	.then(json => {
  		this.categories = json.categories;
  		drawCategories();
  	})
  }
  
  function drawProducts(products) {
  	var template = Handlebars.compile(document.getElementById("products-template").innerHTML);
  	document.getElementById('products-container').innerHTML = template({
  		title: this.title,
  		products: products	
  	});
  }
  
  function drawCategories() {
  	var template = Handlebars.compile(document.getElementById("menu-template").innerHTML);
  	console.log('draw ', this.products);
  	document.getElementById('menu-container').innerHTML = template(this.categories);
  }
  
  function showAllProducts() {
  	this.title = "All keys";
  	let sortedProducts = this.products.sort((a, b) => {
  		if (!a.votes) return -1
  		if (!b.votes) return 1
  		return a.votes - b.votes;
  	})
  	drawProducts(this.products);
  }
  
  function showRedeemedKeys() {
  	this.title = "These keys have been declared as redeemed";
  	let filteredKeys = this.products.filter(product => product.votes);
  	drawProducts(filteredKeys);
  }
  
  function showUnusedKeys() {
  	this.title = "These games should still be available";
  	let filteredKeys = this.products.filter(product => !product.votes);
  	drawProducts(filteredKeys);
  }
  
  function showCategory(category) {
  	this.title = category;
  	let filteredProducts = this.products.filter(product => {
  		return product.category == category;
  	});
  	drawProducts(filteredProducts);
  }
  
  function upvoteProduct(id) {
  	let product = this.products.find(product => {
  		return product.id == id;
  	});
  	product.votes = product.votes + 1;
  	product.hasVoted = true;
  	
  	let headers = new Headers();
  	headers.set('content-type', 'application/json');
  	fetch(projectUrl + '/products/' + id, {
  		method: 'PUT',
  		body: JSON.stringify({ product: product }),
  		headers: headers
  	});
  	
  	showAllProducts();
  }
  