(function() {
	'use strict';
	
	angular.module('ShoppingListCheckOff', [])
	.controller('ToBuyController', ToBuyController)
	.controller('AlreadyBoughtController', AlreadyBoughtController)
	.service('ShoppingListCheckOffService', ShoppingListCheckOffService);
	
	ToBuyController.$inject = ['ShoppingListCheckOffService'];
	
	function ToBuyController(ShoppingListCheckOffService) {
		var toBuyCtrl = this;
		
		toBuyCtrl.buyList = ShoppingListCheckOffService.getToBuyItems();
		
		toBuyCtrl.buyItem = function(index) {
			ShoppingListCheckOffService.changeItem(index);
		};		
	}	
	
	AlreadyBoughtController.$inject = ['ShoppingListCheckOffService'];
	
	function AlreadyBoughtController(ShoppingListCheckOffService) {
		var boughtCtrl = this;
		
		boughtCtrl.boughtList = ShoppingListCheckOffService.getBoughtItems();
	}	
	
	function ShoppingListCheckOffService() {
		var service = this;
		
		var toBuyItems = [{ name: "cookies", quantity: 10 }, { name: "breads", quantity: 2 }, { name: "muffins", quantity: 3 }, { name: "steaks", quantity: 5 }, { name: "fruits", quantity: 20 }];
		var boughtItems = [];
		
		service.getToBuyItems = function() {
			return toBuyItems;
		};
		
		service.getBoughtItems = function() {
			return boughtItems;
		};

		}
	}
})();
		
		service.changeItem = function(index) {
			boughtItems.push(toBuyItems[index]);
			toBuyItems.splice(index, 1);
